-
-
Notifications
You must be signed in to change notification settings - Fork 977
Expand file tree
/
Copy pathsimple-chart.js
More file actions
36 lines (29 loc) 路 1.19 KB
/
Copy pathsimple-chart.js
File metadata and controls
36 lines (29 loc) 路 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Low-level chart session: change market, timeframe and chart type on one chart.
// Run: npm run build && node examples/simple-chart.js
import { TradingViewClient } from '@mathieuc/tradingview';
const client = new TradingViewClient();
const chart = client.createChart();
chart.on('error', (error) => console.error('Chart error:', error.code, error.message));
chart.on('symbolLoaded', (info) => console.log(`Market "${info.description}" loaded`));
chart.on('update', () => {
const last = chart.lastCandle;
if (last) console.log(`[${chart.symbolInfo?.description}] ${last.close} ${chart.symbolInfo?.currency_id}`);
});
chart.setMarket('BINANCE:BTCEUR', { timeframe: 'D' });
setTimeout(() => {
console.log('\nSetting market to BINANCE:ETHEUR...');
chart.setMarket('BINANCE:ETHEUR', { timeframe: 'D' });
}, 5_000);
setTimeout(() => {
console.log('\nSetting timeframe to 15 minutes...');
chart.setTimeframe('15');
}, 10_000);
setTimeout(() => {
console.log('\nSetting the chart type to Heikin Ashi...');
chart.setMarket('BINANCE:ETHEUR', { timeframe: 'D', type: 'HeikinAshi' });
}, 15_000);
setTimeout(async () => {
console.log('\nClosing...');
chart.delete();
await client.close();
}, 20_000);