MCPcopy Create free account
hub / github.com/ccxt/node-binance-api / subscribeCombined

Method subscribeCombined

src/node-binance-api.ts:1490–1533  ·  view source on GitHub ↗

* Used to subscribe to a combined websocket endpoint * @param {string} streams - streams to connect to * @param {function} callback - the function to call when information is received * @param {boolean} reconnect - whether to reconnect on disconnect * @param {object} opened_callb

(streams: any, callback: Callback, reconnect?: Callback, opened_callback?: Callback)

Source from the content-addressed store, hash-verified

1488 * @return {WebSocket} - websocket reference
1489 */
1490 subscribeCombined(streams: any, callback: Callback, reconnect?: Callback, opened_callback?: Callback) {
1491 const httpsproxy = this.getHttpsProxy();
1492 let socksproxy = this.getSocksProxy();
1493 const queryParams = streams.join('/');
1494 let ws: any = undefined;
1495 if (socksproxy) {
1496 socksproxy = this.proxyReplacewithIp(socksproxy);
1497 if (this.Options.verbose) this.Options.log('using socks proxy server ' + socksproxy);
1498 const agent = new SocksProxyAgent({
1499 protocol: this.parseProxy(socksproxy)[0],
1500 host: this.parseProxy(socksproxy)[1],
1501 port: this.parseProxy(socksproxy)[2]
1502 });
1503 ws = new WebSocket(this.getCombineStreamUrl() + queryParams, { agent: agent });
1504 } else if (httpsproxy) {
1505 if (this.Options.verbose) this.Options.log('using proxy server ' + httpsproxy);
1506 const config = url.parse(httpsproxy);
1507 const agent = new HttpsProxyAgent(config);
1508 ws = new WebSocket(this.getCombineStreamUrl() + queryParams, { agent: agent });
1509 } else {
1510 ws = new WebSocket(this.getCombineStreamUrl() + queryParams);
1511 }
1512
1513 ws.reconnect = this.Options.reconnect;
1514 ws.endpoint = stringHash(queryParams);
1515 ws.isAlive = false;
1516 if (this.Options.verbose) {
1517 this.Options.log('CombinedStream: Subscribed to [' + ws.endpoint + '] ' + queryParams);
1518 }
1519 ws.on('open', this.handleSocketOpen.bind(this, ws, opened_callback));
1520 ws.on('pong', this.handleSocketHeartbeat.bind(this, ws));
1521 ws.on('error', this.handleSocketError.bind(this, ws));
1522 ws.on('close', this.handleSocketClose.bind(this, ws, reconnect));
1523 ws.on('message', data => {
1524 try {
1525 if (this.Options.verbose) this.Options.log('CombinedStream: WebSocket data:', data
1526 );
1527 callback(JSONbig.parse(data).data);
1528 } catch (error) {
1529 this.Options.log('CombinedStream: Parse error: ' + error.message);
1530 }
1531 });
1532 return ws;
1533 }
1534
1535 /**
1536 * Used to terminate a web socket

Callers 8

depthStreamMethod · 0.95
depthCacheStreamMethod · 0.95
aggTradesStreamMethod · 0.95
tradesStreamMethod · 0.95
chartMethod · 0.95
candlesticksStreamMethod · 0.95
bookTickersStreamMethod · 0.95
prevDayStreamMethod · 0.95

Calls 6

getHttpsProxyMethod · 0.95
getSocksProxyMethod · 0.95
proxyReplacewithIpMethod · 0.95
parseProxyMethod · 0.95
getCombineStreamUrlMethod · 0.95
logMethod · 0.80

Tested by

no test coverage detected