UNPKG

kucoin-api

Version:

Complete & robust Node.js SDK for Kucoin's REST APIs and WebSockets, with TypeScript & strong end to end tests.

47 lines 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WS_KEY_MAP = void 0; exports.safeTerminateWs = safeTerminateWs; exports.getPromiseRefForWSAPIRequest = getPromiseRefForWSAPIRequest; exports.isWSAPIWsKey = isWSAPIWsKey; /** Should be one WS key per unique URL */ exports.WS_KEY_MAP = { spotPublicV1: 'spotPublicV1', spotPrivateV1: 'spotPrivateV1', futuresPublicV1: 'futuresPublicV1', futuresPrivateV1: 'futuresPrivateV1', wsApiSpotV1: 'wsApiSpotV1', wsApiFuturesV1: 'wsApiFuturesV1', }; /** * #305: ws.terminate() is undefined in browsers. * This only works in node.js, not in browsers. * Does nothing if `ws` is undefined. Does nothing in browsers. */ function safeTerminateWs(ws, fallbackToClose) { if (!ws) { return false; } if (typeof ws['terminate'] === 'function') { ws.terminate(); return true; } else if (fallbackToClose) { ws.close(); } return false; } /** * WS API promises are stored using a primary key. This key is constructed using * properties found in every request & reply. * * The counterpart to this is in resolveEmittableEvents */ function getPromiseRefForWSAPIRequest(wsKey, requestEvent) { const promiseRef = [wsKey, requestEvent.id].join('_'); return promiseRef; } function isWSAPIWsKey(wsKey) { return (wsKey === exports.WS_KEY_MAP.wsApiFuturesV1 || wsKey === exports.WS_KEY_MAP.wsApiSpotV1); } //# sourceMappingURL=websocket-util.js.map