kucoin-api
Version:
Complete & robust Node.js SDK for Kucoin's REST APIs and WebSockets, with TypeScript & strong end to end tests.
57 lines • 2.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRestBaseUrl = exports.APIIDFuturesSign = exports.APIIDFutures = exports.APIIDMainSign = exports.APIIDMain = exports.serializeParams = exports.REST_CLIENT_TYPE_ENUM = void 0;
/**
* Used to switch how authentication/requests work under the hood
*/
exports.REST_CLIENT_TYPE_ENUM = {
/** Spot & Margin */
main: 'main',
/** Futures */
futures: 'futures',
/** Broker */
broker: 'broker',
};
const kucoinURLMap = {
[exports.REST_CLIENT_TYPE_ENUM.main]: 'https://api.kucoin.com',
[exports.REST_CLIENT_TYPE_ENUM.futures]: 'https://api-futures.kucoin.com',
[exports.REST_CLIENT_TYPE_ENUM.broker]: 'https://api-broker.kucoin.com',
};
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;
}
exports.serializeParams = serializeParams;
exports.APIIDMain = 'NODESDK';
exports.APIIDMainSign = 'd28f5b4a-179d-4fcb-9c00-c8319c0bb82c';
exports.APIIDFutures = 'NODESDKFUTURES';
exports.APIIDFuturesSign = '7f7fb0d6-e600-4ef4-8fe3-41e6aea9af84';
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;
}
exports.getRestBaseUrl = getRestBaseUrl;
//# sourceMappingURL=requestUtils.js.map
;