-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathws-proxy-socks.ts
More file actions
36 lines (30 loc) · 1000 Bytes
/
ws-proxy-socks.ts
File metadata and controls
36 lines (30 loc) · 1000 Bytes
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
/**
* Minimal example for using a socks proxy with the ws client, extracted from https://github.com/tiagosiebler/binance/pull/319
*/
import { WebsocketClient } from '../src';
// or
// import { WebsocketClient } from 'binance';
const { SocksProxyAgent } = require('socks-proxy-agent');
const agent = new SocksProxyAgent(process.env.http_proxy);
const wsClient = new WebsocketClient({
beautify: true,
wsOptions: {
agent: agent,
},
});
wsClient.on('formattedMessage', (data) => {
console.log('log formattedMessage: ', data);
});
wsClient.on('open', (data) => {
console.log('connection opened open:', data.wsKey, data.ws.target.url);
});
wsClient.on('reply', (data) => {
console.log('log reply: ', JSON.stringify(data, null, 2));
});
wsClient.on('reconnecting', (data) => {
console.log('ws automatically reconnecting.... ', data?.wsKey);
});
wsClient.on('reconnected', (data) => {
console.log('ws has reconnected ', data?.wsKey);
});
wsClient.subscribeAll24hrTickers('usdm');