UNPKG

@exchanges/binance

Version:

Exchange provider for Binance API

88 lines 4.06 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.BinanceClient = void 0; const axios_1 = __importDefault(require("axios")); const api_1 = require("../api"); const info_1 = require("../info"); const interceptors_1 = require("../interceptors"); class BinanceClient { constructor(options) { this[_a] = null; this._options = null; this.getTime = () => { return Date.now(); }; this.checkGeneralAPIConnection = () => __awaiter(this, void 0, void 0, function* () { try { yield api_1.spotMarginSavingsMaining.marketData.checkServerTime(this); return true; } catch (err) { return false; } }); if (options && typeof options !== 'object') throw new TypeError('BinanceClient options is not object'); this._options = options || {}; this._options.spotApiEndpoint = this._options.spotApiEndpoint || info_1.CONST.SPOT_HOSTS.baseHost; this._options.spotSocketEndpoint = this._options.spotSocketEndpoint || info_1.CONST.SPOT_HOSTS.socketHost; this._options.usdFuturesApiEndpoint = this._options.usdFuturesApiEndpoint || info_1.CONST.USDTM_HOSTS.baseHost; this._options.usdFuturesSocketEndpoint = this._options.usdFuturesSocketEndpoint || info_1.CONST.USDTM_HOSTS.socketHost; this._options.coinFuturesApiEndpoint = this._options.coinFuturesApiEndpoint || info_1.CONST.COINM_HOSTS.baseHost; this._options.coinFuturesSocketEndpoint = this._options.coinFuturesSocketEndpoint || info_1.CONST.COINM_HOSTS.socketHost; this._options.vanillaApiEndpoint = this._options.vanillaApiEndpoint || info_1.CONST.VANILLA_HOSTS.baseHost; this._options.vanillaSocketEndpoint = this._options.vanillaSocketEndpoint || info_1.CONST.VANILLA_HOSTS.socketHost; this._options.axios = this._options.axios || axios_1.default.create({ timeout: 10000 }); (0, interceptors_1.responseErrorInterceptor)(this)(this._options.axios); (0, interceptors_1.responseUpdateXMBXUsedWeight)(this)(this._options.axios); } get options() { return this._options; } get axios() { return this.options.axios; } get spotApiEndpoint() { return this.options.spotApiEndpoint; } get spotSocketEndpoint() { return this.options.spotSocketEndpoint; } get usdFuturesApiEndpoint() { return this.options.usdFuturesApiEndpoint; } get usdFuturesSocketEndpoint() { return this.options.usdFuturesSocketEndpoint; } get coinFuturesApiEndpoint() { return this.options.coinFuturesApiEndpoint; } get coinFuturesSocketEndpoint() { return this.options.coinFuturesSocketEndpoint; } get vanillaApiEndpoint() { return this.options.vanillaApiEndpoint; } get vanillaSocketEndpoint() { return this.options.vanillaSocketEndpoint; } get XMBXUsedWeight() { return this[info_1.CONST.SYMBOL_X_MBX_USED_WEIGHT] || 0; } } exports.BinanceClient = BinanceClient; _a = info_1.CONST.SYMBOL_X_MBX_USED_WEIGHT; //# sourceMappingURL=binanceClient.js.map