-
-
Notifications
You must be signed in to change notification settings - Fork 414
/
Copy pathsimpleChart.test.ts
79 lines (63 loc) · 1.99 KB
/
simpleChart.test.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { describe, it, expect } from 'vitest';
import TradingView from '../main';
import utils from './utils';
describe('Simple chart session', async () => {
let client: TradingView.Client;
let chart: InstanceType<typeof client.Session.Chart>;
it('creates a client', () => {
client = new TradingView.Client();
expect(client).toBeDefined();
});
it('creates a chart session', () => {
chart = new client.Session.Chart();
expect(chart).toBeDefined();
});
it('sets market', async () => {
chart.setMarket('BINANCE:BTCEUR', {
timeframe: 'D',
});
while (
chart.infos.full_name !== 'BINANCE:BTCEUR'
|| chart.periods.length < 10
) await utils.wait(100);
expect(chart.infos.full_name).toBe('BINANCE:BTCEUR');
expect(
utils.calculateTimeGap(chart.periods),
).toBe(24 * 60 * 60);
});
it('sets timeframe', async () => {
console.log('Waiting 1 second...');
await utils.wait(1000);
console.log('Setting timeframe to 15 minutes...');
chart.setSeries('15');
while (chart.periods.length < 10) await utils.wait(100);
console.log('Chart timeframe set');
expect(
utils.calculateTimeGap(chart.periods),
).toBe(15 * 60);
});
it('sets chart type', async () => {
console.log('Waiting 1 second...');
await utils.wait(1000);
console.log('Setting the chart type to "Heikin Ashi"...');
chart.setMarket('BINANCE:ETHEUR', {
timeframe: 'D',
type: 'HeikinAshi',
});
while (chart.infos.full_name !== 'BINANCE:ETHEUR') await utils.wait(100);
console.log('Chart type set');
expect(chart.infos.full_name).toBe('BINANCE:ETHEUR');
});
it('closes chart', async () => {
console.log('Waiting 1 second...');
await utils.wait(1000);
console.log('Closing the chart...');
chart.delete();
});
it('closes client', async () => {
console.log('Waiting 1 second...');
await utils.wait(1000);
console.log('Closing the client...');
await client.end();
});
});