kucoin-api
Version:
Complete & robust Node.js SDK for Kucoin's REST APIs and WebSockets, with TypeScript & strong end to end tests.
33 lines • 931 B
JavaScript
/** Should be one WS key per unique URL */
export const WS_KEY_MAP = {
spotPublicV1: 'spotPublicV1',
spotPrivateV1: 'spotPrivateV1',
futuresPublicV1: 'futuresPublicV1',
futuresPrivateV1: 'futuresPrivateV1',
};
export function isMessageEvent(msg) {
if (typeof msg !== 'object' || !msg) {
return false;
}
const message = msg;
return message['type'] === 'message' && typeof message['data'] === 'string';
}
/**
* #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;
}
//# sourceMappingURL=websocket-util.js.map