UNPKG

sfccxt

Version:

A JavaScript / Python / PHP cryptocurrency trading library with support for 130+ exchanges

1,113 lines (1,086 loc) 103 kB
'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, BadSymbol, ExchangeError, ExchangeNotAvailable, AuthenticationError, InvalidOrder, InsufficientFunds, OrderNotFound, DDoSProtection, PermissionDenied, AddressPending, OnMaintenance, BadRequest, InvalidAddress } = require ('./base/errors'); const { TRUNCATE, TICK_SIZE } = require ('./base/functions/number'); // --------------------------------------------------------------------------- module.exports = class bittrex extends Exchange { describe () { return this.deepExtend (super.describe (), { 'id': 'bittrex', 'name': 'Bittrex', 'countries': [ 'US' ], 'version': 'v3', 'rateLimit': 1500, 'certified': false, 'pro': true, // new metainfo interface 'has': { 'CORS': undefined, 'spot': true, 'margin': false, 'swap': false, 'future': false, 'option': false, 'addMargin': false, 'cancelAllOrders': true, 'cancelOrder': true, 'createDepositAddress': true, 'createMarketOrder': true, 'createOrder': true, 'createReduceOnlyOrder': false, 'createStopLimitOrder': true, 'createStopMarketOrder': true, 'createStopOrder': true, 'fetchBalance': true, 'fetchBidsAsks': true, 'fetchBorrowRate': false, 'fetchBorrowRateHistories': false, 'fetchBorrowRateHistory': false, 'fetchBorrowRates': false, 'fetchBorrowRatesPerSymbol': false, 'fetchClosedOrders': true, 'fetchCurrencies': true, 'fetchDeposit': true, 'fetchDepositAddress': true, 'fetchDeposits': true, 'fetchFundingHistory': false, 'fetchFundingRate': false, 'fetchFundingRateHistory': false, 'fetchFundingRates': false, 'fetchIndexOHLCV': false, 'fetchLeverage': false, 'fetchLeverageTiers': false, 'fetchMarginMode': false, 'fetchMarkets': true, 'fetchMarkOHLCV': false, 'fetchMyTrades': true, 'fetchOHLCV': true, 'fetchOpenInterestHistory': false, 'fetchOpenOrders': true, 'fetchOrder': true, 'fetchOrderBook': true, 'fetchOrderTrades': true, 'fetchPosition': false, 'fetchPositionMode': false, 'fetchPositions': false, 'fetchPositionsRisk': false, 'fetchPremiumIndexOHLCV': false, 'fetchTicker': true, 'fetchTickers': true, 'fetchTime': true, 'fetchTrades': true, 'fetchTradingFee': true, 'fetchTradingFees': true, 'fetchTransactionFees': undefined, 'fetchTransactions': undefined, 'fetchWithdrawal': true, 'fetchWithdrawals': true, 'reduceMargin': false, 'setLeverage': false, 'setMarginMode': false, 'setPositionMode': false, 'withdraw': true, }, 'timeframes': { '1m': 'MINUTE_1', '5m': 'MINUTE_5', '1h': 'HOUR_1', '1d': 'DAY_1', }, 'hostname': 'bittrex.com', 'urls': { 'logo': 'https://user-images.githubusercontent.com/51840849/87153921-edf53180-c2c0-11ea-96b9-f2a9a95a455b.jpg', 'api': { 'public': 'https://api.bittrex.com', 'private': 'https://api.bittrex.com', }, 'www': 'https://bittrex.com', 'doc': [ 'https://bittrex.github.io/api/v3', ], 'fees': [ 'https://bittrex.zendesk.com/hc/en-us/articles/115003684371-BITTREX-SERVICE-FEES-AND-WITHDRAWAL-LIMITATIONS', 'https://bittrex.zendesk.com/hc/en-us/articles/115000199651-What-fees-does-Bittrex-charge-', ], 'referral': 'https://bittrex.com/Account/Register?referralCode=1ZE-G0G-M3B', }, 'api': { 'public': { 'get': [ 'ping', 'currencies', 'currencies/{symbol}', 'markets', 'markets/tickers', 'markets/summaries', 'markets/{marketSymbol}', 'markets/{marketSymbol}/summary', 'markets/{marketSymbol}/orderbook', 'markets/{marketSymbol}/trades', 'markets/{marketSymbol}/ticker', 'markets/{marketSymbol}/candles/{candleInterval}/recent', 'markets/{marketSymbol}/candles/{candleInterval}/historical/{year}/{month}/{day}', 'markets/{marketSymbol}/candles/{candleInterval}/historical/{year}/{month}', 'markets/{marketSymbol}/candles/{candleInterval}/historical/{year}', ], }, 'private': { 'get': [ 'account', 'account/fees/fiat', 'account/fees/fiat/{currencySymbol}', 'account/fees/trading', 'account/fees/trading/{marketSymbol}', 'account/volume', 'account/permissions/markets', 'account/permissions/markets/{marketSymbol}', 'account/permissions/currencies', 'account/permissions/currencies/{currencySymbol}', 'addresses', 'addresses/{currencySymbol}', 'balances', 'balances/{currencySymbol}', 'deposits/open', 'deposits/closed', 'deposits/ByTxId/{txId}', 'deposits/{depositId}', 'executions', 'executions/last-id', 'executions/{executionId}', 'orders/closed', 'orders/open', 'orders/{orderId}', 'orders/{orderId}/executions', 'ping', 'subaccounts/{subaccountId}', 'subaccounts', 'subaccounts/withdrawals/open', 'subaccounts/withdrawals/closed', 'subaccounts/deposits/open', 'subaccounts/deposits/closed', 'withdrawals/open', 'withdrawals/closed', 'withdrawals/ByTxId/{txId}', 'withdrawals/{withdrawalId}', 'withdrawals/allowed-addresses', 'conditional-orders/{conditionalOrderId}', 'conditional-orders/closed', 'conditional-orders/open', 'transfers/sent', 'transfers/received', 'transfers/{transferId}', 'funds-transfer-methods/{fundsTransferMethodId}', ], 'post': [ 'addresses', 'orders', 'subaccounts', 'withdrawals', 'conditional-orders', 'transfers', 'batch', ], 'delete': [ 'orders/open', 'orders/{orderId}', 'withdrawals/{withdrawalId}', 'conditional-orders/{conditionalOrderId}', ], }, }, 'fees': { 'trading': { 'tierBased': true, 'percentage': true, 'maker': this.parseNumber ('0.0075'), 'taker': this.parseNumber ('0.0075'), }, 'funding': { 'tierBased': false, 'percentage': false, }, }, 'precisionMode': TICK_SIZE, 'exceptions': { 'exact': { 'BAD_REQUEST': BadRequest, // {"code":"BAD_REQUEST","detail":"Refer to the data field for specific field validation failures.","data":{"invalidRequestParameter":"day"}} 'STARTDATE_OUT_OF_RANGE': BadRequest, // {"code":"STARTDATE_OUT_OF_RANGE"} // 'Call to Cancel was throttled. Try again in 60 seconds.': DDoSProtection, // 'Call to GetBalances was throttled. Try again in 60 seconds.': DDoSProtection, 'APISIGN_NOT_PROVIDED': AuthenticationError, 'APIKEY_INVALID': AuthenticationError, 'INVALID_SIGNATURE': AuthenticationError, 'INVALID_CURRENCY': ExchangeError, 'INVALID_PERMISSION': AuthenticationError, 'INSUFFICIENT_FUNDS': InsufficientFunds, 'INVALID_CEILING_MARKET_BUY': InvalidOrder, 'INVALID_FIAT_ACCOUNT': InvalidOrder, 'INVALID_ORDER_TYPE': InvalidOrder, 'QUANTITY_NOT_PROVIDED': InvalidOrder, 'MIN_TRADE_REQUIREMENT_NOT_MET': InvalidOrder, 'NOT_FOUND': OrderNotFound, 'ORDER_NOT_OPEN': OrderNotFound, 'INVALID_ORDER': InvalidOrder, 'UUID_INVALID': OrderNotFound, 'RATE_NOT_PROVIDED': InvalidOrder, // createLimitBuyOrder ('ETH/BTC', 1, 0) 'INVALID_MARKET': BadSymbol, // {"success":false,"message":"INVALID_MARKET","result":null,"explanation":null} 'WHITELIST_VIOLATION_IP': PermissionDenied, 'DUST_TRADE_DISALLOWED_MIN_VALUE': InvalidOrder, 'RESTRICTED_MARKET': BadSymbol, 'We are down for scheduled maintenance, but we\u2019ll be back up shortly.': OnMaintenance, // {"success":false,"message":"We are down for scheduled maintenance, but we\u2019ll be back up shortly.","result":null,"explanation":null} }, 'broad': { 'throttled': DDoSProtection, 'problem': ExchangeNotAvailable, }, }, 'options': { 'fetchTicker': { 'method': 'publicGetMarketsMarketSymbolTicker', // publicGetMarketsMarketSymbolSummary }, 'fetchTickers': { 'method': 'publicGetMarketsTickers', // publicGetMarketsSummaries }, 'fetchDeposits': { 'status': 'ok', }, 'fetchWithdrawals': { 'status': 'ok', }, 'parseOrderStatus': false, 'hasAlreadyAuthenticatedSuccessfully': false, // a workaround for APIKEY_INVALID // With certain currencies, like // AEON, BTS, GXS, NXT, SBD, STEEM, STR, XEM, XLM, XMR, XRP // an additional tag / memo / payment id is usually required by exchanges. // With Bittrex some currencies imply the "base address + tag" logic. // The base address for depositing is stored on this.currencies[code] // The base address identifies the exchange as the recipient // while the tag identifies the user account within the exchange // and the tag is retrieved with fetchDepositAddress. 'tag': { 'NXT': true, // NXT, BURST 'CRYPTO_NOTE_PAYMENTID': true, // AEON, XMR 'BITSHAREX': true, // BTS 'RIPPLE': true, // XRP 'NEM': true, // XEM 'STELLAR': true, // XLM 'STEEM': true, // SBD, GOLOS // https://github.com/ccxt/ccxt/issues/4794 // 'LISK': true, // LSK }, 'subaccountId': undefined, // see the implementation of fetchClosedOrdersV3 below // 'fetchClosedOrdersMethod': 'fetch_closed_orders_v3', 'fetchClosedOrdersFilterBySince': true, // 'createOrderMethod': 'create_order_v1', }, 'commonCurrencies': { 'BIFI': 'Bifrost Finance', 'BTR': 'BTRIPS', 'GMT': 'GMT Token', 'MEME': 'Memetic', // conflict with Meme Inu 'MER': 'Mercury', // conflict with Mercurial Finance 'PROS': 'Pros.Finance', 'REPV2': 'REP', 'TON': 'Tokamak Network', }, }); } feeToPrecision (symbol, fee) { return this.decimalToPrecision (fee, TRUNCATE, this.markets[symbol]['precision']['price'], this.precisionMode); } async fetchMarkets (params = {}) { /** * @method * @name bittrex#fetchMarkets * @description retrieves data on all markets for bittrex * @param {object} params extra parameters specific to the exchange api endpoint * @returns {[object]} an array of objects representing market data */ const response = await this.publicGetMarkets (params); // // [ // { // "symbol":"LTC-BTC", // "baseCurrencySymbol":"LTC", // "quoteCurrencySymbol":"BTC", // "minTradeSize":"0.01686767", // "precision":8, // "status":"ONLINE", // "OFFLINE" // "createdAt":"2014-02-13T00:00:00Z" // }, // { // "symbol":"VDX-USDT", // "baseCurrencySymbol":"VDX", // "quoteCurrencySymbol":"USDT", // "minTradeSize":"300.00000000", // "precision":8, // "status":"ONLINE", // "OFFLINE" // "createdAt":"2019-05-23T00:41:21.843Z", // "notice":"USDT has swapped to an ERC20-based token as of August 5, 2019." // } // ] // const result = []; for (let i = 0; i < response.length; i++) { const market = response[i]; const baseId = this.safeString (market, 'baseCurrencySymbol'); const quoteId = this.safeString (market, 'quoteCurrencySymbol'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const status = this.safeString (market, 'status'); result.push ({ 'id': this.safeString (market, 'symbol'), 'symbol': base + '/' + quote, 'base': base, 'quote': quote, 'settle': undefined, 'baseId': baseId, 'quoteId': quoteId, 'settleId': undefined, 'type': 'spot', 'spot': true, 'margin': false, 'swap': false, 'future': false, 'option': false, 'active': (status === 'ONLINE'), 'contract': false, 'linear': undefined, 'inverse': undefined, 'contractSize': undefined, 'expiry': undefined, 'expiryDatetime': undefined, 'strike': undefined, 'optionType': undefined, 'precision': { 'amount': this.parseNumber ('1e-8'), // seems exchange has same amount-precision across all pairs in UI too. This is same as 'minTradeSize' digits after dot 'price': this.parseNumber (this.parsePrecision (this.safeString (market, 'precision'))), }, 'limits': { 'leverage': { 'min': undefined, 'max': undefined, }, 'amount': { 'min': this.safeNumber (market, 'minTradeSize'), 'max': undefined, }, 'price': { 'min': undefined, 'max': undefined, }, 'cost': { 'min': undefined, 'max': undefined, }, }, 'info': market, }); } return result; } parseBalance (response) { const result = { 'info': response }; const indexed = this.indexBy (response, 'currencySymbol'); const currencyIds = Object.keys (indexed); for (let i = 0; i < currencyIds.length; i++) { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); const balance = indexed[currencyId]; account['free'] = this.safeString (balance, 'available'); account['total'] = this.safeString (balance, 'total'); result[code] = account; } return this.safeBalance (result); } async fetchBalance (params = {}) { /** * @method * @name bittrex#fetchBalance * @description query for balance and get the amount of funds available for trading or funds locked in orders * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {object} a [balance structure]{@link https://docs.ccxt.com/en/latest/manual.html?#balance-structure} */ await this.loadMarkets (); const response = await this.privateGetBalances (params); return this.parseBalance (response); } async fetchOrderBook (symbol, limit = undefined, params = {}) { /** * @method * @name bittrex#fetchOrderBook * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data * @param {string} symbol unified symbol of the market to fetch the order book for * @param {int|undefined} limit the maximum amount of order book entries to return * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/en/latest/manual.html#order-book-structure} indexed by market symbols */ await this.loadMarkets (); const market = this.market (symbol); const request = { 'marketSymbol': market['id'], }; if (limit !== undefined) { if ((limit !== 1) && (limit !== 25) && (limit !== 500)) { throw new BadRequest (this.id + ' fetchOrderBook() limit argument must be undefined, 1, 25 or 500, default is 25'); } request['depth'] = limit; } const response = await this.publicGetMarketsMarketSymbolOrderbook (this.extend (request, params)); // // { // "bid":[ // {"quantity":"0.01250000","rate":"10718.56200003"}, // {"quantity":"0.10000000","rate":"10718.56200002"}, // {"quantity":"0.39648292","rate":"10718.56200001"}, // ], // "ask":[ // {"quantity":"0.05100000","rate":"10724.30099631"}, // {"quantity":"0.10000000","rate":"10724.30099632"}, // {"quantity":"0.26000000","rate":"10724.30099634"}, // ] // } // const sequence = this.safeInteger (this.last_response_headers, 'Sequence'); const orderbook = this.parseOrderBook (response, market['symbol'], undefined, 'bid', 'ask', 'rate', 'quantity'); orderbook['nonce'] = sequence; return orderbook; } async fetchCurrencies (params = {}) { /** * @method * @name bittrex#fetchCurrencies * @description fetches all available currencies on an exchange * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {object} an associative dictionary of currencies */ const response = await this.publicGetCurrencies (params); // // [ // { // "symbol":"1ST", // "name":"Firstblood", // "coinType":"ETH_CONTRACT", // "status":"ONLINE", // "minConfirmations":36, // "notice":"", // "txFee":"4.50000000", // "logoUrl":"https://bittrexblobstorage.blob.core.windows.net/public/5685a7be-1edf-4ba0-a313-b5309bb204f8.png", // "prohibitedIn":[], // "baseAddress":"0xfbb1b73c4f0bda4f67dca266ce6ef42f520fbb98", // "associatedTermsOfService":[] // } // ] // const result = {}; for (let i = 0; i < response.length; i++) { const currency = response[i]; const id = this.safeString (currency, 'symbol'); const code = this.safeCurrencyCode (id); const precision = this.parseNumber ('1e-8'); // default precision, seems exchange has same amount-precision across all pairs in UI too. todo: fix "magic constants" const fee = this.safeNumber (currency, 'txFee'); // todo: redesign const isActive = this.safeString (currency, 'status'); result[code] = { 'id': id, 'code': code, 'address': this.safeString (currency, 'baseAddress'), 'info': currency, 'type': this.safeString (currency, 'coinType'), 'name': this.safeString (currency, 'name'), 'active': (isActive === 'ONLINE'), 'deposit': undefined, 'withdraw': undefined, 'fee': fee, 'precision': precision, 'limits': { 'amount': { 'min': precision, 'max': undefined, }, 'withdraw': { 'min': fee, 'max': undefined, }, }, }; } return result; } parseTicker (ticker, market = undefined) { // // ticker // // { // "symbol":"ETH-BTC", // "lastTradeRate":"0.03284496", // "bidRate":"0.03284523", // "askRate":"0.03286857" // } // // summary // // { // "symbol":"ETH-BTC", // "high":"0.03369528", // "low":"0.03282442", // "volume":"4307.83794556", // "quoteVolume":"143.08608869", // "percentChange":"0.79", // "updatedAt":"2020-09-29T07:36:57.823Z" // } // const timestamp = this.parse8601 (this.safeString (ticker, 'updatedAt')); const marketId = this.safeString (ticker, 'symbol'); market = this.safeMarket (marketId, market, '-'); const symbol = market['symbol']; const percentage = this.safeString (ticker, 'percentChange'); const last = this.safeString (ticker, 'lastTradeRate'); return this.safeTicker ({ 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': this.safeString (ticker, 'high'), 'low': this.safeString (ticker, 'low'), 'bid': this.safeString (ticker, 'bidRate'), 'bidVolume': undefined, 'ask': this.safeString (ticker, 'askRate'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, 'percentage': percentage, 'average': undefined, 'baseVolume': this.safeString (ticker, 'volume'), 'quoteVolume': this.safeString (ticker, 'quoteVolume'), 'info': ticker, }, market); } async fetchTickers (symbols = undefined, params = {}) { /** * @method * @name bittrex#fetchTickers * @description fetches price tickers for multiple markets, statistical calculations with the information calculated over the past 24 hours each market * @param {[string]|undefined} 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 bittrex api endpoint * @returns {object} an array of [ticker structures]{@link https://docs.ccxt.com/en/latest/manual.html#ticker-structure} */ await this.loadMarkets (); symbols = this.marketSymbols (symbols); const options = this.safeValue (this.options, 'fetchTickers', {}); const defaultMethod = this.safeString (options, 'method', 'publicGetMarketsTickers'); const method = this.safeString (params, 'method', defaultMethod); params = this.omit (params, 'method'); const response = await this[method] (params); // // publicGetMarketsTickers // // [ // { // "symbol":"4ART-BTC", // "lastTradeRate":"0.00000210", // "bidRate":"0.00000210", // "askRate":"0.00000215" // } // ] // // publicGetMarketsSummaries // // [ // { // "symbol":"4ART-BTC", // "high":"0.00000206", // "low":"0.00000196", // "volume":"14871.32000233", // "quoteVolume":"0.02932756", // "percentChange":"1.48", // "updatedAt":"2020-09-29T07:34:32.757Z" // } // ] // const tickers = []; for (let i = 0; i < response.length; i++) { const ticker = this.parseTicker (response[i]); tickers.push (ticker); } return this.filterByArray (tickers, 'symbol', symbols); } async fetchTicker (symbol, params = {}) { /** * @method * @name bittrex#fetchTicker * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market * @param {string} symbol unified symbol of the market to fetch the ticker for * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/en/latest/manual.html#ticker-structure} */ await this.loadMarkets (); const market = this.market (symbol); const request = { 'marketSymbol': market['id'], }; const options = this.safeValue (this.options, 'fetchTicker', {}); const defaultMethod = this.safeString (options, 'method', 'publicGetMarketsMarketSymbolTicker'); const method = this.safeString (params, 'method', defaultMethod); params = this.omit (params, 'method'); const response = await this[method] (this.extend (request, params)); // // publicGetMarketsMarketSymbolTicker // // { // "symbol":"ETH-BTC", // "lastTradeRate":"0.03284496", // "bidRate":"0.03284523", // "askRate":"0.03286857" // } // // // publicGetMarketsMarketSymbolSummary // // { // "symbol":"ETH-BTC", // "high":"0.03369528", // "low":"0.03282442", // "volume":"4307.83794556", // "quoteVolume":"143.08608869", // "percentChange":"0.79", // "updatedAt":"2020-09-29T07:36:57.823Z" // } // return this.parseTicker (response, market); } async fetchBidsAsks (symbols = undefined, params = {}) { /** * @method * @name bittrex#fetchBidsAsks * @description fetches the bid and ask price and volume for multiple markets * @param {[string]|undefined} symbols unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned * @param {object} params extra parameters specific to the binance api endpoint * @returns {object} an array of [ticker structures]{@link https://docs.ccxt.com/en/latest/manual.html#ticker-structure} */ await this.loadMarkets (); const response = await this.publicGetMarketsTickers (params); // // [ // { // "symbol":"ETH-BTC", // "lastTradeRate":"0.03284496", // "bidRate":"0.03284523", // "askRate":"0.03286857" // } // ] // return this.parseTickers (response, symbols); } parseTrade (trade, market = undefined) { // // public fetchTrades // // { // "id": "8a614d4e-e455-45b0-9aac-502b0aeb433f", // "executedAt": "2021-11-25T14:54:44.65Z", // "quantity": "30.00000000", // "rate": "1.72923112", // "takerSide": "SELL" // } // // private fetchOrderTrades // { // "id": "8a614d4e-e455-45b0-9aac-502b0aeb433f", // "marketSymbol": "ADA-USDT", // "executedAt": "2021-11-25T14:54:44.65Z", // "quantity": "30.00000000", // "rate": "1.72923112", // "orderId": "6f7abf18-6901-4659-a48c-db0e88440ea4", // "commission": "0.38907700", // "isTaker": true // } // // private fetchMyTrades // { // "id":"7e6488c9-294f-4137-b0f2-9f86578186fe", // "marketSymbol":"DOGE-USDT", // "executedAt":"2022-08-12T21:27:37.92Z", // "quantity":"100.00000000", // "rate":"0.071584100000", // "orderId":"2d53f11a-fb22-4820-b04d-80e5f48e6005", // "commission":"0.05368807", // "isTaker":true, // "direction":"BUY" // } // const timestamp = this.parse8601 (this.safeString (trade, 'executedAt')); const id = this.safeString (trade, 'id'); const order = this.safeString (trade, 'orderId'); const marketId = this.safeString (trade, 'marketSymbol'); market = this.safeMarket (marketId, market, '-'); const priceString = this.safeString (trade, 'rate'); const amountString = this.safeString (trade, 'quantity'); let takerOrMaker = undefined; let side = this.safeStringLower2 (trade, 'takerSide', 'direction'); const isTaker = this.safeValue (trade, 'isTaker'); if (isTaker !== undefined) { takerOrMaker = isTaker ? 'taker' : 'maker'; if (!isTaker) { // as noted in PR #15655 this API provides confusing value - when it's 'maker' trade, then side value should reversed if (side === 'buy') { side = 'sell'; } else if (side === 'sell') { side = 'buy'; } } } let fee = undefined; const feeCostString = this.safeString (trade, 'commission'); if (feeCostString !== undefined) { fee = { 'cost': feeCostString, 'currency': market['quote'], }; } return this.safeTrade ({ 'info': trade, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'symbol': market['symbol'], 'id': id, 'order': order, 'takerOrMaker': takerOrMaker, 'type': undefined, 'side': side, 'price': priceString, 'amount': amountString, 'cost': undefined, 'fee': fee, }, market); } async fetchTime (params = {}) { /** * @method * @name bittrex#fetchTime * @description fetches the current integer timestamp in milliseconds from the exchange server * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {int} the current integer timestamp in milliseconds from the exchange server */ const response = await this.publicGetPing (params); // // { // "serverTime": 1594596023162 // } // return this.safeInteger (response, 'serverTime'); } async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { /** * @method * @name bittrex#fetchTrades * @description get the list of most recent trades for a particular symbol * @param {string} symbol unified symbol of the market to fetch trades for * @param {int|undefined} since timestamp in ms of the earliest trade to fetch * @param {int|undefined} limit the maximum amount of trades to fetch * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {[object]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html?#public-trades} */ await this.loadMarkets (); const market = this.market (symbol); const request = { 'marketSymbol': market['id'], }; const response = await this.publicGetMarketsMarketSymbolTrades (this.extend (request, params)); // // [ // { // "id":"9c5589db-42fb-436c-b105-5e2edcb95673", // "executedAt":"2020-10-03T11:48:43.38Z", // "quantity":"0.17939626", // "rate":"0.03297952", // "takerSide":"BUY" // } // ] // return this.parseTrades (response, market, since, limit); } async fetchTradingFee (symbol, params = {}) { /** * @method * @name bittrex#fetchTradingFee * @description fetch the trading fees for a market * @param {string} symbol unified market symbol * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {object} a [fee structure]{@link https://docs.ccxt.com/en/latest/manual.html#fee-structure} */ await this.loadMarkets (); const market = this.market (symbol); const request = { 'marketSymbol': market['id'], }; const response = await this.privateGetAccountFeesTradingMarketSymbol (this.extend (request, params)); // // { // "marketSymbol":"1INCH-ETH", // "makerRate":"0.00750000", // "takerRate":"0.00750000" // } // return this.parseTradingFee (response, market); } async fetchTradingFees (params = {}) { /** * @method * @name bittrex#fetchTradingFees * @description fetch the trading fees for multiple markets * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/en/latest/manual.html#fee-structure} indexed by market symbols */ await this.loadMarkets (); const response = await this.privateGetAccountFeesTrading (params); // // [ // {"marketSymbol":"1ECO-BTC","makerRate":"0.00750000","takerRate":"0.00750000"}, // {"marketSymbol":"1ECO-USDT","makerRate":"0.00750000","takerRate":"0.00750000"}, // {"marketSymbol":"1INCH-BTC","makerRate":"0.00750000","takerRate":"0.00750000"}, // {"marketSymbol":"1INCH-ETH","makerRate":"0.00750000","takerRate":"0.00750000"}, // {"marketSymbol":"1INCH-USD","makerRate":"0.00750000","takerRate":"0.00750000"}, // ] // return this.parseTradingFees (response); } parseTradingFee (fee, market = undefined) { const marketId = this.safeString (fee, 'marketSymbol'); const maker = this.safeNumber (fee, 'makerRate'); const taker = this.safeNumber (fee, 'takerRate'); return { 'info': fee, 'symbol': this.safeSymbol (marketId, market), 'maker': maker, 'taker': taker, }; } parseTradingFees (fees) { const result = { 'info': fees, }; for (let i = 0; i < fees.length; i++) { const fee = this.parseTradingFee (fees[i]); const symbol = fee['symbol']; result[symbol] = fee; } return result; } parseOHLCV (ohlcv, market = undefined) { // // { // "startsAt":"2020-06-12T02:35:00Z", // "open":"0.02493753", // "high":"0.02493753", // "low":"0.02493753", // "close":"0.02493753", // "volume":"0.09590123", // "quoteVolume":"0.00239153" // } // return [ this.parse8601 (this.safeString (ohlcv, 'startsAt')), this.safeNumber (ohlcv, 'open'), this.safeNumber (ohlcv, 'high'), this.safeNumber (ohlcv, 'low'), this.safeNumber (ohlcv, 'close'), this.safeNumber (ohlcv, 'volume'), ]; } async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { /** * @method * @name bittrex#fetchOHLCV * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market * @param {string} symbol unified symbol of the market to fetch OHLCV data for * @param {string} timeframe the length of time each candle represents * @param {int|undefined} since timestamp in ms of the earliest candle to fetch * @param {int|undefined} limit the maximum amount of candles to fetch * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {[[int]]} A list of candles ordered as timestamp, open, high, low, close, volume */ await this.loadMarkets (); const market = this.market (symbol); const reverseId = market['baseId'] + '-' + market['quoteId']; const request = { 'candleInterval': this.timeframes[timeframe], 'marketSymbol': reverseId, }; let method = 'publicGetMarketsMarketSymbolCandlesCandleIntervalRecent'; if (since !== undefined) { const now = this.milliseconds (); const difference = Math.abs (now - since); const sinceDate = this.yyyymmdd (since); const parts = sinceDate.split ('-'); const sinceYear = this.safeInteger (parts, 0); const sinceMonth = this.safeInteger (parts, 1); const sinceDay = this.safeInteger (parts, 2); if (timeframe === '1d') { // if the since argument is beyond one year into the past if (difference > 31622400000) { method = 'publicGetMarketsMarketSymbolCandlesCandleIntervalHistoricalYear'; request['year'] = sinceYear; } // request['year'] = year; } else if (timeframe === '1h') { // if the since argument is beyond 31 days into the past if (difference > 2678400000) { method = 'publicGetMarketsMarketSymbolCandlesCandleIntervalHistoricalYearMonth'; request['year'] = sinceYear; request['month'] = sinceMonth; } } else { // if the since argument is beyond 1 day into the past if (difference > 86400000) { method = 'publicGetMarketsMarketSymbolCandlesCandleIntervalHistoricalYearMonthDay'; request['year'] = sinceYear; request['month'] = sinceMonth; request['day'] = sinceDay; } } } const response = await this[method] (this.extend (request, params)); // // [ // {"startsAt":"2020-06-12T02:35:00Z","open":"0.02493753","high":"0.02493753","low":"0.02493753","close":"0.02493753","volume":"0.09590123","quoteVolume":"0.00239153"}, // {"startsAt":"2020-06-12T02:40:00Z","open":"0.02491874","high":"0.02491874","low":"0.02490970","close":"0.02490970","volume":"0.04515695","quoteVolume":"0.00112505"}, // {"startsAt":"2020-06-12T02:45:00Z","open":"0.02490753","high":"0.02493143","low":"0.02490753","close":"0.02493143","volume":"0.17769640","quoteVolume":"0.00442663"} // ] // return this.parseOHLCVs (response, market, timeframe, since, limit); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { /** * @method * @name bittrex#fetchOpenOrders * @description fetch all unfilled currently open orders * @param {string|undefined} symbol unified market symbol * @param {int|undefined} since the earliest time in ms to fetch open orders for * @param {int|undefined} limit the maximum number of open orders structures to retrieve * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {[object]} a list of [order structures]{@link https://docs.ccxt.com/en/latest/manual.html#order-structure} */ await this.loadMarkets (); const request = {}; let market = undefined; const stop = this.safeValue (params, 'stop'); if (symbol !== undefined) { market = this.market (symbol); request['marketSymbol'] = market['id']; } let method = 'privateGetOrdersOpen'; if (stop) { method = 'privateGetConditionalOrdersOpen'; } const query = this.omit (params, 'stop'); const response = await this[method] (this.extend (request, query)); // // Spot // // [ // { // "id": "df6cf5ee-fc27-4b61-991a-cc94b6459ac9", // "marketSymbol": "BTC-USDT", // "direction": "BUY", // "type": "LIMIT", // "quantity": "0.00023277", // "limit": "30000.00000000", // "timeInForce": "GOOD_TIL_CANCELLED", // "fillQuantity": "0.00000000", // "commission": "0.00000000", // "proceeds": "0.00000000", // "status": "OPEN", // "createdAt": "2022-04-20T02:33:53.16Z", // "updatedAt": "2022-04-20T02:33:53.16Z" // } // ] // // Stop // // [ // { // "id": "f64f7c4f-295c-408b-9cbc-601981abf100", // "marketSymbol": "BTC-USDT", // "operand": "LTE", // "triggerPrice": "0.10000000", // "orderToCreate": { // "marketSymbol": "BTC-USDT", // "direction": "BUY", // "type": "LIMIT", // "quantity": "0.00020000", // "limit": "30000.00000000", // "timeInForce": "GOOD_TIL_CANCELLED" // }, // "status": "OPEN", // "createdAt": "2022-04-20T02:38:12.26Z", // "updatedAt": "2022-04-20T02:38:12.26Z" // } // ] // return this.parseOrders (response, market, since, limit); } async fetchOrderTrades (id, symbol = undefined, since = undefined, limit = undefined, params = {}) { /** * @method * @name bittrex#fetchOrderTrades * @description fetch all the trades made from a single order * @param {string} id order id * @param {string|undefined} symbol unified market symbol * @param {int|undefined} since the earliest time in ms to fetch trades for * @param {int|undefined} limit the maximum number of trades to retrieve * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {[object]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html#trade-structure} */ await this.loadMarkets (); const request = { 'orderId': id, }; const response = await this.privateGetOrdersOrderIdExecutions (this.extend (request, params)); let market = undefined; if (symbol !== undefined) { market = this.market (symbol); } return this.parseTrades (response, market, since, limit); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { /** * @method * @name bittrex#createOrder * @description create a trade order * @param {string} symbol unified symbol of the market to create an order in * @param {string} type 'market' or 'limit' * @param {string} side 'buy' or 'sell' * @param {float} amount how much of currency you want to trade in units of base currency * @param {float|undefined} price the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders * @param {object} params extra parameters specific to the bittrex api endpoint * @returns {object} an [order structure]{@link https://docs.ccxt.com/en/latest/manual.html#order-structure} */ // A ceiling order is a market or limit order that allows you to specify // the amount of quote currency you want to spend (or receive, if selling) // instead of the quantity of the market currency (e.g. buy $100 USD of BTC // at the current market BTC price) await this.loadMarkets (); const market = this.market (symbol); let uppercaseType = undefined; if (type !== undefined) { uppercaseType = type.toUpperCase (); } const reverseId = market['baseId'] + '-' + market['quoteId']; const stop = this.safeValue (params, 'stop'); const stopPrice = this.safeNumber2 (params, 'triggerPrice', 'stopPrice'); const request = { 'marketSymbol': reverseId, // SPOT and STOP // 'direction': side.toUpperCase (), // SPOT, STOP 'orderToCreate' // 'type': uppercaseType, // SPOT: LIMIT, MARKET, CEILING_LIMIT, CEILING_MARKET // 'quantity': this.amountToPrecision (symbol, amount), // SPOT, required for limit orders, excluded for ceiling orders // 'ceiling': this.priceToPrecision (symbol, price), // SPOT, required for ceiling orders, excluded for non-ceiling orders // 'limit': this.priceToPrecision (symbol, price), // SPOT, required for limit orders, excluded for market orders // 'timeInForce': 'GOOD_TIL_CANCELLED', // SPOT, IMMEDIATE_OR_CANCEL, FILL_OR_KILL, POST_ONLY_GOOD_TIL_CANCELLED // 'useAwards': false, // SPOT, optional // 'operand': 'LTE', // STOP, price above (GTE) or below (LTE) which the conditional order will trigger. either this or trailingStopPercent must be specified. // 'triggerPrice': this.priceToPrecision (symbol, stopPrice), // STOP