UNPKG

ccxt

Version:

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges

1,189 lines (1,187 loc) • 129 kB
'use strict'; var whitebit$1 = require('./abstract/whitebit.js'); var errors = require('./base/errors.js'); var Precise = require('./base/Precise.js'); var number = require('./base/functions/number.js'); var sha512 = require('./static_dependencies/noble-hashes/sha512.js'); // ---------------------------------------------------------------------------- // --------------------------------------------------------------------------- /** * @class whitebit * @augments Exchange */ class whitebit extends whitebit$1 { describe() { return this.deepExtend(super.describe(), { 'id': 'whitebit', 'name': 'WhiteBit', 'version': 'v4', 'countries': ['EE'], 'rateLimit': 50, 'pro': true, 'has': { 'CORS': undefined, 'spot': true, 'margin': true, 'swap': false, 'future': false, 'option': false, 'cancelAllOrders': true, 'cancelAllOrdersAfter': true, 'cancelOrder': true, 'cancelOrders': false, 'createMarketBuyOrderWithCost': true, 'createMarketOrderWithCost': false, 'createMarketSellOrderWithCost': false, 'createOrder': true, 'createStopLimitOrder': true, 'createStopMarketOrder': true, 'createStopOrder': true, 'editOrder': false, 'fetchBalance': true, 'fetchBorrowRateHistories': false, 'fetchBorrowRateHistory': false, 'fetchClosedOrders': true, 'fetchCrossBorrowRate': false, 'fetchCrossBorrowRates': false, 'fetchCurrencies': true, 'fetchDeposit': true, 'fetchDepositAddress': true, 'fetchDepositAddresses': false, 'fetchDepositAddressesByNetwork': false, 'fetchDeposits': true, 'fetchDepositsWithdrawals': true, 'fetchDepositWithdrawFee': 'emulated', 'fetchDepositWithdrawFees': true, 'fetchFundingHistory': false, 'fetchFundingRate': true, 'fetchFundingRateHistory': false, 'fetchFundingRates': true, 'fetchIndexOHLCV': false, 'fetchIsolatedBorrowRate': false, 'fetchIsolatedBorrowRates': false, 'fetchMarginMode': false, 'fetchMarkets': true, 'fetchMarkOHLCV': false, 'fetchMyTrades': true, 'fetchOHLCV': true, 'fetchOpenInterestHistory': false, 'fetchOpenOrders': true, 'fetchOrderBook': true, 'fetchOrderTrades': true, 'fetchPositionMode': false, 'fetchPremiumIndexOHLCV': false, 'fetchStatus': true, 'fetchTicker': true, 'fetchTickers': true, 'fetchTime': true, 'fetchTrades': true, 'fetchTradingFee': false, 'fetchTradingFees': true, 'fetchTransactionFees': true, 'repayCrossMargin': false, 'repayIsolatedMargin': false, 'setLeverage': true, 'transfer': true, 'withdraw': true, }, 'timeframes': { '1m': '1m', '3m': '3m', '5m': '5m', '15m': '15m', '30m': '30m', '1h': '1h', '2h': '2h', '4h': '4h', '6h': '6h', '8h': '8h', '12h': '12h', '1d': '1d', '3d': '3d', '1w': '1w', '1M': '1M', }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/1294454/66732963-8eb7dd00-ee66-11e9-849b-10d9282bb9e0.jpg', 'api': { 'v1': { 'public': 'https://whitebit.com/api/v1/public', 'private': 'https://whitebit.com/api/v1', }, 'v2': { 'public': 'https://whitebit.com/api/v2/public', }, 'v4': { 'public': 'https://whitebit.com/api/v4/public', 'private': 'https://whitebit.com/api/v4', }, }, 'www': 'https://www.whitebit.com', 'doc': 'https://github.com/whitebit-exchange/api-docs', 'fees': 'https://whitebit.com/fee-schedule', 'referral': 'https://whitebit.com/referral/d9bdf40e-28f2-4b52-b2f9-cd1415d82963', }, 'api': { 'web': { 'get': [ 'v1/healthcheck', ], }, 'v1': { 'public': { 'get': [ 'markets', 'tickers', 'ticker', 'symbols', 'depth/result', 'history', 'kline', ], }, 'private': { 'post': [ 'account/balance', 'order/new', 'order/cancel', 'orders', 'account/order_history', 'account/executed_history', 'account/executed_history/all', 'account/order', ], }, }, 'v2': { 'public': { 'get': [ 'markets', 'ticker', 'assets', 'fee', 'depth/{market}', 'trades/{market}', ], }, }, 'v4': { 'public': { 'get': [ 'assets', 'collateral/markets', 'fee', 'orderbook/{market}', 'ticker', 'trades/{market}', 'time', 'ping', 'markets', 'futures', 'platform/status', ], }, 'private': { 'post': [ 'collateral-account/balance', 'collateral-account/balance-summary', 'collateral-account/positions/history', 'collateral-account/leverage', 'collateral-account/positions/open', 'collateral-account/summary', 'main-account/address', 'main-account/balance', 'main-account/create-new-address', 'main-account/codes', 'main-account/codes/apply', 'main-account/codes/my', 'main-account/codes/history', 'main-account/fiat-deposit-url', 'main-account/history', 'main-account/withdraw', 'main-account/withdraw-pay', 'main-account/transfer', 'main-account/smart/plans', 'main-account/smart/investment', 'main-account/smart/investment/close', 'main-account/smart/investments', 'main-account/fee', 'main-account/smart/interest-payment-history', 'trade-account/balance', 'trade-account/executed-history', 'trade-account/order', 'trade-account/order/history', 'order/collateral/limit', 'order/collateral/market', 'order/collateral/stop-limit', 'order/collateral/trigger-market', 'order/new', 'order/market', 'order/stock_market', 'order/stop_limit', 'order/stop_market', 'order/cancel', 'order/cancel/all', 'order/kill-switch', 'order/kill-switch/status', 'order/bulk', 'order/modify', 'orders', 'oco-orders', 'order/collateral/oco', 'order/oco-cancel', 'order/oto-cancel', 'profile/websocket_token', 'convert/estimate', 'convert/confirm', 'convert/history', 'sub-account/create', 'sub-account/delete', 'sub-account/edit', 'sub-account/list', 'sub-account/transfer', 'sub-account/block', 'sub-account/unblock', 'sub-account/balances', 'sub-account/transfer/history', ], }, }, }, 'fees': { 'trading': { 'tierBased': false, 'percentage': true, 'taker': this.parseNumber('0.001'), 'maker': this.parseNumber('0.001'), }, }, 'options': { 'timeDifference': 0, 'adjustForTimeDifference': false, 'fiatCurrencies': ['EUR', 'USD', 'RUB', 'UAH'], 'fetchBalance': { 'account': 'spot', }, 'accountsByType': { 'funding': 'main', 'main': 'main', 'spot': 'spot', 'margin': 'collateral', 'trade': 'spot', }, 'networksById': { 'BEP20': 'BSC', }, 'defaultType': 'spot', 'brokerId': 'ccxt', }, 'features': { 'default': { 'sandbox': false, 'createOrder': { 'marginMode': true, 'triggerPrice': true, 'triggerDirection': false, 'triggerPriceType': undefined, 'stopLossPrice': false, 'takeProfitPrice': false, 'attachedStopLossTakeProfit': undefined, 'timeInForce': { 'IOC': true, 'FOK': false, 'PO': true, 'GTD': false, }, 'hedged': false, 'trailing': false, 'leverage': false, 'marketBuyByCost': true, 'marketBuyRequiresPrice': false, 'selfTradePrevention': false, 'iceberg': false, }, 'createOrders': undefined, 'fetchMyTrades': { 'marginMode': false, 'limit': 100, 'daysBack': undefined, 'untilDays': undefined, 'symbolRequired': false, }, 'fetchOrder': undefined, 'fetchOpenOrders': { 'marginMode': false, 'limit': 100, 'trigger': false, 'trailing': false, 'symbolRequired': false, }, 'fetchOrders': undefined, 'fetchClosedOrders': { 'marginMode': false, 'limit': 100, 'daysBack': undefined, 'daysBackCanceled': undefined, 'untilDays': undefined, 'trigger': false, 'trailing': false, 'symbolRequired': false, }, 'fetchOHLCV': { 'limit': 1440, }, }, 'spot': { 'extends': 'default', }, 'swap': { 'linear': { 'extends': 'default', }, 'inverse': { 'extends': 'default', }, }, 'future': { 'linear': undefined, 'inverse': undefined, }, }, 'precisionMode': number.TICK_SIZE, 'exceptions': { 'exact': { 'Unauthorized request.': errors.AuthenticationError, 'The market format is invalid.': errors.BadSymbol, 'Market is not available': errors.BadSymbol, 'Invalid payload.': errors.BadRequest, 'Amount must be greater than 0': errors.InvalidOrder, 'Not enough balance.': errors.InsufficientFunds, 'The order id field is required.': errors.InvalidOrder, 'Not enough balance': errors.InsufficientFunds, 'This action is unauthorized.': errors.PermissionDenied, 'This API Key is not authorized to perform this action.': errors.PermissionDenied, 'Unexecuted order was not found.': errors.OrderNotFound, 'The selected from is invalid.': errors.BadRequest, '503': errors.ExchangeNotAvailable, '422': errors.OrderNotFound, // {"response":null,"status":422,"errors":{"orderId":["Finished order id 1295772653 not found on your account"]},"notification":null,"warning":"Finished order id 1295772653 not found on your account","_token":null} }, 'broad': { 'This action is unauthorized': errors.PermissionDenied, 'Given amount is less than min amount': errors.InvalidOrder, 'Min amount step': errors.InvalidOrder, 'Total is less than': errors.InvalidOrder, 'fee must be no less than': errors.InvalidOrder, 'Enable your key in API settings': errors.PermissionDenied, 'You don\'t have such amount for transfer': errors.InsufficientFunds, // {"code":3,"message":"Inner validation failed","errors":{"amount":["You don't have such amount for transfer (available 0.44523433, in amount: 2)"]}} }, }, }); } /** * @method * @name whitebit#fetchMarkets * @description retrieves data on all markets for whitebit * @see https://docs.whitebit.com/public/http-v4/#market-info * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {object[]} an array of objects representing market data */ async fetchMarkets(params = {}) { if (this.options['adjustForTimeDifference']) { await this.loadTimeDifference(); } const markets = await this.v4PublicGetMarkets(); // // [ // { // "name": "SON_USD", // Market pair name // "stock": "SON", // Ticker of stock currency // "money": "USD", // Ticker of money currency // "stockPrec": "3", // Stock currency precision // "moneyPrec": "2", // Precision of money currency // "feePrec": "4", // Fee precision // "makerFee": "0.1", // Default maker fee ratio // "takerFee": "0.1", // Default taker fee ratio // "minAmount": "0.001", // Minimal amount of stock to trade // "minTotal": "0.001", // Minimal amount of money to trade // "tradesEnabled": true, // Is trading enabled // "isCollateral": true, // Is margin trading enabled // "type": "spot", // Market type. Possible values: "spot", "futures" // "maxTotal": "1000000000" // Maximum total(amount * price) of money to trade // }, // { // ... // } // ] // return this.parseMarkets(markets); } parseMarket(market) { const id = this.safeString(market, 'name'); const baseId = this.safeString(market, 'stock'); let quoteId = this.safeString(market, 'money'); quoteId = (quoteId === 'PERP') ? 'USDT' : quoteId; const base = this.safeCurrencyCode(baseId); const quote = this.safeCurrencyCode(quoteId); const active = this.safeValue(market, 'tradesEnabled'); const isCollateral = this.safeValue(market, 'isCollateral'); const typeId = this.safeString(market, 'type'); let type; let settle = undefined; let settleId = undefined; let symbol = base + '/' + quote; const swap = typeId === 'futures'; const margin = isCollateral && !swap; let contract = false; const amountPrecision = this.parseNumber(this.parsePrecision(this.safeString(market, 'stockPrec'))); const contractSize = amountPrecision; let linear = undefined; let inverse = undefined; if (swap) { settleId = quoteId; settle = this.safeCurrencyCode(settleId); symbol = symbol + ':' + settle; type = 'swap'; contract = true; linear = true; inverse = false; } else { type = 'spot'; } const takerFeeRate = this.safeString(market, 'takerFee'); const taker = Precise["default"].stringDiv(takerFeeRate, '100'); const makerFeeRate = this.safeString(market, 'makerFee'); const maker = Precise["default"].stringDiv(makerFeeRate, '100'); return { 'id': id, 'symbol': symbol, 'base': base, 'quote': quote, 'settle': settle, 'baseId': baseId, 'quoteId': quoteId, 'settleId': settleId, 'type': type, 'spot': !swap, 'margin': margin, 'swap': swap, 'future': false, 'option': false, 'active': active, 'contract': contract, 'linear': linear, 'inverse': inverse, 'taker': this.parseNumber(taker), 'maker': this.parseNumber(maker), 'contractSize': contractSize, 'expiry': undefined, 'expiryDatetime': undefined, 'strike': undefined, 'optionType': undefined, 'precision': { 'amount': amountPrecision, 'price': this.parseNumber(this.parsePrecision(this.safeString(market, 'moneyPrec'))), }, 'limits': { 'leverage': { 'min': undefined, 'max': undefined, }, 'amount': { 'min': this.safeNumber(market, 'minAmount'), 'max': undefined, }, 'price': { 'min': undefined, 'max': undefined, }, 'cost': { 'min': this.safeNumber(market, 'minTotal'), 'max': this.safeNumber(market, 'maxTotal'), }, }, 'created': undefined, 'info': market, }; } /** * @method * @name whitebit#fetchCurrencies * @description fetches all available currencies on an exchange * @see https://docs.whitebit.com/public/http-v4/#asset-status-list * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {object} an associative dictionary of currencies */ async fetchCurrencies(params = {}) { const response = await this.v4PublicGetAssets(params); // // "BTC": { // "name": "Bitcoin", // "unified_cryptoasset_id": 1, // "can_withdraw": true, // "can_deposit": true, // "min_withdraw": "0.001", // "max_withdraw": "2", // "maker_fee": "0.1", // "taker_fee": "0.1", // "min_deposit": "0.0001", // "max_deposit": "0", // }, // const ids = Object.keys(response); const result = {}; for (let i = 0; i < ids.length; i++) { const id = ids[i]; const currency = response[id]; // breaks down in Python due to utf8 encoding issues on the exchange side // const name = this.safeString (currency, 'name'); const canDeposit = this.safeBool(currency, 'can_deposit', true); const canWithdraw = this.safeBool(currency, 'can_withdraw', true); const active = canDeposit && canWithdraw; const code = this.safeCurrencyCode(id); result[code] = { 'id': id, 'code': code, 'info': currency, 'name': undefined, 'active': active, 'deposit': canDeposit, 'withdraw': canWithdraw, 'fee': undefined, 'precision': undefined, 'limits': { 'amount': { 'min': undefined, 'max': undefined, }, 'withdraw': { 'min': this.safeNumber(currency, 'min_withdraw'), 'max': this.safeNumber(currency, 'max_withdraw'), }, }, }; } return result; } /** * @method * @name whitebit#fetchTransactionFees * @deprecated * @description please use fetchDepositWithdrawFees instead * @see https://docs.whitebit.com/public/http-v4/#fee * @param {string[]|undefined} codes not used by fetchTransactionFees () * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} */ async fetchTransactionFees(codes = undefined, params = {}) { await this.loadMarkets(); const response = await this.v4PublicGetFee(params); // // { // "1INCH":{ // "is_depositable":true, // "is_withdrawal":true, // "ticker":"1INCH", // "name":"1inch", // "providers":[ // ], // "withdraw":{ // "max_amount":"0", // "min_amount":"21.5", // "fixed":"17.5", // "flex":null // }, // "deposit":{ // "max_amount":"0", // "min_amount":"19.5", // "fixed":null, // "flex":null // } // }, // {...} // } // const currenciesIds = Object.keys(response); const withdrawFees = {}; const depositFees = {}; for (let i = 0; i < currenciesIds.length; i++) { const currency = currenciesIds[i]; const data = response[currency]; const code = this.safeCurrencyCode(currency); const withdraw = this.safeValue(data, 'withdraw', {}); withdrawFees[code] = this.safeString(withdraw, 'fixed'); const deposit = this.safeValue(data, 'deposit', {}); depositFees[code] = this.safeString(deposit, 'fixed'); } return { 'withdraw': withdrawFees, 'deposit': depositFees, 'info': response, }; } /** * @method * @name whitebit#fetchDepositWithdrawFees * @description fetch deposit and withdraw fees * @see https://docs.whitebit.com/public/http-v4/#fee * @param {string[]|undefined} codes not used by fetchDepositWithdrawFees () * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} */ async fetchDepositWithdrawFees(codes = undefined, params = {}) { await this.loadMarkets(); const response = await this.v4PublicGetFee(params); // // { // "1INCH": { // "is_depositable": true, // "is_withdrawal": true, // "ticker": "1INCH", // "name": "1inch", // "providers": [], // "withdraw": { // "max_amount": "0", // "min_amount": "21.5", // "fixed": "17.5", // "flex": null // }, // "deposit": { // "max_amount": "0", // "min_amount": "19.5", // "fixed": null, // "flex": null // } // }, // "WBT (ERC20)": { // "is_depositable": true, // "is_withdrawal": true, // "ticker": "WBT", // "name": "WhiteBIT Token", // "providers": [], // "withdraw": { max_amount: "0", min_amount: '0.7', fixed: "0.253", flex: null }, // "deposit": { max_amount: "0", min_amount: "0.35", fixed: null, flex: null } // }, // "WBT (TRC20)": { // "is_depositable": true, // "is_withdrawal": true, // "ticker": "WBT", // "name": "WhiteBIT Token", // "providers": [], // "withdraw": { max_amount: "0", min_amount: "1.5", fixed: "0.075", flex: null }, // "deposit": { max_amount: "0", min_amount: "0.75", fixed: null, flex: null } // }, // ... // } // return this.parseDepositWithdrawFees(response, codes); } parseDepositWithdrawFees(response, codes = undefined, currencyIdKey = undefined) { // // { // "1INCH": { // "is_depositable": true, // "is_withdrawal": true, // "ticker": "1INCH", // "name": "1inch", // "providers": [], // "withdraw": { // "max_amount": "0", // "min_amount": "21.5", // "fixed": "17.5", // "flex": null // }, // "deposit": { // "max_amount": "0", // "min_amount": "19.5", // "fixed": null, // "flex": null // } // }, // "WBT (ERC20)": { // "is_depositable": true, // "is_withdrawal": true, // "ticker": "WBT", // "name": "WhiteBIT Token", // "providers": [], // "withdraw": { max_amount: "0", min_amount: "0.7", fixed: "0.253", flex: null }, // "deposit": { max_amount: "0", min_amount: "0.35", fixed: null, flex: null } // }, // "WBT (TRC20)": { // "is_depositable": true, // "is_withdrawal": true, // "ticker": "WBT", // "name": "WhiteBIT Token", // "providers": [], // "withdraw": { max_amount: "0", min_amount: "1.5", fixed: "0.075", flex: null }, // "deposit": { max_amount: "0", min_amount: "0.75", fixed: null, flex: null } // }, // ... // } // const depositWithdrawFees = {}; codes = this.marketCodes(codes); const currencyIds = Object.keys(response); for (let i = 0; i < currencyIds.length; i++) { const entry = currencyIds[i]; const splitEntry = entry.split(' '); const currencyId = splitEntry[0]; const feeInfo = response[entry]; const code = this.safeCurrencyCode(currencyId); if ((codes === undefined) || (this.inArray(code, codes))) { const depositWithdrawFee = this.safeValue(depositWithdrawFees, code); if (depositWithdrawFee === undefined) { depositWithdrawFees[code] = this.depositWithdrawFee({}); } depositWithdrawFees[code]['info'][entry] = feeInfo; let networkId = this.safeString(splitEntry, 1); const withdraw = this.safeValue(feeInfo, 'withdraw'); const deposit = this.safeValue(feeInfo, 'deposit'); const withdrawFee = this.safeNumber(withdraw, 'fixed'); const depositFee = this.safeNumber(deposit, 'fixed'); const withdrawResult = { 'fee': withdrawFee, 'percentage': (withdrawFee !== undefined) ? false : undefined, }; const depositResult = { 'fee': depositFee, 'percentage': (depositFee !== undefined) ? false : undefined, }; if (networkId !== undefined) { const networkLength = networkId.length; networkId = networkId.slice(1, networkLength - 1); const networkCode = this.networkIdToCode(networkId); depositWithdrawFees[code]['networks'][networkCode] = { 'withdraw': withdrawResult, 'deposit': depositResult, }; } else { depositWithdrawFees[code]['withdraw'] = withdrawResult; depositWithdrawFees[code]['deposit'] = depositResult; } } } const depositWithdrawCodes = Object.keys(depositWithdrawFees); for (let i = 0; i < depositWithdrawCodes.length; i++) { const code = depositWithdrawCodes[i]; const currency = this.currency(code); depositWithdrawFees[code] = this.assignDefaultDepositWithdrawFees(depositWithdrawFees[code], currency); } return depositWithdrawFees; } /** * @method * @name whitebit#fetchTradingFees * @description fetch the trading fees for multiple markets * @see https://docs.whitebit.com/public/http-v4/#asset-status-list * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols */ async fetchTradingFees(params = {}) { await this.loadMarkets(); const response = await this.v4PublicGetAssets(params); // // { // "1INCH": { // "name": "1inch", // "unified_cryptoasset_id": "8104", // "can_withdraw": true, // "can_deposit": true, // "min_withdraw": "33", // "max_withdraw": "0", // "maker_fee": "0.1", // "taker_fee": "0.1", // "min_deposit": "30", // "max_deposit": "0" // }, // ... // } // const result = {}; for (let i = 0; i < this.symbols.length; i++) { const symbol = this.symbols[i]; const market = this.market(symbol); const fee = this.safeValue(response, market['baseId'], {}); let makerFee = this.safeString(fee, 'maker_fee'); let takerFee = this.safeString(fee, 'taker_fee'); makerFee = Precise["default"].stringDiv(makerFee, '100'); takerFee = Precise["default"].stringDiv(takerFee, '100'); result[symbol] = { 'info': fee, 'symbol': market['symbol'], 'percentage': true, 'tierBased': false, 'maker': this.parseNumber(makerFee), 'taker': this.parseNumber(takerFee), }; } return result; } /** * @method * @name whitebit#fetchTicker * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market * @see https://docs.whitebit.com/public/http-v4/#market-activity * @param {string} symbol unified symbol of the market to fetch the ticker for * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure} */ async fetchTicker(symbol, params = {}) { await this.loadMarkets(); const market = this.market(symbol); const request = { 'market': market['id'], }; const response = await this.v1PublicGetTicker(this.extend(request, params)); // // { // "success":true, // "message":"", // "result": { // "bid":"0.021979", // "ask":"0.021996", // "open":"0.02182", // "high":"0.022039", // "low":"0.02161", // "last":"0.021987", // "volume":"2810.267", // "deal":"61.383565474", // "change":"0.76", // }, // } // const ticker = this.safeDict(response, 'result', {}); return this.parseTicker(ticker, market); } parseTicker(ticker, market = undefined) { // // FetchTicker (v1) // // { // "bid": "0.021979", // "ask": "0.021996", // "open": "0.02182", // "high": "0.022039", // "low": "0.02161", // "last": "0.021987", // "volume": "2810.267", // "deal": "61.383565474", // "change": "0.76", // } // // FetchTickers (v4) // // "BCH_RUB": { // "base_id": 1831, // "quote_id": 0, // "last_price": "32830.21", // "quote_volume": "1494659.8024096", // "base_volume": "46.1083", // "isFrozen": false, // "change": "2.12" // in percent // } // // WS market_update // // { // "open": "52853.04", // "close": "55913.88", // "high": "56272", // "low": "49549.67", // "volume": "57331.067185", // "deal": "3063860382.42985338", // "last": "55913.88", // "period": 86400 // } // v2 // { // lastUpdateTimestamp: '2025-01-02T09:16:36.000Z', // tradingPairs: 'ARB_USDC', // lastPrice: '0.7727', // lowestAsk: '0.7735', // highestBid: '0.7732', // baseVolume24h: '1555793.74', // quoteVolume24h: '1157602.622406', // tradesEnabled: true // } // const marketId = this.safeString(ticker, 'tradingPairs'); market = this.safeMarket(marketId, market); // last price is provided as "last" or "last_price" const last = this.safeStringN(ticker, ['last', 'last_price', 'lastPrice']); // if "close" is provided, use it, otherwise use <last> const close = this.safeString(ticker, 'close', last); return this.safeTicker({ 'symbol': market['symbol'], 'timestamp': undefined, 'datetime': undefined, 'high': this.safeString(ticker, 'high'), 'low': this.safeString(ticker, 'low'), 'bid': this.safeString2(ticker, 'bid', 'highestBid'), 'bidVolume': undefined, 'ask': this.safeString2(ticker, 'ask', 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': this.safeString(ticker, 'open'), 'close': close, 'last': last, 'previousClose': undefined, 'change': undefined, 'percentage': this.safeString(ticker, 'change'), 'average': undefined, 'baseVolume': this.safeStringN(ticker, ['base_volume', 'volume', 'baseVolume24h']), 'quoteVolume': this.safeStringN(ticker, ['quote_volume', 'deal', 'quoteVolume24h']), 'info': ticker, }, market); } /** * @method * @name whitebit#fetchTickers * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market * @see https://docs.whitebit.com/public/http-v4/#market-activity * @param {string[]} [symbols] unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned * @param {object} [params] extra parameters specific to the exchange API endpoint * @param {string} [params.method] either v2PublicGetTicker or v4PublicGetTicker default is v4PublicGetTicker * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure} */ async fetchTickers(symbols = undefined, params = {}) { await this.loadMarkets(); symbols = this.marketSymbols(symbols); let method = 'v4PublicGetTicker'; [method, params] = this.handleOptionAndParams(params, 'fetchTickers', 'method', method); let response = undefined; if (method === 'v4PublicGetTicker') { response = await this.v4PublicGetTicker(params); } else { response = await this.v2PublicGetTicker(params); } // // "BCH_RUB": { // "base_id":1831, // "quote_id":0, // "last_price":"32830.21", // "quote_volume":"1494659.8024096", // "base_volume":"46.1083", // "isFrozen":false, // "change":"2.12" // }, // const resultList = this.safeList(response, 'result'); if (resultList !== undefined) { return this.parseTickers(resultList, symbols); } const marketIds = Object.keys(response); const result = {}; for (let i = 0; i < marketIds.length; i++) { const marketId = marketIds[i]; const market = this.safeMarket(marketId); const ticker = this.parseTicker(response[marketId], market); const symbol = ticker['symbol']; result[symbol] = ticker; } return this.filterByArrayTickers(result, 'symbol', symbols); } /** * @method * @name whitebit#fetchOrderBook * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data * @see https://docs.whitebit.com/public/http-v4/#orderbook * @param {string} symbol unified symbol of the market to fetch the order book for * @param {int} [limit] the maximum amount of order book entries to return * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols */ async fetchOrderBook(symbol, limit = undefined, params = {}) { await this.loadMarkets(); const market = this.market(symbol); const request = { 'market': market['id'], }; if (limit !== undefined) { request['limit'] = limit; // default = 100, maximum = 100 } const response = await this.v4PublicGetOrderbookMarket(this.extend(request, params)); // // { // "timestamp": 1594391413, // "asks": [ // [ // "9184.41", // "0.773162" // ], // [ ... ] // ], // "bids": [ // [ // "9181.19", // "0.010873" // ], // [ ... ] // ] // } // const timestamp = this.safeTimestamp(response, 'timestamp'); return this.parseOrderBook(response, symbol, timestamp); } /** * @method * @name whitebit#fetchTrades * @description get the list of most recent trades for a particular symbol * @see https://docs.whitebit.com/public/http-v4/#recent-trades * @param {string} symbol unified symbol of the market to fetch trades for * @param {int} [since] timestamp in ms of the earliest trade to fetch * @param {int} [limit] the maximum amount of trades to fetch * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades} */ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) { await this.loadMarkets(); const market = this.market(symbol); const request = { 'market': market['id'], }; const response = await this.v4PublicGetTradesMarket(this.extend(request, params)); // // [ // { // "tradeID": 158056419, // "price": "9186.13", // "quote_volume": "0.0021", // "base_volume": "9186.13", // "trade_timestamp": 1594391747, // "type": "sell" // }, // ], // return this.parseTrades(response, market, since, limit); } /** * @method * @name whitebit#fetchMyTrades * @description fetch all trades made by the user * @see https://docs.whitebit.com/private/http-trade-v4/#query-executed-order-history * @param {string} symbol unified symbol of the market to fetch trades for * @param {int} [since] timestamp in ms of the earliest trade to fetch * @param {int} [limit] the maximum amount of trades to fetch * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades} */ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) { await this.loadMarkets(); let market = undefined; const request = {}; if (symbol !== undefined) { market = this.market(symbol); request['market'] = market['id']; } const response = await this.v4PrivatePostTradeAccountExecutedHistory(this.extend(request, params)); // // when no symbol is provided // // { // "USDC_USDT":[ // { // "id":"1343815269", // "clientOrderId":"", // "time":"1641051917.532965", // "side":"sell", // "role":"2", // "amount":"9.986", // "price":"0.9995", // "deal":"9.981007", // "fee":"0.009981007", // "orderId":"58166729555" // }, // ] // } // // when a symbol is provided // // [ // { // "id": 1343815269, // "clientOrderId": '', // "time": 1641051917.532965, // "side": "sell", // "role": 2, // "amount": "9.986", // "price": "0.9995", // "deal": "9.981007", // "fee": "0.009981007", // "orderId": 58166729555, // }, // ] // if (Array.isArray(response)) { return this.parseTrades(response, market, since, limit); } else { let results = []; const keys = Object.keys(response); for (let i = 0; i < keys.length; i++) { const marketId = keys[i]; const marketNew = this.safeMarket(marketId, undefined, '_'); const rawTrades = this.safeValue(response, marketId, []); const parsed = this.parseTrades(rawTrades, marketNew, since, limit); results = this.arrayConcat(results, parsed); } results = this.sortBy2(results, 'timestamp', 'id'); return this.filterBySinceLimit(results, since, limit, 'timestamp'); } } parseTrade(trade, market = undefined) { // // fetchTradesV4 // // { // "tradeID": 158056419, // "price": "9186.13", // "quote_volume": "0.0021", // "base_volume": "9186.13", // "trade_timestamp": 1594391747, // "type": "sell" // } // // orderTrades (v4Private) // // { // "time": 1593342324.613711, // "fee": "0.00000419198", // "price": "0.00000701", // "amount": "598", // "id": 149156519, // trade id // "dealOrderId": 3134995325, // orderId // "clientOrderId": "customId11", // "role": 2, // 1 = maker, 2 = taker // "deal": "0.00419198" // amount in money // } // // fetchMyTrades // // { // "id": 1343815269, // "clientOrderId": '', // "time": 1641051917.532965, // "side": "sell", // "role": 2, // "amount": "9.986", // "price": "0.9995", // "deal": "9.981007", // "fee": "0.009981007", // "orderId": 58166729555, // } // market = this.safeMarket(undefined, market); const timestamp = this.safeTimestamp2(trade, 'time', 'trade_timestamp'); const orderId = this.safeString2(trade, 'dealOrderId', 'orderId'); const cost = this.safeString(trade, 'deal'); const price = this.safeString(trade, 'price'); const amount = this.safeString2(trade, 'amount', 'quote_volume'); const id = this.safeString2(trade, 'id', 'tradeID'); const side = this.safeString2(trade, 'type', 'side'); const symbol = market['symbol']; const role = this.safeInteger(trade, 'role'); let takerOrMaker = undefined; if (role