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

Method deliverySubscribeSingle

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

* Used to subscribe to a single delivery websocket endpoint * @param {string} endpoint - endpoint to connect to * @param {function} callback - the function to call when information is received * @param {object} params - Optional reconnect {boolean} (whether to reconnect on disconnect)

(endpoint: string, callback: Callback, params: Dict = {})

Source from the content-addressed store, hash-verified

2525 * @return {WebSocket} - websocket reference
2526 */
2527 deliverySubscribeSingle(endpoint: string, callback: Callback, params: Dict = {}) {
2528 if (typeof params === 'boolean') params = { reconnect: params };
2529 if (!params.reconnect) params.reconnect = false;
2530 if (!params.openCallback) params.openCallback = false;
2531 if (!params.id) params.id = false;
2532 const httpsproxy = this.getHttpsProxy();
2533 let socksproxy = this.getSocksProxy();
2534 let ws: any = undefined;
2535 if (socksproxy) {
2536 socksproxy = this.proxyReplacewithIp(socksproxy);
2537 if (this.Options.verbose) this.Options.log(`deliverySubscribeSingle: using socks proxy server: ${socksproxy}`);
2538 const agent = new SocksProxyAgent({
2539 protocol: this.parseProxy(socksproxy)[0],
2540 host: this.parseProxy(socksproxy)[1],
2541 port: this.parseProxy(socksproxy)[2]
2542 });
2543 ws = new WebSocket((this.getDStreamSingleUrl()) + endpoint, { agent });
2544 } else if (httpsproxy) {
2545 const config = url.parse(httpsproxy);
2546 const agent = new HttpsProxyAgent(config);
2547 if (this.Options.verbose) this.Options.log(`deliverySubscribeSingle: using proxy server: ${agent}`);
2548 ws = new WebSocket((this.getDStreamSingleUrl()) + endpoint, { agent });
2549 } else {
2550 ws = new WebSocket((this.getDStreamSingleUrl()) + endpoint);
2551 }
2552
2553 if (this.Options.verbose) this.Options.log('deliverySubscribeSingle: Subscribed to ' + endpoint);
2554 ws.reconnect = this.Options.reconnect;
2555 ws.endpoint = endpoint;
2556 ws.isAlive = false;
2557 ws.on('open', this.handleDeliverySocketOpen.bind(this, ws, params.openCallback));
2558 ws.on('pong', this.handleDeliverySocketHeartbeat.bind(this, ws));
2559 ws.on('error', this.handleDeliverySocketError.bind(this, ws));
2560 ws.on('close', this.handleDeliverySocketClose.bind(this, ws, params.reconnect));
2561 ws.on('message', data => {
2562 try {
2563 if (this.Options.verbose) this.Options.log('deliverySubscribeSingle: Received data:', data);
2564 callback(JSONbig.parse(data));
2565 } catch (error) {
2566 this.Options.log('Parse error: ' + error.message);
2567 }
2568 });
2569 return ws;
2570 }
2571
2572 /**
2573 * Used to subscribe to a combined delivery websocket endpoint

Callers 9

deliverySubscribeMethod · 0.95
deliveryTickerStreamMethod · 0.95
deliveryChartMethod · 0.95
deliveryCandlesticksMethod · 0.95

Calls 6

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

Tested by

no test coverage detected