TradingView-API
TradingView-API copied to clipboard
Data point is missing in FakeReplayMode example output
Describe the bug 2022-04-07 is missing on the output
To Reproduce Modify from FakeReplayMode.js example
const { Client } = require('../main');
/*
This example tests the fake
replay mode which works in
intraday even with free plan
*/
console.log('----- Testing FakeReplayMode: -----');
const client = new Client({
token: process.argv[2],
});
const chart = new client.Session.Chart();
chart.setMarket('NASDAQ:AAPL', {
timeframe: 'D',
range: -1, // Range is negative, so 'to' means 'from'
to: Math.round(new Date('2022-04-05T00:00:00.000Z').getTime() / 1000),
// to: 1600000000,
});
let interval = NaN;
chart.onUpdate(async () => {
const times = chart.periods.map((p) => p.time);
const closes = chart.periods.map((p) => p.close);
const intrval = times[0] - times[1];
if (Number.isNaN(interval) && times.length >= 2) interval = intrval;
if (!Number.isNaN(interval) && interval !== intrval) {
throw new Error(`Wrong interval: ${intrval} (should be ${interval})`);
}
console.log('Next ->', chart.periods.length, times[0], new Date(times[0] * 1000).toISOString(), closes[0]);
if ((times[0] + 86400) * 1000 > Date.now()) {
await client.end();
console.log('Done !', times.length);
}
chart.fetchMore(-1);
});
Output:
$ date -u --iso-8601=seconds; node FakeReplayMode.js <session token>
2022-04-09T05:26:11+00:00
----- Testing FakeReplayMode: -----
Next -> 1 1649165400 2022-04-05T13:30:00.000Z 175.06
Next -> 2 1649251800 2022-04-06T13:30:00.000Z 171.83
Next -> 4 1649424600 2022-04-08T13:30:00.000Z 170.09
Done ! 4
Environment:
- OS: ubuntu
- Node version: v14.17.0