bitmart-api
Version:
Complete & robust Node.js SDK for BitMart's REST APIs and WebSockets, with TypeScript declarations.
54 lines • 1.6 kB
JavaScript
/** Should be one WS key per unique URL */
export const WS_KEY_MAP = {
spotPublicV1: 'spotPublicV1',
spotPrivateV1: 'spotPrivateV1',
futuresPublicV1: 'futuresPublicV1',
futuresPrivateV1: 'futuresPrivateV1',
futuresPublicV2: 'futuresPublicV2',
futuresPrivateV2: 'futuresPrivateV2',
};
export const WS_BASE_URL_MAP = {
spotPublicV1: {
livenet: 'wss://ws-manager-compress.bitmart.com/api?protocol=1.1',
},
spotPrivateV1: {
livenet: 'wss://ws-manager-compress.bitmart.com/user?protocol=1.1',
},
futuresPublicV1: {
livenet: 'wss://openapi-ws.bitmart.com/api?protocol=1.1',
},
futuresPrivateV1: {
livenet: 'wss://openapi-ws.bitmart.com/user?protocol=1.1',
},
futuresPublicV2: {
livenet: 'wss://openapi-ws-v2.bitmart.com/api?protocol=1.1',
},
futuresPrivateV2: {
livenet: 'wss://openapi-ws-v2.bitmart.com/user?protocol=1.1',
},
};
export const WS_ERROR_ENUM = {
INVALID_ACCESS_KEY: 'todo:',
};
export function neverGuard(x, msg) {
return new Error(`Unhandled value exception "${x}", ${msg}`);
}
/**
* 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