bitmart-api
Version:
Complete & robust Node.js SDK for BitMart's REST APIs and WebSockets, with TypeScript declarations.
50 lines • 1.73 kB
JavaScript
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',
testnet: 'https://noTestnet',
};
if (restInverseOptions.baseUrl) {
return restInverseOptions.baseUrl;
}
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;
}
}
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