@mathieuc/tradingview 3.4.0 → 3.4.2
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/.eslintrc.js +3 -0
- package/README.md +7 -1
- package/examples/AllPrivateIndicators.js +5 -4
- package/examples/BuiltInIndicator.js +3 -4
- package/examples/CustomChartType.js +4 -6
- package/examples/CustomTimeframe.js +3 -4
- package/examples/Errors.js +3 -3
- package/examples/FakeReplayMode.js +4 -5
- package/examples/FromToData.js +4 -5
- package/examples/GetDrawings.js +3 -4
- package/examples/GraphicIndicator.js +4 -5
- package/examples/MultipleSyncFetch.js +3 -4
- package/examples/PinePermManage.js +7 -7
- package/examples/ReplayMode.js +4 -5
- package/examples/Search.js +4 -5
- package/examples/SimpleChart.js +3 -3
- package/examples/UserLogin.js +4 -4
- package/package.json +6 -3
- package/src/chart/session.js +1 -1
- package/src/classes/PinePermManager.js +89 -74
- package/src/client.js +5 -1
- package/src/miscRequests.js +175 -190
- package/vite.config.js +6 -0
- package/src/FormData.js +0 -36
- package/src/request.js +0 -37
- package/test.js +0 -70
- package/tests/01. Search.js +0 -17
- package/tests/02. QuoteSession.js +0 -51
- package/tests/03. SimpleChart.js +0 -59
- package/tests/04. Indicators.js +0 -96
- package/tests/05. BuiltInIndicator.js +0 -39
- package/tests/06. FakeReplayMode.js +0 -57
- package/tests/07. ReplayMode.js +0 -49
- package/tests/08. CustomChartTypes.js +0 -113
- package/tests/09. AllErrors.js +0 -146
- package/tests/10. Authenticated.js +0 -95
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
module.exports = (log, success, warn, err, cb) => {
|
|
4
|
-
const client = new TradingView.Client();
|
|
5
|
-
|
|
6
|
-
client.onError((...error) => {
|
|
7
|
-
err('Client error', ...error);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const quoteSession = new client.Session.Quote({
|
|
11
|
-
fields: 'all',
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const BTC = new quoteSession.Market('BTCEUR');
|
|
15
|
-
|
|
16
|
-
BTC.onLoaded(() => {
|
|
17
|
-
success('BTCEUR LOADED');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const keys = [
|
|
21
|
-
'volume', 'update_mode', 'type', 'timezone',
|
|
22
|
-
'short_name', 'rtc_time', 'rtc', 'rchp', 'ch',
|
|
23
|
-
'rch', 'provider_id', 'pro_name', 'pricescale',
|
|
24
|
-
'prev_close_price', 'original_name', 'lp',
|
|
25
|
-
'open_price', 'minmove2', 'minmov', 'lp_time',
|
|
26
|
-
'low_price', 'is_tradable', 'high_price',
|
|
27
|
-
'fractional', 'exchange', 'description',
|
|
28
|
-
'current_session', 'currency_code', 'chp',
|
|
29
|
-
'currency-logoid', 'base-currency-logoid',
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
BTC.onData(async (data) => {
|
|
33
|
-
const rsKeys = Object.keys(data);
|
|
34
|
-
success('BTCEUR DATA');
|
|
35
|
-
if (rsKeys.length <= 2) return;
|
|
36
|
-
|
|
37
|
-
keys.forEach((k) => {
|
|
38
|
-
if (!rsKeys.includes(k)) {
|
|
39
|
-
err(`Missing '${k}' key in`, rsKeys);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
quoteSession.delete();
|
|
44
|
-
await client.end();
|
|
45
|
-
cb();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
BTC.onError((...error) => {
|
|
49
|
-
err('BTCEUR ERROR:', error);
|
|
50
|
-
});
|
|
51
|
-
};
|
package/tests/03. SimpleChart.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
module.exports = async (log, success, warn, err, cb) => {
|
|
4
|
-
const client = new TradingView.Client();
|
|
5
|
-
|
|
6
|
-
client.onError((...error) => {
|
|
7
|
-
err('Client error', error);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const chart = new client.Session.Chart();
|
|
11
|
-
|
|
12
|
-
chart.setMarket('BINANCE:BTCEUR', { // Set the market
|
|
13
|
-
timeframe: 'D',
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
chart.onError((...error) => {
|
|
17
|
-
err('Chart error', error);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
chart.onSymbolLoaded(() => { // When the symbol is successfully loaded
|
|
21
|
-
success(`Market "${chart.infos.description}" loaded !`);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Wait 3 seconds and set the market to BINANCE:ETHEUR
|
|
25
|
-
setTimeout(() => {
|
|
26
|
-
log('Setting market to BINANCE:ETHEUR...');
|
|
27
|
-
chart.setMarket('BINANCE:ETHEUR', {
|
|
28
|
-
timeframe: 'D',
|
|
29
|
-
});
|
|
30
|
-
}, 2000);
|
|
31
|
-
|
|
32
|
-
// Wait 4 seconds and set the timeframe to 15 minutes
|
|
33
|
-
setTimeout(() => {
|
|
34
|
-
log('Setting timeframe to 15 minutes...');
|
|
35
|
-
chart.setSeries('15');
|
|
36
|
-
}, 3000);
|
|
37
|
-
|
|
38
|
-
// Wait 5 seconds and set the chart type to "Heikin Ashi"
|
|
39
|
-
setTimeout(() => {
|
|
40
|
-
log('Setting the chart type to "Heikin Ashi"...');
|
|
41
|
-
chart.setMarket('BINANCE:ETHEUR', {
|
|
42
|
-
timeframe: 'D',
|
|
43
|
-
type: 'HeikinAshi',
|
|
44
|
-
});
|
|
45
|
-
}, 4000);
|
|
46
|
-
|
|
47
|
-
// Wait 7 seconds and close the chart
|
|
48
|
-
setTimeout(() => {
|
|
49
|
-
log('Closing the chart...');
|
|
50
|
-
chart.delete();
|
|
51
|
-
}, 5000);
|
|
52
|
-
|
|
53
|
-
// Wait 8 seconds and close the client
|
|
54
|
-
setTimeout(async () => {
|
|
55
|
-
log('Closing the client...');
|
|
56
|
-
await client.end();
|
|
57
|
-
cb();
|
|
58
|
-
}, 6000);
|
|
59
|
-
};
|
package/tests/04. Indicators.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
module.exports = async (log, success, warn, err, cb) => {
|
|
4
|
-
const client = new TradingView.Client();
|
|
5
|
-
|
|
6
|
-
client.onError((...error) => {
|
|
7
|
-
err('Client error', error);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const chart = new client.Session.Chart();
|
|
11
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
12
|
-
timeframe: '60',
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
chart.onError((...error) => {
|
|
16
|
-
err('Chart error', error);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
TradingView.getIndicator('STD;Supertrend%Strategy').then((indicator) => {
|
|
20
|
-
indicator.setOption('commission_type', 'percent');
|
|
21
|
-
indicator.setOption('commission_value', 0);
|
|
22
|
-
indicator.setOption('initial_capital', 25000);
|
|
23
|
-
indicator.setOption('default_qty_value', 20);
|
|
24
|
-
indicator.setOption('default_qty_type', 'percent_of_equity');
|
|
25
|
-
indicator.setOption('currency', 'EUR');
|
|
26
|
-
indicator.setOption('pyramiding', 10);
|
|
27
|
-
|
|
28
|
-
const SuperTrend = new chart.Study(indicator);
|
|
29
|
-
|
|
30
|
-
SuperTrend.onError((...error) => {
|
|
31
|
-
err('SuperTrend error', error[0]);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
let QTY = 10;
|
|
35
|
-
|
|
36
|
-
SuperTrend.onUpdate(async () => {
|
|
37
|
-
// MarketCipher B is a strategy so it sends a strategy report
|
|
38
|
-
const perfReport = SuperTrend.strategyReport.performance;
|
|
39
|
-
|
|
40
|
-
success('Performances:', {
|
|
41
|
-
total: {
|
|
42
|
-
trades: perfReport.all.totalTrades,
|
|
43
|
-
perf: `${Math.round(perfReport.all.netProfitPercent * 10000) / 100} %`,
|
|
44
|
-
},
|
|
45
|
-
buy: {
|
|
46
|
-
trades: perfReport.long.totalTrades,
|
|
47
|
-
perf: `${Math.round(perfReport.long.netProfitPercent * 10000) / 100} %`,
|
|
48
|
-
},
|
|
49
|
-
sell: {
|
|
50
|
-
trades: perfReport.short.totalTrades,
|
|
51
|
-
perf: `${Math.round(perfReport.short.netProfitPercent * 10000) / 100} %`,
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
if (QTY >= 50) {
|
|
56
|
-
SuperTrend.remove();
|
|
57
|
-
chart.delete();
|
|
58
|
-
await client.end();
|
|
59
|
-
cb();
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
QTY += 10;
|
|
64
|
-
log('TRY WITH', QTY, '%');
|
|
65
|
-
setTimeout(() => {
|
|
66
|
-
indicator.setOption('default_qty_value', QTY);
|
|
67
|
-
SuperTrend.setIndicator(indicator);
|
|
68
|
-
}, 1000);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
TradingView.getIndicator('PUB;uA35GeckoTA2EfgI63SD2WCSmca4njxp').then((indicator) => {
|
|
73
|
-
indicator.setOption('Show_WT_Hidden_Divergences', true);
|
|
74
|
-
indicator.setOption('Show_Stoch_Regular_Divergences', true);
|
|
75
|
-
indicator.setOption('Show_Stoch_Hidden_Divergences', true);
|
|
76
|
-
|
|
77
|
-
const CipherB = new chart.Study(indicator);
|
|
78
|
-
|
|
79
|
-
CipherB.onError((...error) => {
|
|
80
|
-
err('MarketCipher B error:', error[0]);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
CipherB.onUpdate(() => {
|
|
84
|
-
const last = CipherB.periods[0];
|
|
85
|
-
// MarketCipher B is not a strategy so it only sends plots values
|
|
86
|
-
success('MarketCipher B last values:', {
|
|
87
|
-
VWAP: Math.round(last.VWAP * 1000) / 1000,
|
|
88
|
-
moneyFlow: (last.RSIMFIArea >= 0) ? 'POSITIVE' : 'NEGATIVE',
|
|
89
|
-
buyCircle: last.Buy_and_sell_circle && last.VWAP > 0,
|
|
90
|
-
sellCircle: last.Buy_and_sell_circle && last.VWAP < 0,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
CipherB.remove();
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
module.exports = async (log, success, warn, err, cb) => {
|
|
4
|
-
const client = new TradingView.Client();
|
|
5
|
-
|
|
6
|
-
client.onError((...error) => {
|
|
7
|
-
err('Client error', error);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const chart = new client.Session.Chart();
|
|
11
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
12
|
-
timeframe: '60',
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
chart.onError((...error) => {
|
|
16
|
-
err('Chart error', error);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const volumeProfile = new TradingView.BuiltInIndicator('VbPFixed@tv-basicstudies-139!');
|
|
20
|
-
|
|
21
|
-
volumeProfile.setOption('first_bar_time', Date.now() - 10 ** 8);
|
|
22
|
-
|
|
23
|
-
const VOL = new chart.Study(volumeProfile);
|
|
24
|
-
VOL.onUpdate(async () => {
|
|
25
|
-
VOL.graphic.horizHists
|
|
26
|
-
.filter((h) => h.lastBarTime === 0) // We only keep recent volume infos
|
|
27
|
-
.sort((a, b) => b.priceHigh - a.priceHigh)
|
|
28
|
-
.forEach((h) => {
|
|
29
|
-
success(
|
|
30
|
-
`~ ${Math.round((h.priceHigh + h.priceLow) / 2)} € :`,
|
|
31
|
-
`${'_'.repeat(h.rate[0] / 3)}${'_'.repeat(h.rate[1] / 3)}`,
|
|
32
|
-
);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
chart.delete();
|
|
36
|
-
await client.end();
|
|
37
|
-
cb();
|
|
38
|
-
});
|
|
39
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
module.exports = async (log, success, warn, err, cb) => {
|
|
4
|
-
const client = new TradingView.Client();
|
|
5
|
-
|
|
6
|
-
client.onError((...error) => {
|
|
7
|
-
err('Client error', error);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const chart = new client.Session.Chart();
|
|
11
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
12
|
-
timeframe: 'D',
|
|
13
|
-
range: -1,
|
|
14
|
-
to: Math.round(Date.now() / 1000) - 86400 * 7,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
chart.onError((...error) => {
|
|
18
|
-
err('Chart error', error);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
let interval = NaN;
|
|
22
|
-
let consec = 1;
|
|
23
|
-
let lastTime = 0;
|
|
24
|
-
|
|
25
|
-
chart.onUpdate(async () => {
|
|
26
|
-
const times = chart.periods.map((p) => p.time);
|
|
27
|
-
|
|
28
|
-
if (lastTime === times[0]) {
|
|
29
|
-
consec += 1;
|
|
30
|
-
warn(`Same lastTime ${lastTime}, ${consec} times in a row`);
|
|
31
|
-
} else consec = 1;
|
|
32
|
-
[lastTime] = times;
|
|
33
|
-
|
|
34
|
-
if (consec >= 10) {
|
|
35
|
-
chart.delete();
|
|
36
|
-
await client.end();
|
|
37
|
-
cb();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const intrval = times[0] - times[1];
|
|
41
|
-
if (Number.isNaN(interval) && times.length >= 2) interval = intrval;
|
|
42
|
-
|
|
43
|
-
if (!Number.isNaN(interval) && interval !== intrval) {
|
|
44
|
-
err(`Wrong interval: ${intrval} (should be ${interval})`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
log('Next ->', times[0]);
|
|
48
|
-
|
|
49
|
-
if ((times[0] + 86400) * 1000 > Date.now()) {
|
|
50
|
-
chart.delete();
|
|
51
|
-
await client.end();
|
|
52
|
-
cb();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
chart.fetchMore(-1);
|
|
56
|
-
});
|
|
57
|
-
};
|
package/tests/07. ReplayMode.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
module.exports = async (log, success, warn, err, cb) => {
|
|
4
|
-
const client = new TradingView.Client();
|
|
5
|
-
|
|
6
|
-
client.onError((...error) => {
|
|
7
|
-
err('Client error', error);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const chart = new client.Session.Chart();
|
|
11
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
12
|
-
timeframe: 'D',
|
|
13
|
-
replay: Math.round(Date.now() / 1000) - 86400 * 10,
|
|
14
|
-
range: 1,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
chart.onError((...error) => {
|
|
18
|
-
err('Chart error', error);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
let finished = false;
|
|
22
|
-
async function step() {
|
|
23
|
-
log('Next');
|
|
24
|
-
await chart.replayStep(1);
|
|
25
|
-
if (!finished) step();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
chart.onReplayLoaded(async () => {
|
|
29
|
-
log('START REPLAY MODE');
|
|
30
|
-
await chart.replayStart(200);
|
|
31
|
-
|
|
32
|
-
setTimeout(async () => {
|
|
33
|
-
await chart.replayStop();
|
|
34
|
-
log('STOP REPLAY MODE');
|
|
35
|
-
step();
|
|
36
|
-
}, 1000);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
chart.onReplayPoint((p) => {
|
|
40
|
-
success('Point ->', p);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
chart.onReplayEnd(async () => {
|
|
44
|
-
finished = true;
|
|
45
|
-
chart.delete();
|
|
46
|
-
await client.end();
|
|
47
|
-
cb();
|
|
48
|
-
});
|
|
49
|
-
};
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
module.exports = async (log, success, warn, err, cb) => {
|
|
4
|
-
const client = new TradingView.Client();
|
|
5
|
-
|
|
6
|
-
client.onError((...error) => {
|
|
7
|
-
err('Client error', error);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const chart = new client.Session.Chart();
|
|
11
|
-
|
|
12
|
-
chart.onError((...error) => {
|
|
13
|
-
err('Chart error', error);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
/* (0s) Heikin Ashi chart */
|
|
17
|
-
setTimeout(() => {
|
|
18
|
-
log('Setting chart type to: HeikinAshi');
|
|
19
|
-
|
|
20
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
21
|
-
type: 'HeikinAshi',
|
|
22
|
-
timeframe: 'D',
|
|
23
|
-
});
|
|
24
|
-
}, 0);
|
|
25
|
-
|
|
26
|
-
/* (1s) Renko chart */
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
log('Setting chart type to: Renko');
|
|
29
|
-
|
|
30
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
31
|
-
type: 'Renko',
|
|
32
|
-
timeframe: 'D',
|
|
33
|
-
inputs: {
|
|
34
|
-
source: 'close',
|
|
35
|
-
sources: 'Close',
|
|
36
|
-
boxSize: 3,
|
|
37
|
-
style: 'ATR',
|
|
38
|
-
atrLength: 14,
|
|
39
|
-
wicks: true,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}, 1000);
|
|
43
|
-
|
|
44
|
-
/* (2s) Line Break chart */
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
log('Setting chart type to: LineBreak');
|
|
47
|
-
|
|
48
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
49
|
-
type: 'LineBreak',
|
|
50
|
-
timeframe: 'D',
|
|
51
|
-
inputs: {
|
|
52
|
-
source: 'close',
|
|
53
|
-
lb: 3,
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
}, 2000);
|
|
57
|
-
|
|
58
|
-
/* (3s) Kagi chart */
|
|
59
|
-
setTimeout(() => {
|
|
60
|
-
log('Setting chart type to: Kagi');
|
|
61
|
-
|
|
62
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
63
|
-
type: 'Kagi',
|
|
64
|
-
timeframe: 'D',
|
|
65
|
-
inputs: {
|
|
66
|
-
source: 'close',
|
|
67
|
-
style: 'ATR',
|
|
68
|
-
atrLength: 14,
|
|
69
|
-
reversalAmount: 1,
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
}, 3000);
|
|
73
|
-
|
|
74
|
-
/* (4s) Point & Figure chart */
|
|
75
|
-
setTimeout(() => {
|
|
76
|
-
log('Setting chart type to: PointAndFigure');
|
|
77
|
-
|
|
78
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
79
|
-
type: 'PointAndFigure',
|
|
80
|
-
timeframe: 'D',
|
|
81
|
-
inputs: {
|
|
82
|
-
sources: 'Close',
|
|
83
|
-
reversalAmount: 3,
|
|
84
|
-
boxSize: 1,
|
|
85
|
-
style: 'ATR',
|
|
86
|
-
atrLength: 14,
|
|
87
|
-
oneStepBackBuilding: false,
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
}, 4000);
|
|
91
|
-
|
|
92
|
-
/* (5s) Range chart */
|
|
93
|
-
setTimeout(() => {
|
|
94
|
-
log('Setting chart type to: Range');
|
|
95
|
-
|
|
96
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
97
|
-
type: 'Range',
|
|
98
|
-
timeframe: 'D',
|
|
99
|
-
inputs: {
|
|
100
|
-
range: 1,
|
|
101
|
-
phantomBars: false,
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
}, 5000);
|
|
105
|
-
|
|
106
|
-
/* (6s) Delete chart, close client */
|
|
107
|
-
setTimeout(async () => {
|
|
108
|
-
success('Closing client...');
|
|
109
|
-
chart.delete();
|
|
110
|
-
await client.end();
|
|
111
|
-
cb();
|
|
112
|
-
}, 6000);
|
|
113
|
-
};
|
package/tests/09. AllErrors.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
module.exports = async (log, success, warn, err, cb) => {
|
|
4
|
-
const client = new TradingView.Client(); // Creates a websocket client
|
|
5
|
-
|
|
6
|
-
const tests = [
|
|
7
|
-
(next) => { /* Testing "Credentials error" */
|
|
8
|
-
log('Testing "Credentials error" error:');
|
|
9
|
-
|
|
10
|
-
const client2 = new TradingView.Client({
|
|
11
|
-
token: 'FAKE_CREDENTIALS', // Set wrong credentials
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
client2.onError((...error) => {
|
|
15
|
-
success('=> Client error:', error);
|
|
16
|
-
client2.end();
|
|
17
|
-
next();
|
|
18
|
-
});
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
(next) => { /* Testing "Invalid symbol" */
|
|
22
|
-
log('Testing "Invalid symbol" error:');
|
|
23
|
-
|
|
24
|
-
const chart = new client.Session.Chart();
|
|
25
|
-
chart.onError((...error) => { // Listen for errors
|
|
26
|
-
success('=> Chart error:', error);
|
|
27
|
-
chart.delete();
|
|
28
|
-
next();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
chart.setMarket('XXXXX'); // Set a wrong market
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
(next) => { /* Testing "Invalid timezone" */
|
|
35
|
-
log('Testing "Invalid timezone" error:');
|
|
36
|
-
|
|
37
|
-
const chart = new client.Session.Chart();
|
|
38
|
-
chart.onError((...error) => { // Listen for errors
|
|
39
|
-
success('=> Chart error:', error);
|
|
40
|
-
next();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
chart.setMarket('BINANCE:BTCEUR'); // Set a market
|
|
44
|
-
chart.setTimezone('Nowhere/Nowhere'); // Set a fake timezone
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
(next) => { /* Testing "Custom timeframe" */
|
|
48
|
-
log('Testing "Custom timeframe" error:');
|
|
49
|
-
|
|
50
|
-
const chart = new client.Session.Chart();
|
|
51
|
-
chart.onError((...error) => { // Listen for errors
|
|
52
|
-
success('=> Chart error:', error);
|
|
53
|
-
chart.delete();
|
|
54
|
-
next();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
chart.setMarket('BINANCE:BTCEUR', { // Set a market
|
|
58
|
-
timeframe: '20', // Set a custom timeframe
|
|
59
|
-
/*
|
|
60
|
-
Timeframe '20' isn't available because we are
|
|
61
|
-
not logged in as a premium TradingView account
|
|
62
|
-
*/
|
|
63
|
-
});
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
(next) => { /* Testing "Invalid timeframe" */
|
|
67
|
-
log('Testing "Invalid timeframe" error:');
|
|
68
|
-
|
|
69
|
-
const chart = new client.Session.Chart();
|
|
70
|
-
chart.onError((...error) => { // Listen for errors
|
|
71
|
-
success('=> Chart error:', error);
|
|
72
|
-
next();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
chart.setMarket('BINANCE:BTCEUR', { // Set a market
|
|
76
|
-
timeframe: 'XX', // Set a wrong timeframe
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
(next) => { /* Testing "Study not auth" */
|
|
81
|
-
log('Testing "Study not auth" error:');
|
|
82
|
-
|
|
83
|
-
const chart = new client.Session.Chart();
|
|
84
|
-
chart.onError((...error) => { // Listen for errors
|
|
85
|
-
success('=> Chart error:', error);
|
|
86
|
-
next();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
chart.setMarket('BINANCE:BTCEUR', { // Set a market
|
|
90
|
-
timeframe: '15',
|
|
91
|
-
type: 'Renko',
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
chart.onUpdate(() => {
|
|
95
|
-
log('DATA', chart.periods[0]);
|
|
96
|
-
});
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
(next) => { /* Testing "Set the market before" */
|
|
100
|
-
log('Testing "Set the market before..." error:');
|
|
101
|
-
|
|
102
|
-
const chart = new client.Session.Chart();
|
|
103
|
-
chart.onError((...error) => { // Listen for errors
|
|
104
|
-
success('=> Chart error:', error);
|
|
105
|
-
chart.delete();
|
|
106
|
-
next();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
chart.setSeries('15'); // Set series before setting the market
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
(next) => { /* Testing "Inexistent indicator" */
|
|
113
|
-
log('Testing "Inexistent indicator" error:');
|
|
114
|
-
|
|
115
|
-
TradingView.getIndicator('STD;XXXXXXX')
|
|
116
|
-
.catch((error) => {
|
|
117
|
-
success('=> API error:', [error.message]);
|
|
118
|
-
next();
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
async (next) => { /* Testing "Invalid value" */
|
|
123
|
-
log('Testing "Invalid value" error:');
|
|
124
|
-
|
|
125
|
-
const chart = new client.Session.Chart();
|
|
126
|
-
chart.setMarket('BINANCE:BTCEUR'); // Set a market
|
|
127
|
-
|
|
128
|
-
const ST = await TradingView.getIndicator('STD;Supertrend');
|
|
129
|
-
ST.setOption('Factor', -1); // This will cause an error
|
|
130
|
-
|
|
131
|
-
const Supertrend = new chart.Study(ST);
|
|
132
|
-
Supertrend.onError((...error) => {
|
|
133
|
-
success('=> Study error:', error);
|
|
134
|
-
chart.delete();
|
|
135
|
-
next();
|
|
136
|
-
});
|
|
137
|
-
},
|
|
138
|
-
];
|
|
139
|
-
|
|
140
|
-
(async () => {
|
|
141
|
-
// eslint-disable-next-line no-restricted-syntax, no-await-in-loop
|
|
142
|
-
for (const t of tests) await new Promise(t);
|
|
143
|
-
success(`Crashtests ${tests.length}/${tests.length} done !`);
|
|
144
|
-
cb();
|
|
145
|
-
})();
|
|
146
|
-
};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-restricted-syntax */
|
|
2
|
-
/* eslint-disable no-await-in-loop */
|
|
3
|
-
const TradingView = require('../main');
|
|
4
|
-
|
|
5
|
-
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
6
|
-
|
|
7
|
-
module.exports = async (log, success, warn, err, cb) => {
|
|
8
|
-
log('Getting user info');
|
|
9
|
-
|
|
10
|
-
const userInfos = await TradingView.getUser(process.env.SESSION);
|
|
11
|
-
if (userInfos && userInfos.id) {
|
|
12
|
-
success('User info:', {
|
|
13
|
-
id: userInfos.id,
|
|
14
|
-
username: userInfos.username,
|
|
15
|
-
firstName: userInfos.firstName,
|
|
16
|
-
lastName: userInfos.lastName,
|
|
17
|
-
following: userInfos.following,
|
|
18
|
-
followers: userInfos.followers,
|
|
19
|
-
notifications: userInfos.notifications,
|
|
20
|
-
joinDate: userInfos.joinDate,
|
|
21
|
-
});
|
|
22
|
-
} else err('Get user error. Result:', userInfos);
|
|
23
|
-
|
|
24
|
-
await wait(1000);
|
|
25
|
-
|
|
26
|
-
log('Getting user indicators');
|
|
27
|
-
|
|
28
|
-
const userIndicators = await TradingView.getPrivateIndicators(process.env.SESSION);
|
|
29
|
-
if (userIndicators) {
|
|
30
|
-
if (userIndicators.length === 0) warn('No private indicator found');
|
|
31
|
-
else success('User indicators:', userIndicators.map((i) => i.name));
|
|
32
|
-
} else err('Get indicators error. Result:', userIndicators);
|
|
33
|
-
|
|
34
|
-
await wait(1000);
|
|
35
|
-
|
|
36
|
-
log('Creating logged client');
|
|
37
|
-
const client = new TradingView.Client({
|
|
38
|
-
token: process.env.SESSION,
|
|
39
|
-
});
|
|
40
|
-
client.onError((...error) => {
|
|
41
|
-
err('Client error', error);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const chart = new client.Session.Chart();
|
|
45
|
-
chart.onError((...error) => {
|
|
46
|
-
err('Chart error', error);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
log('Setting market to BINANCE:BTCEUR...');
|
|
50
|
-
chart.setMarket('BINANCE:BTCEUR', { timeframe: 'D' });
|
|
51
|
-
|
|
52
|
-
const checked = new Set();
|
|
53
|
-
async function check(item) {
|
|
54
|
-
checked.add(item);
|
|
55
|
-
log('Checked:', [...checked], `(${checked.size}/${userIndicators.length + 1})`);
|
|
56
|
-
if (checked.size < userIndicators.length + 1) return;
|
|
57
|
-
|
|
58
|
-
log('Closing client...');
|
|
59
|
-
chart.delete();
|
|
60
|
-
await client.end();
|
|
61
|
-
success('Client closed');
|
|
62
|
-
cb();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
chart.onUpdate(async () => {
|
|
66
|
-
success('Market data:', {
|
|
67
|
-
name: chart.infos.pro_name,
|
|
68
|
-
description: chart.infos.short_description,
|
|
69
|
-
exchange: chart.infos.exchange,
|
|
70
|
-
price: chart.periods[0].close,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
await check(Symbol.for('PRICE'));
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
await wait(1000);
|
|
77
|
-
|
|
78
|
-
log('Loading indicators...');
|
|
79
|
-
|
|
80
|
-
for (const indic of userIndicators) {
|
|
81
|
-
const privateIndic = await indic.get();
|
|
82
|
-
log(`[${indic.name}] Loading indicator...`);
|
|
83
|
-
|
|
84
|
-
const indicator = new chart.Study(privateIndic);
|
|
85
|
-
|
|
86
|
-
indicator.onReady(() => {
|
|
87
|
-
success(`[${indic.name}] Indicator loaded !`);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
indicator.onUpdate(async () => {
|
|
91
|
-
success(`[${indic.name}] Last plot:`, indicator.periods[0]);
|
|
92
|
-
await check(indic.id);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
};
|