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

Method ensureWsApiConnection

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

* Ensures a WebSocket API connection is open for the given connectionId * @param {string} connectionId - connection identifier * @return {promise} - resolves when the connection is open

(connectionId: string)

Source from the content-addressed store, hash-verified

3945 * @return {promise} - resolves when the connection is open
3946 */
3947 private ensureWsApiConnection(connectionId: string): Promise<void> {
3948 return new Promise((resolve, reject) => {
3949 const existing = this.wsApiConnections[connectionId];
3950 if (existing) {
3951 if (existing.readyState === WebSocket.OPEN) {
3952 resolve();
3953 return;
3954 }
3955 if (existing.readyState === WebSocket.CONNECTING) {
3956 existing.once('open', () => resolve());
3957 existing.once('error', (err: Error) => reject(err));
3958 return;
3959 }
3960 }
3961 const ws = this.connectWsApi(connectionId, () => {}, () => {});
3962 ws.once('open', () => resolve());
3963 ws.once('error', (err: Error) => reject(err));
3964 });
3965 }
3966
3967 /**
3968 * Gets the book tickers of given symbol(s)

Callers 1

tickerPriceMethod · 0.95

Calls 1

connectWsApiMethod · 0.95

Tested by

no test coverage detected