bitmart-api
Version:
Complete & robust Node.js SDK for BitMart's REST APIs and WebSockets, with TypeScript declarations.
56 lines • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.APIID = void 0;
exports.serializeParams = serializeParams;
exports.getRestBaseUrl = getRestBaseUrl;
exports.isMessageEvent = isMessageEvent;
const BaseRestClient_js_1 = require("./BaseRestClient.js");
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;
}
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 BaseRestClient_js_1.REST_CLIENT_TYPE_ENUM.mainV1: {
return exchangeBaseUrls.livenetV1;
}
case BaseRestClient_js_1.REST_CLIENT_TYPE_ENUM.mainV2: {
return exchangeBaseUrls.livenetV2;
}
}
return exchangeBaseUrls.livenetV1;
}
exports.APIID = 'bitmartapinode1';
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