UNPKG

bybit-api-gnome

Version:

Forked for Lick Hunter, Complete & robust node.js SDK for Bybit's REST APIs and WebSockets v5, with TypeScript & integration tests.

74 lines 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.REST_CLIENT_TYPE_ENUM = exports.APIID = void 0; exports.serializeParams = serializeParams; exports.getRestBaseUrl = getRestBaseUrl; exports.isWsPong = isWsPong; /** * Serialise a (flat) object into a query string * @param params the object to serialise * @param strict_validation throw if any properties are undefined * @param sortProperties sort properties alphabetically before building a query string * @param encodeSerialisedValues URL encode value before serialising * @returns the params object as a serialised string key1=value1&key2=value2&etc */ function serializeParams(params = {}, strict_validation = false, sortProperties = true, encodeSerialisedValues = true) { const properties = sortProperties ? Object.keys(params).sort() : Object.keys(params); return properties .map((key) => { const value = encodeSerialisedValues ? encodeURIComponent(params[key]) : params[key]; if (strict_validation === true && typeof value === 'undefined') { throw new Error('Failed to sign API request due to undefined parameter'); } return `${key}=${value}`; }) .join('&'); } function getRestBaseUrl(useTestnet, restInverseOptions) { const exchangeBaseUrls = { livenet: 'https://api.bybit.com', testnet: 'https://api-testnet.bybit.com', }; if (restInverseOptions.baseUrl) { return restInverseOptions.baseUrl; } if (useTestnet) { return exchangeBaseUrls.testnet; } return exchangeBaseUrls.livenet; } function isWsPong(msg) { if (!msg) { return false; } if (msg.pong || msg.ping) { return true; } if (msg['op'] === 'pong') { return true; } if (msg['ret_msg'] === 'pong') { return true; } return (msg.request && msg.request.op === 'ping' && msg.ret_msg === 'pong' && msg.success === true); } exports.APIID = 'GoatAlerts'; /** * Used to switch how authentication/requests work under the hood (primarily for SPOT since it's different there) */ exports.REST_CLIENT_TYPE_ENUM = { accountAsset: 'accountAsset', inverse: 'inverse', inverseFutures: 'inverseFutures', linear: 'linear', spot: 'spot', v3: 'v3', }; //# sourceMappingURL=requestUtils.js.map