@mathieuc/tradingview 3.5.2 → 4.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -51
- package/dist/chart/chart-session.d.ts +114 -0
- package/dist/chart/chart-session.js +339 -0
- package/dist/chart/graphics.d.ts +129 -0
- package/dist/chart/graphics.js +153 -0
- package/dist/chart/index.d.ts +11 -0
- package/dist/chart/index.js +6 -0
- package/dist/chart/strategy.d.ts +100 -0
- package/dist/chart/strategy.js +51 -0
- package/dist/chart/study.d.ts +60 -0
- package/dist/chart/study.js +171 -0
- package/dist/chart/timeframes.d.ts +7 -0
- package/dist/chart/timeframes.js +22 -0
- package/dist/chart/types.d.ts +105 -0
- package/dist/chart/types.js +9 -0
- package/dist/client/client.d.ts +89 -0
- package/dist/client/client.js +254 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.js +2 -0
- package/dist/client/transport.d.ts +27 -0
- package/dist/client/transport.js +38 -0
- package/dist/data/candles.d.ts +40 -0
- package/dist/data/candles.js +101 -0
- package/dist/data/history.d.ts +61 -0
- package/dist/data/history.js +101 -0
- package/dist/data/index.d.ts +28 -0
- package/dist/data/index.js +15 -0
- package/dist/data/indicators.d.ts +54 -0
- package/dist/data/indicators.js +139 -0
- package/dist/data/operation.d.ts +71 -0
- package/dist/data/operation.js +205 -0
- package/dist/data/provider.d.ts +23 -0
- package/dist/data/provider.js +11 -0
- package/dist/data/quotes.d.ts +33 -0
- package/dist/data/quotes.js +117 -0
- package/dist/data/symbols.d.ts +9 -0
- package/dist/data/symbols.js +19 -0
- package/dist/errors.d.ts +53 -0
- package/dist/errors.js +24 -0
- package/dist/events.d.ts +36 -0
- package/dist/events.js +70 -0
- package/dist/http/account.d.ts +47 -0
- package/dist/http/account.js +127 -0
- package/dist/http/index.d.ts +11 -0
- package/dist/http/index.js +5 -0
- package/dist/http/indicators.d.ts +37 -0
- package/dist/http/indicators.js +144 -0
- package/dist/http/layouts.d.ts +36 -0
- package/dist/http/layouts.js +24 -0
- package/dist/http/market.d.ts +45 -0
- package/dist/http/market.js +59 -0
- package/dist/http/pine-permissions.d.ts +29 -0
- package/dist/http/pine-permissions.js +56 -0
- package/dist/http/request.d.ts +44 -0
- package/dist/http/request.js +83 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +19 -0
- package/dist/indicators/builtin-indicator.d.ts +17 -0
- package/dist/indicators/builtin-indicator.js +75 -0
- package/dist/indicators/index.d.ts +8 -0
- package/dist/indicators/index.js +2 -0
- package/dist/indicators/pine-indicator.d.ts +63 -0
- package/dist/indicators/pine-indicator.js +101 -0
- package/dist/protocol/compression.d.ts +12 -0
- package/dist/protocol/compression.js +83 -0
- package/dist/protocol/framing.d.ts +59 -0
- package/dist/protocol/framing.js +68 -0
- package/dist/protocol/ids.d.ts +2 -0
- package/dist/protocol/ids.js +10 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.js +3 -0
- package/dist/quote/fields.d.ts +35 -0
- package/dist/quote/fields.js +21 -0
- package/dist/quote/index.d.ts +4 -0
- package/dist/quote/index.js +2 -0
- package/dist/quote/quote-session.d.ts +73 -0
- package/dist/quote/quote-session.js +205 -0
- package/docs/README.es.md +58 -0
- package/docs/README.fr.md +58 -0
- package/docs/README.pt.md +58 -0
- package/docs/data-api.md +229 -0
- package/docs/low-level-api.md +213 -0
- package/docs/migration-v4.md +128 -0
- package/docs/v4-coverage.md +192 -0
- package/docs/v4-reliability.md +33 -0
- package/package.json +55 -20
- package/.env.sample +0 -2
- package/.eslintrc.js +0 -28
- package/.gitattributes +0 -2
- package/docs/DOCS.md +0 -3
- package/examples/AllPrivateIndicators.js +0 -44
- package/examples/BuiltInIndicator.js +0 -51
- package/examples/CustomChartType.js +0 -123
- package/examples/CustomTimeframe.js +0 -31
- package/examples/Errors.js +0 -155
- package/examples/FakeReplayMode.js +0 -40
- package/examples/FromToData.js +0 -35
- package/examples/GetDrawings.js +0 -27
- package/examples/GraphicIndicator.js +0 -42
- package/examples/MultipleSyncFetch.js +0 -44
- package/examples/PinePermManage.js +0 -67
- package/examples/ReplayMode.js +0 -103
- package/examples/Search.js +0 -14
- package/examples/SimpleChart.js +0 -63
- package/examples/UserLogin.js +0 -16
- package/main.js +0 -11
- package/src/chart/graphicParser.js +0 -308
- package/src/chart/session.js +0 -553
- package/src/chart/study.js +0 -435
- package/src/classes/BuiltInIndicator.js +0 -137
- package/src/classes/PineIndicator.js +0 -132
- package/src/classes/PinePermManager.js +0 -159
- package/src/client.js +0 -298
- package/src/miscRequests.js +0 -609
- package/src/protocol.js +0 -60
- package/src/quote/market.js +0 -132
- package/src/quote/session.js +0 -125
- package/src/types.js +0 -36
- package/src/utils.js +0 -20
- package/vite.config.js +0 -7
package/examples/Errors.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example tests many types of errors
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
if (!process.env.SESSION || !process.env.SIGNATURE) {
|
|
8
|
-
throw Error('Please set your sessionid and signature cookies');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Creates a websocket client
|
|
12
|
-
const client = new TradingView.Client({
|
|
13
|
-
token: process.env.SESSION,
|
|
14
|
-
signature: process.env.SIGNATURE,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const tests = [
|
|
18
|
-
(next) => { /* Testing "Credentials error" */
|
|
19
|
-
console.info('\nTesting "Credentials error" error:');
|
|
20
|
-
|
|
21
|
-
const client2 = new TradingView.Client({
|
|
22
|
-
token: 'FAKE_CREDENTIALS', // Set wrong credentials
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
client2.onError((...err) => {
|
|
26
|
-
console.error(' => Client error:', err);
|
|
27
|
-
client2.end();
|
|
28
|
-
next();
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
(next) => { /* Testing "Invalid symbol" */
|
|
33
|
-
console.info('\nTesting "Invalid symbol" error:');
|
|
34
|
-
|
|
35
|
-
const chart = new client.Session.Chart();
|
|
36
|
-
chart.onError((...err) => { // Listen for errors
|
|
37
|
-
console.error(' => Chart error:', err);
|
|
38
|
-
chart.delete();
|
|
39
|
-
next();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
chart.setMarket('XXXXX'); // Set a wrong market
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
(next) => { /* Testing "Invalid timezone" */
|
|
46
|
-
console.info('\nTesting "Invalid timezone" error:');
|
|
47
|
-
|
|
48
|
-
const chart = new client.Session.Chart();
|
|
49
|
-
chart.onError((...err) => { // Listen for errors
|
|
50
|
-
console.error(' => Chart error:', err);
|
|
51
|
-
next();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
chart.setMarket('BINANCE:BTCEUR'); // Set a market
|
|
55
|
-
chart.setTimezone('Nowhere/Nowhere'); // Set a fake timezone
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
(next) => { /* Testing "Custom timeframe" */
|
|
59
|
-
console.info('\nTesting "Custom timeframe" error:');
|
|
60
|
-
|
|
61
|
-
const chart = new client.Session.Chart();
|
|
62
|
-
chart.onError((...err) => { // Listen for errors
|
|
63
|
-
console.error(' => Chart error:', err);
|
|
64
|
-
chart.delete();
|
|
65
|
-
next();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
chart.setMarket('BINANCE:BTCEUR', { // Set a market
|
|
69
|
-
timeframe: '20', // Set a custom timeframe
|
|
70
|
-
/*
|
|
71
|
-
Timeframe '20' isn't available because we are
|
|
72
|
-
not logged in as a premium TradingView account
|
|
73
|
-
*/
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
(next) => { /* Testing "Invalid timeframe" */
|
|
78
|
-
console.info('\nTesting "Invalid timeframe" error:');
|
|
79
|
-
|
|
80
|
-
const chart = new client.Session.Chart();
|
|
81
|
-
chart.onError((...err) => { // Listen for errors
|
|
82
|
-
console.error(' => Chart error:', err);
|
|
83
|
-
next();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
chart.setMarket('BINANCE:BTCEUR', { // Set a market
|
|
87
|
-
timeframe: 'XX', // Set a wrong timeframe
|
|
88
|
-
});
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
(next) => { /* Testing "Study not auth" */
|
|
92
|
-
console.info('\nTesting "Study not auth" error:');
|
|
93
|
-
|
|
94
|
-
const chart = new client.Session.Chart();
|
|
95
|
-
chart.onError((...err) => { // Listen for errors
|
|
96
|
-
console.error(' => Chart error:', err);
|
|
97
|
-
next();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
chart.setMarket('BINANCE:BTCEUR', { // Set a market
|
|
101
|
-
timeframe: '15',
|
|
102
|
-
type: 'Renko',
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
chart.onUpdate(() => {
|
|
106
|
-
console.log('DATA', chart.periods[0]);
|
|
107
|
-
});
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
(next) => { /* Testing "Set the market before" */
|
|
111
|
-
console.info('\nTesting "Set the market before..." error:');
|
|
112
|
-
|
|
113
|
-
const chart = new client.Session.Chart();
|
|
114
|
-
chart.onError((...err) => { // Listen for errors
|
|
115
|
-
console.error(' => Chart error:', err);
|
|
116
|
-
chart.delete();
|
|
117
|
-
next();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
chart.setSeries('15'); // Set series before setting the market
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
(next) => { /* Testing "Inexistent indicator" */
|
|
124
|
-
console.info('\nTesting "Inexistent indicator" error:');
|
|
125
|
-
|
|
126
|
-
TradingView.getIndicator('STD;XXXXXXX')
|
|
127
|
-
.catch((err) => {
|
|
128
|
-
console.error(' => API error:', [err.message]);
|
|
129
|
-
next();
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
async (next) => { /* Testing "Invalid value" */
|
|
134
|
-
console.info('\nTesting "Invalid value" error:');
|
|
135
|
-
|
|
136
|
-
const chart = new client.Session.Chart();
|
|
137
|
-
chart.setMarket('BINANCE:BTCEUR'); // Set a market
|
|
138
|
-
|
|
139
|
-
const ST = await TradingView.getIndicator('STD;Supertrend');
|
|
140
|
-
ST.setOption('Factor', -1); // This will cause an error
|
|
141
|
-
|
|
142
|
-
const Supertrend = new chart.Study(ST);
|
|
143
|
-
Supertrend.onError((...err) => {
|
|
144
|
-
console.error(' => Study error:', err);
|
|
145
|
-
chart.delete();
|
|
146
|
-
next();
|
|
147
|
-
});
|
|
148
|
-
},
|
|
149
|
-
];
|
|
150
|
-
|
|
151
|
-
(async () => {
|
|
152
|
-
// eslint-disable-next-line no-restricted-syntax, no-await-in-loop
|
|
153
|
-
for (const t of tests) await new Promise(t);
|
|
154
|
-
console.log(`\nTests ${tests.length}/${tests.length} done !`);
|
|
155
|
-
})();
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const { Client } = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example tests the fake replay mode which
|
|
5
|
-
* works in intraday even with free plan
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
console.log('----- Testing FakeReplayMode: -----');
|
|
9
|
-
|
|
10
|
-
const client = new Client();
|
|
11
|
-
const chart = new client.Session.Chart();
|
|
12
|
-
|
|
13
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
14
|
-
timeframe: '240',
|
|
15
|
-
range: -1, // Range is negative, so 'to' means 'from'
|
|
16
|
-
to: Math.round(Date.now() / 1000) - 86400 * 7, // Seven days before now
|
|
17
|
-
// to: 1600000000,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
let interval = NaN;
|
|
21
|
-
|
|
22
|
-
chart.onUpdate(async () => {
|
|
23
|
-
const times = chart.periods.map((p) => p.time);
|
|
24
|
-
|
|
25
|
-
const intrval = times[0] - times[1];
|
|
26
|
-
if (Number.isNaN(interval) && times.length >= 2) interval = intrval;
|
|
27
|
-
|
|
28
|
-
if (!Number.isNaN(interval) && interval !== intrval) {
|
|
29
|
-
throw new Error(`Wrong interval: ${intrval} (should be ${interval})`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
console.log('Next ->', times[0]);
|
|
33
|
-
|
|
34
|
-
if (times[0] > ((Date.now() / 1000) - 86400 * 1)) {
|
|
35
|
-
await client.end();
|
|
36
|
-
console.log('Done !', times.length);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
chart.fetchMore(-2);
|
|
40
|
-
});
|
package/examples/FromToData.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example tests fetching chart data of a number
|
|
5
|
-
* of candles before or after a timestamp
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
if (!process.env.SESSION || !process.env.SIGNATURE) {
|
|
9
|
-
throw Error('Please set your sessionid and signature cookies');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const client = new TradingView.Client({
|
|
13
|
-
token: process.env.SESSION,
|
|
14
|
-
signature: process.env.SIGNATURE,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const chart = new client.Session.Chart();
|
|
18
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
19
|
-
timeframe: '240',
|
|
20
|
-
range: 2, // Can be positive to get before or negative to get after
|
|
21
|
-
to: 1700000000,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// This works with indicators
|
|
25
|
-
|
|
26
|
-
TradingView.getIndicator('STD;Supertrend').then(async (indic) => {
|
|
27
|
-
console.log(`Loading '${indic.description}' study...`);
|
|
28
|
-
const SUPERTREND = new chart.Study(indic);
|
|
29
|
-
|
|
30
|
-
SUPERTREND.onUpdate(() => {
|
|
31
|
-
console.log('Prices periods:', chart.periods);
|
|
32
|
-
console.log('Study periods:', SUPERTREND.periods);
|
|
33
|
-
client.end();
|
|
34
|
-
});
|
|
35
|
-
});
|
package/examples/GetDrawings.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example tests the getDrawings function
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// First parameter must be the layoutID
|
|
8
|
-
// If the layout is private:
|
|
9
|
-
// - Second parameter must be the userid (you can use getUser function)
|
|
10
|
-
// - You should provide your sessionid and signature cookies in .env file
|
|
11
|
-
|
|
12
|
-
if (!process.argv[2]) throw Error('Please specify a layoutID');
|
|
13
|
-
|
|
14
|
-
TradingView.getDrawings(process.argv[2], null, {
|
|
15
|
-
session: process.env.SESSION,
|
|
16
|
-
signature: process.env.SIGNATURE,
|
|
17
|
-
id: process.argv[3],
|
|
18
|
-
}).then((drawings) => {
|
|
19
|
-
console.log(`Found ${drawings.length} drawings:`, drawings.map((d) => ({
|
|
20
|
-
id: d.id,
|
|
21
|
-
symbol: d.symbol,
|
|
22
|
-
type: d.type,
|
|
23
|
-
text: d.state.text,
|
|
24
|
-
})));
|
|
25
|
-
}).catch((err) => {
|
|
26
|
-
console.error('Error:', err.message);
|
|
27
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example tests an indicator that sends graphic data such
|
|
5
|
-
* as 'lines', 'labels', 'boxes', 'tables', 'polygons', etc...
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
if (!process.env.SESSION || !process.env.SIGNATURE) {
|
|
9
|
-
throw Error('Please set your sessionid and signature cookies');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const client = new TradingView.Client({
|
|
13
|
-
token: process.env.SESSION,
|
|
14
|
-
signature: process.env.SIGNATURE,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const chart = new client.Session.Chart();
|
|
18
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
19
|
-
timeframe: '5',
|
|
20
|
-
range: 10000,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// TradingView.getIndicator('USER;01efac32df544348810bc843a7515f36').then((indic) => {
|
|
24
|
-
// TradingView.getIndicator('PUB;5xi4DbWeuIQrU0Fx6ZKiI2odDvIW9q2j').then((indic) => {
|
|
25
|
-
TradingView.getIndicator('STD;Zig_Zag').then((indic) => {
|
|
26
|
-
const STD = new chart.Study(indic);
|
|
27
|
-
|
|
28
|
-
STD.onError((...err) => {
|
|
29
|
-
console.log('Study error:', ...err);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
STD.onReady(() => {
|
|
33
|
-
console.log(`STD '${STD.instance.description}' Loaded !`);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
STD.onUpdate(() => {
|
|
37
|
-
console.log('Graphic data:', STD.graphic);
|
|
38
|
-
// console.log('Tables:', changes, STD.graphic.tables);
|
|
39
|
-
// console.log('Cells:', STD.graphic.tables[0].cells());
|
|
40
|
-
client.end();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This examples synchronously fetches data from 3 indicators
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
if (!process.env.SESSION || !process.env.SIGNATURE) {
|
|
8
|
-
throw Error('Please set your sessionid and signature cookies');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const client = new TradingView.Client({
|
|
12
|
-
token: process.env.SESSION,
|
|
13
|
-
signature: process.env.SIGNATURE,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
function getIndicData(indicator) {
|
|
17
|
-
const chart = new client.Session.Chart();
|
|
18
|
-
chart.setMarket('BINANCE:DOTUSDT');
|
|
19
|
-
const STD = new chart.Study(indicator);
|
|
20
|
-
|
|
21
|
-
console.log(`Getting "${indicator.description}"...`);
|
|
22
|
-
|
|
23
|
-
return new Promise((res) => {
|
|
24
|
-
STD.onUpdate(() => {
|
|
25
|
-
res(STD.periods);
|
|
26
|
-
console.log(`"${indicator.description}" done !`);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
(async () => {
|
|
32
|
-
console.log('Getting all indicators...');
|
|
33
|
-
|
|
34
|
-
const indicData = await Promise.all([
|
|
35
|
-
await TradingView.getIndicator('PUB;3lEKXjKWycY5fFZRYYujEy8fxzRRUyF3'),
|
|
36
|
-
await TradingView.getIndicator('PUB;5nawr3gCESvSHQfOhrLPqQqT4zM23w3X'),
|
|
37
|
-
await TradingView.getIndicator('PUB;vrOJcNRPULteowIsuP6iHn3GIxBJdXwT'),
|
|
38
|
-
].map(getIndicData));
|
|
39
|
-
|
|
40
|
-
console.log(indicData);
|
|
41
|
-
console.log('All done !');
|
|
42
|
-
|
|
43
|
-
client.end();
|
|
44
|
-
})();
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const { PinePermManager } = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example creates a pine permission manager
|
|
5
|
-
* and tests all the available functions
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
if (!process.env.SESSION || !process.env.SIGNATURE) {
|
|
9
|
-
throw Error('Please set your sessionid and signature cookies');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const pineid = process.argv[2];
|
|
13
|
-
|
|
14
|
-
if (!pineid) throw Error('Please specify a pine id as first argument');
|
|
15
|
-
|
|
16
|
-
console.log('Pine ID:', pineid);
|
|
17
|
-
|
|
18
|
-
const manager = new PinePermManager(
|
|
19
|
-
process.env.SESSION,
|
|
20
|
-
process.env.SIGNATURE,
|
|
21
|
-
pineid,
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
(async () => {
|
|
25
|
-
console.log('Users:', await manager.getUsers());
|
|
26
|
-
|
|
27
|
-
console.log('Adding user \'TradingView\'...');
|
|
28
|
-
|
|
29
|
-
switch (await manager.addUser('TradingView')) {
|
|
30
|
-
case 'ok':
|
|
31
|
-
console.log('Done !');
|
|
32
|
-
break;
|
|
33
|
-
case 'exists':
|
|
34
|
-
console.log('This user is already authorized');
|
|
35
|
-
break;
|
|
36
|
-
default:
|
|
37
|
-
console.error('Unknown error...');
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
console.log('Users:', await manager.getUsers());
|
|
42
|
-
|
|
43
|
-
console.log('Modifying expiration date...');
|
|
44
|
-
|
|
45
|
-
const newDate = new Date(Date.now() + 24 * 3600000); // Add one day
|
|
46
|
-
if (await manager.modifyExpiration('TradingView', newDate) === 'ok') {
|
|
47
|
-
console.log('Done !');
|
|
48
|
-
} else console.error('Unknown error...');
|
|
49
|
-
|
|
50
|
-
console.log('Users:', await manager.getUsers());
|
|
51
|
-
|
|
52
|
-
console.log('Removing expiration date...');
|
|
53
|
-
|
|
54
|
-
if (await manager.modifyExpiration('TradingView') === 'ok') {
|
|
55
|
-
console.log('Done !');
|
|
56
|
-
} else console.error('Unknown error...');
|
|
57
|
-
|
|
58
|
-
console.log('Users:', await manager.getUsers());
|
|
59
|
-
|
|
60
|
-
console.log('Removing user \'TradingView\'...');
|
|
61
|
-
|
|
62
|
-
if (await manager.removeUser('TradingView') === 'ok') {
|
|
63
|
-
console.log('Done !');
|
|
64
|
-
} else console.error('Unknown error...');
|
|
65
|
-
|
|
66
|
-
console.log('Users:', await manager.getUsers());
|
|
67
|
-
})();
|
package/examples/ReplayMode.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example tests the real replay mode by fetching
|
|
5
|
-
* indicator data and stores it in a 'periods' variable
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
if (!process.env.SESSION || !process.env.SIGNATURE) {
|
|
9
|
-
throw Error('Please set your sessionid and signature cookies');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
console.log('----- Testing ReplayMode: -----');
|
|
13
|
-
|
|
14
|
-
const client = new TradingView.Client({
|
|
15
|
-
token: process.env.SESSION,
|
|
16
|
-
signature: process.env.SIGNATURE,
|
|
17
|
-
});
|
|
18
|
-
const chart = new client.Session.Chart();
|
|
19
|
-
|
|
20
|
-
const config = {
|
|
21
|
-
symbol: 'BINANCE:BTCEUR',
|
|
22
|
-
timeframe: 'D',
|
|
23
|
-
startFrom: Math.round(Date.now() / 1000) - 86400 * 7, // Seven days before now
|
|
24
|
-
// startFrom: 1600000000,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
chart.setMarket(config.symbol, {
|
|
28
|
-
timeframe: config.timeframe,
|
|
29
|
-
replay: config.startFrom,
|
|
30
|
-
range: 1,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// chart.onReplayLoaded(() => {
|
|
34
|
-
// console.log('STARTING REPLAY MODE');
|
|
35
|
-
// chart.replayStart(1000);
|
|
36
|
-
|
|
37
|
-
// // setTimeout(() => {
|
|
38
|
-
// // console.log('STOPPING REPLAY MODE');
|
|
39
|
-
// // chart.replayStop();
|
|
40
|
-
// // }, 7000);
|
|
41
|
-
// });
|
|
42
|
-
|
|
43
|
-
let loading = 0;
|
|
44
|
-
const indicators = [];
|
|
45
|
-
const periods = {};
|
|
46
|
-
|
|
47
|
-
let interval = NaN;
|
|
48
|
-
|
|
49
|
-
async function step() {
|
|
50
|
-
const period = { ...chart.periods[0] };
|
|
51
|
-
|
|
52
|
-
const times = Object.keys(periods);
|
|
53
|
-
const intrval = times[times.length - 1] - times[times.length - 2];
|
|
54
|
-
if (Number.isNaN(interval) && times.length >= 2) interval = intrval;
|
|
55
|
-
|
|
56
|
-
if (!Number.isNaN(interval) && interval !== intrval) {
|
|
57
|
-
throw new Error(`Wrong interval: ${intrval} (should be ${interval})`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
indicators.forEach(([n, i]) => {
|
|
61
|
-
const plots = { ...i.periods[0] };
|
|
62
|
-
delete plots.$time;
|
|
63
|
-
period[n] = { plots };
|
|
64
|
-
|
|
65
|
-
Object.keys(i.graphic).forEach((g) => {
|
|
66
|
-
if (!i.graphic[g].length) return;
|
|
67
|
-
if (!period[n].graphics) period[n].graphics = {};
|
|
68
|
-
period[n].graphics[g] = i.graphic[g];
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
periods[period.time] = period;
|
|
73
|
-
|
|
74
|
-
console.log('Next ->', period.time, times.length);
|
|
75
|
-
|
|
76
|
-
await chart.replayStep(1);
|
|
77
|
-
step();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
chart.onReplayEnd(async () => {
|
|
81
|
-
await client.end();
|
|
82
|
-
console.log('Done !', Object.keys(periods).length);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
async function addIndicator(name, pineId, options = {}) {
|
|
86
|
-
loading += 1;
|
|
87
|
-
|
|
88
|
-
const indic = pineId.includes('@')
|
|
89
|
-
? new TradingView.BuiltInIndicator(pineId)
|
|
90
|
-
: await TradingView.getIndicator(pineId);
|
|
91
|
-
Object.keys(options).forEach((o) => { indic.setOption(o, options[o]); });
|
|
92
|
-
|
|
93
|
-
const std = new chart.Study(indic);
|
|
94
|
-
|
|
95
|
-
std.onReady(() => {
|
|
96
|
-
indicators.push([name, std]);
|
|
97
|
-
if (loading === indicators.length) step();
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
addIndicator('Volume', 'Volume@tv-basicstudies-241');
|
|
102
|
-
addIndicator('EMA_50', 'STD;EMA', { Length: 50 });
|
|
103
|
-
addIndicator('EMA_200', 'STD;EMA', { Length: 200 });
|
package/examples/Search.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example tests the searching functions such
|
|
5
|
-
* as 'searchMarketV3' and 'searchIndicator'
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
TradingView.searchMarketV3('BINANCE:').then((rs) => {
|
|
9
|
-
console.log('Found Markets:', rs);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
TradingView.searchIndicator('RSI').then((rs) => {
|
|
13
|
-
console.log('Found Indicators:', rs);
|
|
14
|
-
});
|
package/examples/SimpleChart.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example creates a BTCEUR daily chart
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const client = new TradingView.Client(); // Creates a websocket client
|
|
8
|
-
|
|
9
|
-
const chart = new client.Session.Chart(); // Init a Chart session
|
|
10
|
-
|
|
11
|
-
chart.setMarket('BINANCE:BTCEUR', { // Set the market
|
|
12
|
-
timeframe: 'D',
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
chart.onError((...err) => { // Listen for errors (can avoid crash)
|
|
16
|
-
console.error('Chart error:', ...err);
|
|
17
|
-
// Do something...
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
chart.onSymbolLoaded(() => { // When the symbol is successfully loaded
|
|
21
|
-
console.log(`Market "${chart.infos.description}" loaded !`);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
chart.onUpdate(() => { // When price changes
|
|
25
|
-
if (!chart.periods[0]) return;
|
|
26
|
-
console.log(`[${chart.infos.description}]: ${chart.periods[0].close} ${chart.infos.currency_id}`);
|
|
27
|
-
// Do something...
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// Wait 5 seconds and set the market to BINANCE:ETHEUR
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
console.log('\nSetting market to BINANCE:ETHEUR...');
|
|
33
|
-
chart.setMarket('BINANCE:ETHEUR', {
|
|
34
|
-
timeframe: 'D',
|
|
35
|
-
});
|
|
36
|
-
}, 5000);
|
|
37
|
-
|
|
38
|
-
// Wait 10 seconds and set the timeframe to 15 minutes
|
|
39
|
-
setTimeout(() => {
|
|
40
|
-
console.log('\nSetting timeframe to 15 minutes...');
|
|
41
|
-
chart.setSeries('15');
|
|
42
|
-
}, 10000);
|
|
43
|
-
|
|
44
|
-
// Wait 15 seconds and set the chart type to "Heikin Ashi"
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
console.log('\nSetting the chart type to "Heikin Ashi"s...');
|
|
47
|
-
chart.setMarket('BINANCE:ETHEUR', {
|
|
48
|
-
timeframe: 'D',
|
|
49
|
-
type: 'HeikinAshi',
|
|
50
|
-
});
|
|
51
|
-
}, 15000);
|
|
52
|
-
|
|
53
|
-
// Wait 20 seconds and close the chart
|
|
54
|
-
setTimeout(() => {
|
|
55
|
-
console.log('\nClosing the chart...');
|
|
56
|
-
chart.delete();
|
|
57
|
-
}, 20000);
|
|
58
|
-
|
|
59
|
-
// Wait 25 seconds and close the client
|
|
60
|
-
setTimeout(() => {
|
|
61
|
-
console.log('\nClosing the client...');
|
|
62
|
-
client.end();
|
|
63
|
-
}, 25000);
|
package/examples/UserLogin.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example tests the user login function
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
if (!process.argv[2]) throw Error('Please specify your username/email');
|
|
8
|
-
if (!process.argv[3]) throw Error('Please specify your password');
|
|
9
|
-
|
|
10
|
-
TradingView.loginUser(process.argv[2], process.argv[3], false).then((user) => {
|
|
11
|
-
console.log('User:', user);
|
|
12
|
-
console.log('Sessionid:', user.session);
|
|
13
|
-
console.log('Signature:', user.signature);
|
|
14
|
-
}).catch((err) => {
|
|
15
|
-
console.error('Login error:', err.message);
|
|
16
|
-
});
|
package/main.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const miscRequests = require('./src/miscRequests');
|
|
2
|
-
const Client = require('./src/client');
|
|
3
|
-
const BuiltInIndicator = require('./src/classes/BuiltInIndicator');
|
|
4
|
-
const PineIndicator = require('./src/classes/PineIndicator');
|
|
5
|
-
const PinePermManager = require('./src/classes/PinePermManager');
|
|
6
|
-
|
|
7
|
-
module.exports = { ...miscRequests };
|
|
8
|
-
module.exports.Client = Client;
|
|
9
|
-
module.exports.BuiltInIndicator = BuiltInIndicator;
|
|
10
|
-
module.exports.PineIndicator = PineIndicator;
|
|
11
|
-
module.exports.PinePermManager = PinePermManager;
|