forked from tiagosiebler/binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws-close.ts
40 lines (32 loc) · 932 Bytes
/
ws-close.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
import { DefaultLogger, WebsocketClient } from '../src';
// or
// import { DefaultLogger, WebsocketClient } from 'binance';
(async () => {
const key = process.env.APIKEY || 'APIKEY';
const secret = process.env.APISECRET || 'APISECRET';
let wsKey;
const logger = {
...DefaultLogger,
silly: () => {},
};
const wsClient = new WebsocketClient(
{
api_key: key,
api_secret: secret,
beautify: true,
},
logger,
);
wsClient.on('open', (data) => {
console.log('connection opened open:', data.wsKey, data.ws.target.url);
wsKey = data.wsKey;
});
wsClient.on('reconnecting', (data) => {
console.log('ws automatically reconnecting.... ', data?.wsKey);
});
wsClient.on('reconnected', (data) => {
console.log('ws has reconnected ', data?.wsKey);
});
wsClient.subscribeUsdFuturesUserDataStream();
setTimeout(() => wsClient.close(wsKey, false), 5000);
})();