UNPKG

kucoin-api

Version:

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

41 lines 1.26 kB
/** Should be one WS key per unique URL */ export const 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. */ export 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 */ export function getPromiseRefForWSAPIRequest(wsKey, requestEvent) { const promiseRef = [wsKey, requestEvent.id].join('_'); return promiseRef; } export function isWSAPIWsKey(wsKey) { return (wsKey === WS_KEY_MAP.wsApiFuturesV1 || wsKey === WS_KEY_MAP.wsApiSpotV1); } //# sourceMappingURL=websocket-util.js.map