UNPKG

ccxt

Version:

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

1,169 lines (1,167 loc) • 158 kB
// ---------------------------------------------------------------------------- // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN: // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code // EDIT THE CORRESPONDENT .ts FILE INSTEAD // --------------------------------------------------------------------------- import Exchange from './abstract/whitebit.js'; import { ExchangeNotAvailable, ExchangeError, DDoSProtection, BadSymbol, InvalidOrder, ArgumentsRequired, AuthenticationError, OrderNotFound, PermissionDenied, InsufficientFunds, BadRequest, NotSupported } from './base/errors.js'; import { Precise } from './base/Precise.js'; import { TICK_SIZE } from './base/functions/number.js'; import { sha512 } from './static_dependencies/noble-hashes/sha512.js'; // --------------------------------------------------------------------------- /** * @class whitebit * @augments Exchange */ export default class whitebit extends Exchange { 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': true, 'future': false, 'option': false, 'cancelAllOrders': true, 'cancelAllOrdersAfter': true, 'cancelOrder': true, 'cancelOrders': false, 'createConvertTrade': true, 'createDepositAddress': true, 'createMarketBuyOrderWithCost': true, 'createMarketOrderWithCost': false, 'createMarketSellOrderWithCost': false, 'createOrder': true, 'createPostOnlyOrder': true, 'createStopLimitOrder': true, 'createStopMarketOrder': true, 'createStopOrder': true, 'createTriggerOrder': true, 'editOrder': false, 'fetchBalance': true, 'fetchBorrowRateHistories': false, 'fetchBorrowRateHistory': false, 'fetchClosedOrders': true, 'fetchConvertQuote': true, 'fetchConvertTrade': false, 'fetchConvertTradeHistory': true, 'fetchCrossBorrowRate': true, 'fetchCrossBorrowRates': false, 'fetchCurrencies': true, 'fetchDeposit': true, 'fetchDepositAddress': true, 'fetchDepositAddresses': false, 'fetchDepositAddressesByNetwork': false, 'fetchDeposits': true, 'fetchDepositsWithdrawals': true, 'fetchDepositWithdrawFee': 'emulated', 'fetchDepositWithdrawFees': true, 'fetchFundingHistory': true, '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, 'fetchPosition': true, 'fetchPositionHistory': true, 'fetchPositionMode': false, 'fetchPositions': true, '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/depth/{market}', 'orderbook/{market}', 'ticker', 'trades/{market}', 'time', 'ping', 'markets', 'futures', 'platform/status', 'mining-pool', ], }, 'private': { 'post': [ 'collateral-account/balance', 'collateral-account/balance-summary', 'collateral-account/positions/history', 'collateral-account/leverage', 'collateral-account/positions/open', 'collateral-account/summary', 'collateral-account/funding-history', '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/collateral/bulk', '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', 'order/conditional-cancel', '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', 'sub-account/api-key/create', 'sub-account/api-key/edit', 'sub-account/api-key/delete', 'sub-account/api-key/list', 'sub-account/api-key/reset', 'sub-account/api-key/ip-address/list', 'sub-account/api-key/ip-address/create', 'sub-account/api-key/ip-address/delete', 'mining/rewards', 'market/fee', 'conditional-orders', ], }, }, }, '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': TICK_SIZE, 'exceptions': { 'exact': { 'Unauthorized request.': AuthenticationError, 'The market format is invalid.': BadSymbol, 'Market is not available': BadSymbol, 'Invalid payload.': BadRequest, 'Amount must be greater than 0': InvalidOrder, 'Not enough balance.': InsufficientFunds, 'The order id field is required.': InvalidOrder, 'Not enough balance': InsufficientFunds, 'This action is unauthorized.': PermissionDenied, 'This API Key is not authorized to perform this action.': PermissionDenied, 'Unexecuted order was not found.': OrderNotFound, 'The selected from is invalid.': BadRequest, '503': ExchangeNotAvailable, '422': 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': PermissionDenied, 'Given amount is less than min amount': InvalidOrder, 'Min amount step': InvalidOrder, 'Total is less than': InvalidOrder, 'fee must be no less than': InvalidOrder, 'Enable your key in API settings': PermissionDenied, 'You don\'t have such amount for transfer': 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.stringDiv(takerFeeRate, '100'); const makerFeeRate = this.safeString(market, 'makerFee'); const maker = Precise.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.0003", // max_withdraw: "0", // maker_fee: "0.1", // taker_fee: "0.1", // min_deposit: "0.0001", // max_deposit: "0", // networks: { // deposits: [ "BTC", ], // withdraws: [ "BTC", ], // default: "BTC", // }, // confirmations: { // BTC: "2", // }, // limits: { // deposit: { // BTC: { min: "0.0001", }, // }, // withdraw: { // BTC: { min: "0.0003", }, // }, // }, // currency_precision: "8", // is_memo: false, // }, // USD: { // name: "United States Dollar", // unified_cryptoasset_id: "6955", // can_withdraw: true, // can_deposit: true, // min_withdraw: "10", // max_withdraw: "10000", // maker_fee: "0.1", // taker_fee: "0.1", // min_deposit: "10", // max_deposit: "10000", // networks: { // deposits: [ "USD", ], // withdraws: [ "USD", ], // default: "USD", // }, // providers: { // deposits: [ "ADVCASH", ], // withdraws: [ "ADVCASH", ], // }, // limits: { // deposit: { // USD: { max: "10000", min: "10", }, // }, // withdraw: { // USD: { max: "10000", min: "10", }, // }, // }, // currency_precision: "2", // is_memo: false, // } // } // const ids = Object.keys(response); const result = {}; for (let i = 0; i < ids.length; i++) { const id = ids[i]; const currency = response[id]; // const name = this.safeString (currency, 'name'); // breaks down in Python due to utf8 encoding issues on the exchange side const code = this.safeCurrencyCode(id); const hasProvider = ('providers' in currency); const networks = {}; const rawNetworks = this.safeDict(currency, 'networks', {}); const depositsNetworks = this.safeList(rawNetworks, 'deposits', []); const withdrawsNetworks = this.safeList(rawNetworks, 'withdraws', []); const networkLimits = this.safeDict(currency, 'limits', {}); const depositLimits = this.safeDict(networkLimits, 'deposit', {}); const withdrawLimits = this.safeDict(networkLimits, 'withdraw', {}); const allNetworks = this.arrayConcat(depositsNetworks, withdrawsNetworks); for (let j = 0; j < allNetworks.length; j++) { const networkId = allNetworks[j]; const networkCode = this.networkIdToCode(networkId); networks[networkCode] = { 'id': networkId, 'network': networkCode, 'active': undefined, 'deposit': this.inArray(networkId, depositsNetworks), 'withdraw': this.inArray(networkId, withdrawsNetworks), 'fee': undefined, 'precision': undefined, 'limits': { 'deposit': { 'min': this.safeNumber(depositLimits, 'min', undefined), 'max': this.safeNumber(depositLimits, 'max', undefined), }, 'withdraw': { 'min': this.safeNumber(withdrawLimits, 'min', undefined), 'max': this.safeNumber(withdrawLimits, 'max', undefined), }, }, }; } result[code] = this.safeCurrencyStructure({ 'id': id, 'code': code, 'info': currency, 'name': undefined, 'active': undefined, 'deposit': this.safeBool(currency, 'can_deposit'), 'withdraw': this.safeBool(currency, 'can_withdraw'), 'fee': undefined, 'networks': undefined, 'type': hasProvider ? 'fiat' : 'crypto', 'precision': this.parseNumber(this.parsePrecision(this.safeString(currency, 'currency_precision'))), 'limits': { 'amount': { 'min': undefined, 'max': undefined, }, 'withdraw': { 'min': this.safeNumber(currency, 'min_withdraw'), 'max': this.safeNumber(currency, 'max_withdraw'), }, 'deposit': { 'min': this.safeNumber(currency, 'min_deposit'), 'max': this.safeNumber(currency, 'max_deposit'), }, }, }); } 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.stringDiv(makerFee, '100'); takerFee = Precise.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", /