UNPKG

kucoin-api

Version:

Complete & robust Node.js SDK for Kucoin's REST APIs and WebSockets, with TypeScript & strong end to end tests.

52 lines 1.8 kB
/** * Used to switch how authentication/requests work under the hood */ export const REST_CLIENT_TYPE_ENUM = { /** Spot & Margin */ main: 'main', /** Futures */ futures: 'futures', /** Broker */ broker: 'broker', }; const kucoinURLMap = { [REST_CLIENT_TYPE_ENUM.main]: 'https://api.kucoin.com', [REST_CLIENT_TYPE_ENUM.futures]: 'https://api-futures.kucoin.com', [REST_CLIENT_TYPE_ENUM.broker]: 'https://api-broker.kucoin.com', }; 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 const APIIDMain = 'NODESDK'; export const APIIDMainSign = 'd28f5b4a-179d-4fcb-9c00-c8319c0bb82c'; export const APIIDFutures = 'NODESDKFUTURES'; export const APIIDFuturesSign = '7f7fb0d6-e600-4ef4-8fe3-41e6aea9af84'; export function getRestBaseUrl(useTestnet, restInverseOptions, restClientType) { const exchangeBaseUrls = { livenet: kucoinURLMap[restClientType], testnet: 'https://noTestnet', }; if (restInverseOptions.baseUrl) { return restInverseOptions.baseUrl; } if (useTestnet) { return exchangeBaseUrls.testnet; } return exchangeBaseUrls.livenet; } //# sourceMappingURL=requestUtils.js.map