UNPKG

bitmart-api

Version:

Complete & robust Node.js SDK for BitMart's REST APIs and WebSockets, with TypeScript declarations.

60 lines 2.09 kB
import { REST_CLIENT_TYPE_ENUM } from './BaseRestClient.js'; export function serializeParams(params, strict_validation, encodeValues, prefixWith) { if (!params) { return ''; } const queryString = Object.keys(params) .sort() .map((key) => { const value = params[key]; if (strict_validation === true && typeof value === 'undefined') { throw new Error('Failed to sign API request due to undefined parameter'); } const encodedValue = encodeValues ? encodeURIComponent(value) : value; return `${key}=${encodedValue}`; }) .join('&'); // Only prefix if there's a value return queryString ? prefixWith + queryString : queryString; } export function getRestBaseUrl(useTestnet, restInverseOptions, restClientType) { const exchangeBaseUrls = { livenetV1: 'https://api-cloud.bitmart.com', livenetV2: 'https://api-cloud-v2.bitmart.com', demoV2: 'https://demo-api-cloud-v2.bitmart.com', testnet: 'https://noTestnet', }; if (restInverseOptions.baseUrl) { return restInverseOptions.baseUrl; } if (restInverseOptions.demoTrading) { // Demo environment is only available for V2 Futures if (restClientType === REST_CLIENT_TYPE_ENUM.mainV2) { return exchangeBaseUrls.demoV2; } // For V1, fall back to production } if (useTestnet) { return exchangeBaseUrls.testnet; } switch (restClientType) { case REST_CLIENT_TYPE_ENUM.mainV1: { return exchangeBaseUrls.livenetV1; } case REST_CLIENT_TYPE_ENUM.mainV2: { return exchangeBaseUrls.livenetV2; } default: { return exchangeBaseUrls.livenetV1; } } } export const APIID = 'bitmartapinode1'; export function isMessageEvent(msg) { if (typeof msg !== 'object' || !msg) { return false; } const message = msg; return message['type'] === 'message' && typeof message['data'] === 'string'; } //# sourceMappingURL=requestUtils.js.map