ccxt-look
Version:
1,162 lines (1,134 loc) • 80.7 kB
JavaScript
'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, DECIMAL_PLACES } = 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,
'fetchBorrowRate': false,
'fetchBorrowRateHistories': false,
'fetchBorrowRateHistory': false,
'fetchBorrowRates': false,
'fetchBorrowRatesPerSymbol': false,
'fetchClosedOrders': true,
'fetchCurrencies': true,
'fetchDepositAddress': true,
'fetchDeposits': true,
'fetchFundingFees': undefined,
'fetchFundingHistory': false,
'fetchFundingRate': false,
'fetchFundingRateHistory': false,
'fetchFundingRates': false,
'fetchIndexOHLCV': false,
'fetchLeverage': false,
'fetchLeverageTiers': false,
'fetchMarkets': true,
'fetchMarkOHLCV': false,
'fetchMyTrades': 'emulated',
'fetchOHLCV': true,
'fetchOpenOrders': true,
'fetchOrder': true,
'fetchOrderBook': true,
'fetchOrderTrades': true,
'fetchPosition': false,
'fetchPositions': false,
'fetchPositionsRisk': false,
'fetchPremiumIndexOHLCV': false,
'fetchTicker': true,
'fetchTickers': true,
'fetchTime': true,
'fetchTrades': true,
'fetchTradingFee': true,
'fetchTradingFees': true,
'fetchTransactions': undefined,
'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',
'addresses',
'addresses/{currencySymbol}',
'balances',
'balances/{currencySymbol}',
'deposits/open',
'deposits/closed',
'deposits/ByTxId/{txId}',
'deposits/{depositId}',
'orders/closed',
'orders/open',
'orders/{orderId}',
'orders/{orderId}/executions',
'ping',
'subaccounts/{subaccountId}',
'subaccounts',
'withdrawals/open',
'withdrawals/closed',
'withdrawals/ByTxId/{txId}',
'withdrawals/{withdrawalId}',
'withdrawals/whitelistAddresses',
'conditional-orders/{conditionalOrderId}',
'conditional-orders/closed',
'conditional-orders/open',
'transfers/sent',
'transfers/received',
'transfers/{transferId}',
],
'post': [
'addresses',
'orders',
'subaccounts',
'withdrawals',
'conditional-orders',
'transfers',
],
'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,
},
},
'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
},
'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',
},
});
}
costToPrecision (symbol, cost) {
return this.decimalToPrecision (cost, TRUNCATE, this.markets[symbol]['precision']['price'], DECIMAL_PLACES);
}
feeToPrecision (symbol, fee) {
return this.decimalToPrecision (fee, TRUNCATE, this.markets[symbol]['precision']['price'], DECIMAL_PLACES);
}
async fetchMarkets (params = {}) {
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': parseInt ('8'),
'price': this.safeInteger (market, 'precision', 8),
},
'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 = {}) {
await this.loadMarkets ();
const response = await this.privateGetBalances (params);
return this.parseBalance (response);
}
async fetchOrderBook (symbol, limit = undefined, params = {}) {
await this.loadMarkets ();
const request = {
'marketSymbol': this.marketId (symbol),
};
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, symbol, undefined, 'bid', 'ask', 'rate', 'quantity');
orderbook['nonce'] = sequence;
return orderbook;
}
async fetchCurrencies (params = {}) {
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 = 8; // default precision, 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': 1 / Math.pow (10, 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, false);
}
async fetchTickers (symbols = undefined, params = {}) {
await this.loadMarkets ();
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 = {}) {
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);
}
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
// }
//
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;
const isTaker = this.safeValue (trade, 'isTaker');
if (isTaker !== undefined) {
takerOrMaker = isTaker ? 'taker' : 'maker';
}
let fee = undefined;
const feeCostString = this.safeString (trade, 'commission');
if (feeCostString !== undefined) {
fee = {
'cost': feeCostString,
'currency': market['quote'],
};
}
const side = this.safeStringLower (trade, 'takerSide');
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 = {}) {
const response = await this.publicGetPing (params);
//
// {
// "serverTime": 1594596023162
// }
//
return this.safeInteger (response, 'serverTime');
}
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets ();
const market = this.market (symbol);
const request = {
'marketSymbol': this.marketId (symbol),
};
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 = {}) {
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 = {}) {
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 = {}) {
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 = {}) {
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 = {}) {
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 = {}) {
// 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
// 'trailingStopPercent': this.priceToPrecision (symbol, stopPrice), // STOP, either this or triggerPrice must be set
// 'orderToCreate': {direction:side,type:uppercaseType}, // STOP, The spot order to be triggered
// 'orderToCancel': {id:'f03d5e98-b5ac-48fb-8647-dd4db828a297',type:uppercaseType}, // STOP, The spot order to be canceled
// 'clineConditionalOrderId': 'f03d5e98-b5ac-48fb-8647-dd4db828a297', // STOP
};
let method = 'privatePostOrders';
if (stop || stopPrice) {
method = 'privatePostConditionalOrders';
const operand = this.safeString (params, 'operand');
if (operand === undefined) {
throw new ArgumentsRequired (this.id + ' createOrder() requires an operand parameter');
}
const trailingStopPercent = this.safeNumber (params, 'trailingStopPercent');
const orderToCreate = this.safeValue (params, 'orderToCreate');
const orderToCancel = this.safeValue (params, 'orderToCancel');
if (stopPrice === undefined) {
request['trailingStopPercent'] = this.priceToPrecision (symbol, trailingStopPercent);
}
if (orderToCreate) {
const isCeilingLimit = (uppercaseType === 'CEILING_LIMIT');
const isCeilingMarket = (uppercaseType === 'CEILING_MARKET');
const isCeilingOrder = isCeilingLimit || isCeilingMarket;
let ceiling = undefined;
let limit = undefined;
let timeInForce = undefined;
if (isCeilingOrder) {
let cost = undefined;
if (isCeilingLimit) {
limit = this.priceToPrecision (symbol, price);
cost = this.safeNumber2 (params, 'ceiling', 'cost', amount);
} else if (isCeilingMarket) {
cost = this.safeNumber2 (params, 'ceiling', 'cost');
if (cost === undefined) {
if (price === undefined) {
cost = amount;
} else {
cost = amount * price;
}
}
}
ceiling = this.costToPrecision (symbol, cost);
timeInForce = 'IMMEDIATE_OR_CANCEL';
} else {
if (uppercaseType === 'LIMIT') {
limit = this.priceToPrecision (symbol, price);
timeInForce = 'GOOD_TIL_CANCELLED';
} else {
timeInForce = 'IMMEDIATE_OR_CANCEL';
}
}
request['orderToCreate'] = {
'marketSymbol': reverseId,
'direction': side.toUpperCase (),
'type': uppercaseType,
'quantity': this.amountToPrecision (symbol, amount),
'ceiling': ceiling,
'limit': limit,
'timeInForce': timeInForce,
'clientOrderId': this.safeString (params, 'clientOrderId'),
'useAwards': this.safeValue (params, 'useAwards'),
};
}
if (orderToCancel) {
request['orderToCancel'] = orderToCancel;
}
request['triggerPrice'] = this.priceToPrecision (symbol, stopPrice);
request['operand'] = operand;
} else {
if (side !== undefined) {
request['direction'] = side.toUpperCase ();
}
request['type'] = uppercaseType;
const isCeilingLimit = (uppercaseType === 'CEILING_LIMIT');
const isCeilingMarket = (uppercaseType === 'CEILING_MARKET');
const isCeilingOrder = isCeilingLimit || isCeilingMarket;
if (isCeilingOrder) {
let cost = undefined;
if (isCeilingLimit) {
request['limit'] = this.priceToPrecision (symbol, price);
cost = this.safeNumber2 (params, 'ceiling', 'cost', amount);
} else if (isCeilingMarket) {
cost = this.safeNumber2 (params, 'ceiling', 'cost');
if (cost === undefined) {
if (price === undefined) {
cost = amount;
} else {
cost = amount * price;
}
}
}
request['ceiling'] = this.costToPrecision (symbol, cost);
// bittrex only accepts IMMEDIATE_OR_CANCEL or FILL_OR_KILL for ceiling orders
request['timeInForce'] = 'IMMEDIATE_OR_CANCEL';
} else {
request['quantity'] = this.amountToPrecision (symbol, amount);
if (uppercaseType === 'LIMIT') {
request['limit'] = this.priceToPrecision (symbol, price);
request['timeInForce'] = 'GOOD_TIL_CANCELLED';
} else {
// bittrex does not allow GOOD_TIL_CANCELLED for market orders
request['timeInForce'] = 'IMMEDIATE_OR_CANCEL';
}
}
}
const query = this.omit (params, [ 'stop', 'stopPrice', 'ceiling', 'cost', 'operand', 'trailingStopPercent', 'orderToCreate', 'orderToCancel' ]);
const response = await this[method] (this.extend (request, query));
//
// Spot
//
// {
// id: 'f03d5e98-b5ac-48fb-8647-dd4db828a297',
// marketSymbol: 'BTC-USDT',
// direction: 'SELL',
// type: 'LIMIT',
// quantity: '0.01',
// limit: '6000',
// timeInForce: 'GOOD_TIL_CANCELLED',
// fillQuantity: '0.00000000',
// commission: '0.00000000',
// proceeds: '0.00000000',
// status: 'OPEN',
// createdAt: '2020-03-18T02:37:33.42Z',
// updatedAt: '2020-03-18T02:37:33.42Z'
// }
//
// Stop
//
// {
// "id": "9791fe52-a3e5-4ac3-ae03-e327b2993571",
// "marketSymbol": "BTC-USDT",
// "operand": "LTE",
// "triggerPrice": "0.1",
// "orderToCreate": {
// "marketSymbol": "BTC-USDT",
// "direction": "BUY",
// "type": "LIMIT",
// "quantity": "0.0002",
// "limit": "30000",
// "timeInForce": "GOOD_TIL_CANCELLED"
// },
// "status": "OPEN",
// "createdAt": "2022-04-19T21:02:14.17Z",
// "updatedAt": "2022-04-19T21:02:14.17Z"
// }
//
return this.parseOrder (response, market);
}
async cancelOrder (id, symbol = undefined, params = {}) {
await this.loadMarkets ();
const stop = this.safeValue (params, 'stop');
let request = {};
let method = undefined;
let market = undefined;
if (symbol !== undefined) {
market = this.market (symbol);
}
if (stop) {
method = 'privateDeleteConditionalOrdersConditionalOrderId';
request = {
'conditionalOrderId': id,
};
} else {
method = 'privateDeleteOrdersOrderId';
request = {
'orderId': id,
};
}
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": "CANCELLED",
// "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": "CANCELLED",
// "createdAt": "2022-04-20T02:38:12.26Z",
// "updatedAt": "2022-04-20T02:38:12.26Z"
// "closedAt": "2022-04-20T03:47:24.69Z"
// }
// ]
//
return this.extend (this.parseOrder (response, market), {
'id': id,
'info': response,
'status': 'canceled',
});
}
async cancelAllOrders (symbol = undefined, params = {}) {
await this.loadMarkets ();
const request = {};
let market = undefined;
if (symbol !== undefined) {
market = this.market (symbol);
request['marketSymbol'] = market['id'];
}
const response = await this.privateDeleteOrdersOpen (this.extend (request, params));
//
// [
// {
// "id":"66582be0-5337-4d8c-b212-c356dd525801",
// "statusCode":"SUCCESS",
// "result":{
// "id":"66582be0-5337-4d8c-b212-c356dd525801",
// "marketSymbol":"BTC-USDT",
// "direction":"BUY",
//