UNPKG

ccxt-look

Version:

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

1,205 lines (1,175 loc) 67.6 kB
'use strict'; // ---------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadSymbol } = require ('./base/errors'); const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- module.exports = class eqonex extends Exchange { describe () { return this.deepExtend (super.describe (), { 'id': 'eqonex', 'name': 'EQONEX', 'countries': [ 'US', 'SG' ], // United States, Singapore 'rateLimit': 10, 'has': { 'CORS': undefined, 'spot': true, 'margin': false, 'swap': undefined, // has but not fully implemented 'future': undefined, // has but not fully implemented 'option': false, 'cancelOrder': true, 'createOrder': true, 'createStopLimitOrder': true, 'createStopMarketOrder': true, 'createStopOrder': true, 'editOrder': true, 'fetchBalance': true, 'fetchBorrowRate': false, 'fetchBorrowRateHistories': false, 'fetchBorrowRateHistory': false, 'fetchBorrowRates': false, 'fetchBorrowRatesPerSymbol': false, 'fetchCanceledOrders': true, 'fetchClosedOrders': true, 'fetchCurrencies': true, 'fetchDepositAddress': true, 'fetchDeposits': true, 'fetchMarkets': true, 'fetchMyTrades': true, 'fetchOHLCV': true, 'fetchOrder': true, 'fetchOrderBook': true, 'fetchOrders': true, 'fetchTicker': undefined, 'fetchTrades': true, 'fetchTradingFee': false, 'fetchTradingFees': true, 'fetchTradingLimits': true, 'fetchWithdrawals': true, 'withdraw': true, }, 'timeframes': { '1m': 1, '5m': 2, '15m': 3, '1h': 4, '6h': 5, '1d': 6, '7d': 7, '1w': 7, }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/51840849/122649755-1a076c80-d138-11eb-8f2e-9a9166a03d79.jpg', 'test': { 'public': 'https://testnet.eqonex.com/api', 'private': 'https://testnet.eqonex.com/api', }, 'api': { 'public': 'https://eqonex.com/api', 'private': 'https://eqonex.com/api', }, 'www': 'https://eqonex.com', 'doc': [ 'https://developer.eqonex.com', ], 'referral': 'https://eqonex.com?referredByCode=zpa8kij4ouvBFup3', }, 'api': { 'public': { 'get': [ 'health', 'getInstruments', 'getInstrumentPairs', 'getOrderBook', 'getRisk', 'getTradeHistory', 'getFundingRateHistory', 'getChart', 'getExchangeInfo', // not documented ], }, 'private': { 'post': [ 'logon', 'order', 'cancelOrder', 'cancelReplaceOrder', 'getOrder', 'getOrders', 'getOrderStatus', 'getOrderHistory', 'userTrades', 'getPositions', 'cancelAll', 'getUserHistory', 'getRisk', 'getDepositAddresses', 'getDepositHistory', // not documented 'getWithdrawRequests', 'sendWithdrawRequest', 'getTransferHistory', ], }, }, 'requiredCredentials': { 'apiKey': true, 'secret': true, 'uid': true, }, 'exceptions': { 'broad': { 'symbol not found': BadSymbol, }, }, }); } async fetchMarkets (params = {}) { const request = { 'verbose': true, }; const response = await this.publicGetGetInstrumentPairs (this.extend (request, params)); // // { // "instrumentPairs": [ // { // "instrumentId":303, // "symbol":"BTC/USDC[220325]", // "quoteId":1, // "baseId":3, // "price_scale":2, // "quantity_scale":6, // "securityStatus":1, // "securityDesc":"BTC Dated Future", // "assetType":"DATED_FUTURE", // "currency":"BTC", // "contAmtCurr":"USDC", // "settlCurrency":"USDC", // "commCurrency":"USDC", // "cfiCode":"FFCPSX", // "securityExchange":"EQOS", // "micCode":"EQOD", // "instrumentPricePrecision":2, // "minPriceIncrement":1.0, // "minPriceIncrementAmount":1.0, // "roundLot":100, // "minTradeVol":0.000100, // "maxTradeVol":0.000000, // "qtyType":0, // "contractMultiplier":1.0, // "auctionStartTime":0, // "auctionDuration":0, // "auctionFrequency":0, // "auctionPrice":0, // "auctionVolume":0, // "marketStatus":"OPEN", // "underlyingSymbol":"BTC/USDC", // "underlyingSecurityId":52, // "underlyingSecuritySource":"M", // "underlyingSecurityExchange":"EQOC", // "issueDate":1643256000000, // "maturityDate":"2022-03-25", // "maturityTime":"2022-03-25T08:00:00Z", // "contractExpireTime":1648195200000 // } // ... // ] // } // const instrumentPairs = this.safeValue (response, 'instrumentPairs', []); const markets = []; for (let i = 0; i < instrumentPairs.length; i++) { const market = this.parseMarket (instrumentPairs[i]); markets.push (market); } return markets; } parseMarket (market) { // // { // "instrumentPairs": [ // { // "instrumentId":303, // "symbol":"BTC/USDC[220325]", // "quoteId":1, // "baseId":3, // "price_scale":2, // "quantity_scale":6, // "securityStatus":1, // "securityDesc":"BTC Dated Future", // "assetType":"DATED_FUTURE", // "currency":"BTC", // "contAmtCurr":"USDC", // "settlCurrency":"USDC", // "commCurrency":"USDC", // "cfiCode":"FFCPSX", // "securityExchange":"EQOS", // "micCode":"EQOD", // "instrumentPricePrecision":2, // "minPriceIncrement":1.0, // "minPriceIncrementAmount":1.0, // "roundLot":100, // "minTradeVol":0.000100, // "maxTradeVol":0.000000, // "qtyType":0, // "contractMultiplier":1.0, // "auctionStartTime":0, // "auctionDuration":0, // "auctionFrequency":0, // "auctionPrice":0, // "auctionVolume":0, // "marketStatus":"OPEN", // "underlyingSymbol":"BTC/USDC", // "underlyingSecurityId":52, // "underlyingSecuritySource":"M", // "underlyingSecurityExchange":"EQOC", // "issueDate":1643256000000, // "maturityDate":"2022-03-25", // "maturityTime":"2022-03-25T08:00:00Z", // "contractExpireTime":1648195200000 // } // ... // ] // } // const assetType = this.safeString (market, 'assetType'); const spot = (assetType === 'PAIR'); const swap = (assetType === 'PERPETUAL_SWAP'); const future = (assetType === 'DATED_FUTURE'); const contract = swap || future; const id = this.safeString (market, 'instrumentId'); const baseId = this.safeString (market, 'currency'); const quoteId = this.safeString (market, 'contAmtCurr'); const settleId = contract ? this.safeString (market, 'settlCurrency') : undefined; const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const settle = this.safeCurrencyCode (settleId); let symbol = base + '/' + quote; const uppercaseId = this.safeString (market, 'symbol'); let type = 'spot'; let linear = undefined; let inverse = undefined; const expiry = this.safeNumber (market, 'contractExpireTime'); if (contract) { symbol = symbol + ':' + settle; linear = (quote === settle); inverse = !linear; if (swap) { type = 'swap'; } else if (future) { symbol = symbol + '-' + this.yymmdd (expiry); type = 'future'; } else { symbol = uppercaseId; type = assetType; } } const status = this.safeInteger (market, 'securityStatus'); return { 'id': id, 'uppercaseId': uppercaseId, 'symbol': symbol, 'base': base, 'quote': quote, 'settle': settle, 'baseId': baseId, 'quoteId': quoteId, 'settleId': settleId, 'type': type, 'spot': spot, 'margin': false, 'swap': swap, 'future': future, 'option': false, 'active': (status === 1), 'contract': contract, 'linear': linear, 'inverse': inverse, 'contractSize': this.safeNumber (market, 'contractMultiplier'), 'expiry': expiry, 'expiryDatetime': this.iso8601 (expiry), 'strike': undefined, 'optionType': undefined, 'precision': { 'amount': this.safeInteger (market, 'quantity_scale'), 'price': this.safeInteger (market, 'price_scale'), }, 'limits': { 'leverage': { 'min': undefined, 'max': undefined, }, 'amount': { 'min': this.safeNumber (market, 'minTradeVol'), 'max': undefined, }, 'price': { 'min': undefined, 'max': undefined, }, 'cost': { 'min': undefined, 'max': undefined, }, }, 'info': market, }; } async fetchCurrencies (params = {}) { const response = await this.publicGetGetInstruments (params); // // { // "instruments": [ // [ // 3, // id // "BTC", // symbol // 2, // price_scale // 6, // amount_scale // 1, // status // 0, // withdraw_fee // "BTC", // name // true, // withdrawal_pct // ], // ] // } // const currencies = {}; const instruments = this.safeValue (response, 'instruments', []); for (let i = 0; i < instruments.length; i++) { const currency = this.parseCurrency (instruments[i]); const code = currency['code']; currencies[code] = currency; } return currencies; } parseCurrency (currency) { // // [ // 3, // 0 id // "BTC", // 1 symbol // 2, // 2 price_scale // 6, // 3 amount_scale // 1, // 4 status // 0, // 5 withdraw_fee // "BTC", // 6 name // true, // 7 withdrawal_pct // ], // const id = this.safeString (currency, 0); const uppercaseId = this.safeString (currency, 1); const code = this.safeCurrencyCode (uppercaseId); const priceScale = this.safeInteger (currency, 2); const amountScale = this.safeInteger (currency, 3); const precision = Math.max (priceScale, amountScale); const name = this.safeString (currency, 6); const status = this.safeInteger (currency, 4); const active = (status === 1); const fee = this.safeNumber (currency, 5); // withdraw_fee return { 'id': id, 'info': currency, 'uppercaseId': uppercaseId, 'code': code, 'name': name, 'precision': precision, 'fee': fee, 'active': active, 'deposit': undefined, 'withdraw': undefined, 'limits': { 'amount': { 'min': undefined, 'max': undefined, }, 'withdraw': { 'min': undefined, 'max': undefined, }, }, }; } async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'pairId': parseInt (market['id']), 'timespan': this.timeframes[timeframe], }; if (limit !== undefined) { request['limit'] = limit; } const response = await this.publicGetGetChart (this.extend (request, params)); // // { // "pairId":57, // "t":1, // "s":"ETH/BTC", // "lastPx":44099, // "lastQty":100000, // "o":0.043831000000000016, // "h":0.04427100000000002, // "l":0.032000000000000015, // "c":0.04409900000000002, // "v":0.21267333000000016, // "q":4.850000000000001, // "chart":[ // [1612519260000,44099,44099,44099,44099,0,441], // [1612519200000,44099,44099,44099,44099,0,440], // [1612519140000,44269,44271,44269,44271,0,439], // ] // } // const chart = this.safeValue (response, 'chart', []); return this.parseOHLCVs (chart, market, timeframe, since, limit); } parseOHLCV (ohlcv, market = undefined) { // // [ // 1612519260000, // timestamp // 44099, // open // 44099, // high // 44099, // low // 44099, // close // 0, // base volume // 441, // seqNumber // ] // const timestamp = this.safeInteger (ohlcv, 0); const open = this.parseNumber (this.convertFromScale (this.safeString (ohlcv, 1), market['precision']['price'])); const high = this.parseNumber (this.convertFromScale (this.safeString (ohlcv, 2), market['precision']['price'])); const low = this.parseNumber (this.convertFromScale (this.safeString (ohlcv, 3), market['precision']['price'])); const close = this.parseNumber (this.convertFromScale (this.safeString (ohlcv, 4), market['precision']['price'])); const volume = this.parseNumber (this.convertFromScale (this.safeString (ohlcv, 5), market['precision']['amount'])); return [ timestamp, open, high, low, close, volume ]; } parseBidAsk (bidask, priceKey = 0, amountKey = 1, market = undefined) { if (market === undefined) { throw new ArgumentsRequired (this.id + ' parseBidAsk() requires a market argument'); } const priceString = this.safeString (bidask, priceKey); const amountString = this.safeString (bidask, amountKey); return [ this.parseNumber (this.convertFromScale (priceString, market['precision']['price'])), this.parseNumber (this.convertFromScale (amountString, market['precision']['amount'])), ]; } parseOrderBook (orderbook, symbol, timestamp = undefined, bidsKey = 'bids', asksKey = 'asks', priceKey = 0, amountKey = 1, market = undefined) { const result = { 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'nonce': undefined, }; const sides = [ bidsKey, asksKey ]; for (let i = 0; i < sides.length; i++) { const side = sides[i]; const orders = []; const bidasks = this.safeValue (orderbook, side); for (let k = 0; k < bidasks.length; k++) { orders.push (this.parseBidAsk (bidasks[k], priceKey, amountKey, market)); } result[side] = orders; } result[bidsKey] = this.sortBy (result[bidsKey], 0, true); result[asksKey] = this.sortBy (result[asksKey], 0); return result; } async fetchOrderBook (symbol, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'pairId': parseInt (market['id']), }; const response = await this.publicGetGetOrderBook (this.extend (request, params)); // // { // "bids":[ // [4000480,30000,1612644984667], // [3999304,200000,1612644984667], // [3998862,50000,1612644984667], // ], // "asks":[ // [4001962,1790000,1612644984667], // [4002616,1000,1612644984667], // [4003889,1000,1612644984667], // ], // "usdMark":40011.02, // "marketStatus":0, // "estFundingRate":0.0, // "fundingRateTime":0, // "auctionPrice":0.0, // "auctionVolume":0.0 // } // return this.parseOrderBook (response, symbol, undefined, 'bids', 'asks', 0, 1, market); } async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'pairId': parseInt (market['id']), }; const response = await this.publicGetGetTradeHistory (this.extend (request, params)); // // { // "trades":[ // [4022800,47000,"20210206-21:39:12.886",256323,1], // [4023066,1000,"20210206-21:38:55.030",256322,1], // [4022406,50000,"20210206-21:36:56.334",256321,1], // ] // } // const trades = this.safeValue (response, 'trades', []); return this.parseTrades (trades, market, since, limit, params); } parseTrade (trade, market = undefined) { // // public fetchTrades // // [ // 4022800, // 0 price // 47000, // 1 quantity // "20210206-21:39:12.886", // 2 timestamp // 256323, // 3 sequence number // 1 // 4 taker side 1 = buy, 2 = sell // ] // // private fetchMyTrades // // { // "account":3583, // "commission":"-0.015805", // "commCurrency":"USDC", // "execId":265757, // "ordType":"2", // "ordStatus":"2", // "execType":"F", // "aggressorIndicator":true, // "orderId":388953019, // "price":"1842.04", // "qty":"0.010000", // "lastPx":"1756.22", // "avgPx":"1756.22", // "cumQty":"0.010000", // "quoteQty":"0.010000", // "side":"BUY", // "symbol":"ETH/USDC", // "clOrdId":"1613106766970339107", // "submitterId":3583, // "targetStrategy":"0", // "time":1613106766971, // "date":"20210212-05:12:46.971" // } // let id = undefined; let timestamp = undefined; let orderId = undefined; let type = undefined; let side = undefined; let priceString = undefined; let amountString = undefined; let fee = undefined; let marketId = undefined; if (Array.isArray (trade)) { id = this.safeString (trade, 3); priceString = this.convertFromScale (this.safeString (trade, 0), market['precision']['price']); amountString = this.convertFromScale (this.safeString (trade, 1), market['precision']['amount']); timestamp = this.toMilliseconds (this.safeString (trade, 2)); const takerSide = this.safeInteger (trade, 4); if (takerSide === 1) { side = 'buy'; } else if (takerSide === 2) { side = 'sell'; } } else { id = this.safeString (trade, 'execId'); timestamp = this.safeInteger (trade, 'time'); marketId = this.safeString (trade, 'symbol'); orderId = this.safeString (trade, 'orderId'); side = this.safeStringLower (trade, 'side'); type = this.parseOrderType (this.safeString (trade, 'ordType')); priceString = this.safeString (trade, 'lastPx'); amountString = this.safeString (trade, 'qty'); let feeCostString = this.safeString (trade, 'commission'); if (feeCostString !== undefined) { feeCostString = Precise.stringNeg (feeCostString); const feeCurrencyId = this.safeString (trade, 'commCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { 'cost': feeCostString, 'currency': feeCurrencyCode, }; } } market = this.safeMarket (marketId, market); return this.safeTrade ({ 'info': trade, 'id': id, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'symbol': market['symbol'], 'order': orderId, 'type': type, 'side': side, 'takerOrMaker': undefined, 'price': priceString, 'amount': amountString, 'cost': undefined, 'fee': fee, }, market); } parseBalance (response) { const positions = this.safeValue (response, 'positions', []); const result = { 'info': response, }; for (let i = 0; i < positions.length; i++) { const position = positions[i]; const assetType = this.safeString (position, 'assetType'); if (assetType === 'ASSET') { const currencyId = this.safeString (position, 'symbol'); const code = this.safeCurrencyCode (currencyId); const quantityString = this.safeString (position, 'quantity'); const availableQuantityString = this.safeString (position, 'availableQuantity'); const scale = this.safeInteger (position, 'quantity_scale'); const account = this.account (); account['free'] = this.convertFromScale (availableQuantityString, scale); account['total'] = this.convertFromScale (quantityString, scale); result[code] = account; } } return this.safeBalance (result); } async fetchBalance (params = {}) { await this.loadMarkets (); const response = await this.privatePostGetPositions (params); // { // "positions":[ // { // "instrumentId":1, // "userId":3583, // "quantity":0, // "availableQuantity":0, // "quantity_scale":6, // "symbol":"USDC", // "assetType":"ASSET", // "usdCostBasis":0.0, // "usdAvgCostBasis":0.0, // "usdValue":0.0, // "usdUnrealized":0.0, // "usdRealized":0.0, // "baseUsdMark":1.0, // "settleCoinUsdMark":0.0, // "settleCoinUnrealized":0.0, // "settleCoinRealized":0.0 // }, // ] // } return this.parseBalance (response); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const orderSide = (side === 'buy') ? 1 : 2; const quantityScale = this.getScale (amount); const request = { // 'id': 0, // 'account': 0, // required for institutional users 'instrumentId': parseInt (market['id']), 'symbol': market['uppercaseId'], // 'clOrdId': '', 'side': orderSide, // 1 = buy, 2 = sell // 'ordType': 1, // 1 = market, 2 = limit, 3 = stop market, 4 = stop limit // 'price': this.priceToPrecision (symbol, price), // required for limit and stop limit orders // 'price_scale': this.getScale (price), 'quantity': this.convertToScale (this.numberToString (amount), quantityScale), 'quantity_scale': quantityScale, // 'stopPx': this.priceToPrecision (symbol, stopPx), // 'stopPx_scale': this.getScale (stopPx), // 'targetStrategy': 0, // 'isHidden': false, // 'timeInForce': 1, // 1 = Good Till Cancel (GTC), 3 = Immediate or Cancel (IOC), 4 = Fill or Kill (FOK), 5 = Good Till Crossing (GTX), 6 = Good Till Date (GTD) // 'interval': 0, // 'intervalCount': 0, // 'intervalDelay': 0, // 'price2': 0, // 'price2_scale': this.getScale (price2), // 'blockWaitAck': 0, // 1 = wait for order acknowledgement, when set, response will include the matching engine "orderId" field }; if (type === 'market') { request['ordType'] = 1; } else if (type === 'limit') { request['ordType'] = 2; const priceScale = this.getScale (price); request['price'] = this.convertToScale (this.numberToString (price), priceScale); request['priceScale'] = priceScale; } else { const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stopPx'); params = this.omit (params, [ 'stopPrice', 'stopPx' ]); if (stopPrice === undefined) { if (type === 'stop') { if (price === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument or a stopPrice parameter or a stopPx parameter for ' + type + ' orders'); } request['ordType'] = 3; request['stopPx'] = this.convertToScale (this.numberToString (price), this.getScale (price)); } else if (type === 'stop limit') { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPrice parameter or a stopPx parameter for ' + type + ' orders'); } } else { if (type === 'stop') { request['ordType'] = 3; request['stopPx'] = this.convertToScale (this.numberToString (stopPrice), this.getScale (stopPrice)); } else if (type === 'stop limit') { request['ordType'] = 4; const priceScale = this.getScale (price); const stopPriceScale = this.getScale (stopPrice); request['price_scale'] = priceScale; request['stopPx_scale'] = stopPriceScale; request['stopPx'] = this.convertToScale (this.numberToString (stopPrice), stopPriceScale); request['price'] = this.convertToScale (this.numberToString (price), priceScale); } } } const response = await this.privatePostOrder (this.extend (request, params)); // // { // "status":"sent", // "id":385617863, // "instrumentId":53, // "clOrdId":"1613037510849637345", // "userId":3583, // "price":2000, // "quantity":200, // "ordType":2 // } // return this.parseOrder (response, market); } async cancelOrder (id, symbol = undefined, params = {}) { if (symbol === undefined) { throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument'); } await this.loadMarkets (); const market = this.market (symbol); const request = { 'origOrderId': parseInt (id), 'instrumentId': parseInt (market['id']), }; const response = await this.privatePostCancelOrder (this.extend (request, params)); // // { // "status":"sent", // "id":0, // "origOrderId":385613629, // "instrumentId":53, // "userId":3583, // "price":0, // "quantity":0, // "ordType":0 // } // return this.parseOrder (response, market); } async editOrder (id, symbol, type, side, amount, price = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const orderSide = (side === 'buy') ? 1 : 2; const quantityScale = this.getScale (amount); const request = { // 'id': 0, 'origOrderId': id, // 'account': 0, // required for institutional users 'instrumentId': parseInt (market['id']), 'symbol': market['uppercaseId'], // 'clOrdId': '', 'side': orderSide, // 1 = buy, 2 = sell // 'ordType': 1, // 1 = market, 2 = limit, 3 = stop market, 4 = stop limit // 'price': this.priceToPrecision (symbol, price), // required for limit and stop limit orders // 'price_scale': this.getScale (price), 'quantity': this.convertToScale (this.numberToString (amount), quantityScale), 'quantity_scale': quantityScale, // 'stopPx': this.priceToPrecision (symbol, stopPx), // 'stopPx_scale': this.getScale (stopPx), // 'timeInForce': 1, // 1 = Good Till Cancel (GTC), 3 = Immediate or Cancel (IOC), 4 = Fill or Kill (FOK), 5 = Good Till Crossing (GTX), 6 = Good Till Date (GTD) }; if (type === 'market') { request['ordType'] = 1; } else if (type === 'limit') { request['ordType'] = 2; request['price'] = this.convertToScale (this.numberToString (price), this.getScale (price)); } else { const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stopPx'); params = this.omit (params, [ 'stopPrice', 'stopPx' ]); if (stopPrice === undefined) { if (type === 'stop') { if (price === undefined) { throw new ArgumentsRequired (this.id + ' editOrder() requires a price argument or a stopPrice parameter or a stopPx parameter for ' + type + ' orders'); } request['ordType'] = 3; request['stopPx'] = this.convertToScale (this.numberToString (price), this.getScale (price)); } else if (type === 'stop limit') { throw new ArgumentsRequired (this.id + ' editOrder() requires a stopPrice parameter or a stopPx parameter for ' + type + ' orders'); } } else { if (type === 'stop') { request['ordType'] = 3; request['stopPx'] = this.convertToScale (this.numberToString (stopPrice), this.getScale (stopPrice)); } else if (type === 'stop limit') { request['ordType'] = 4; const priceScale = this.getScale (price); const stopPriceScale = this.getScale (stopPrice); request['price_scale'] = priceScale; request['stopPx_scale'] = stopPriceScale; request['stopPx'] = this.convertToScale (this.numberToString (stopPrice), stopPriceScale); request['price'] = this.convertToScale (this.numberToString (price), priceScale); } } } const response = await this.privatePostOrder (this.extend (request, params)); // // { // "status":"sent", // "id":385617863, // "instrumentId":53, // "clOrdId":"1613037510849637345", // "userId":3583, // "price":2000, // "quantity":200, // "ordType":2 // } // return this.parseOrder (response, market); } async fetchOrder (id, symbol = undefined, params = {}) { await this.loadMarkets (); const request = { 'orderId': parseInt (id), }; const response = await this.privatePostGetOrderStatus (this.extend (request, params)); // // { // "orderId":388953019, // "clOrdId":"1613106766970339107", // "symbol":"ETH/USDC", // "instrumentId":53, // "side":"1", // "userId":3583, // "account":3583, // "execType":"F", // "ordType":"2", // "ordStatus":"2", // "timeInForce":"3", // "timeStamp":"20210212-05:12:46.971", // "execId":265757, // "targetStrategy":0, // "isHidden":false, // "isReduceOnly":false, // "isLiquidation":false, // "fee":0, // "fee_scale":6, // "feeInstrumentId":1, // "price":184204, // "price_scale":2, // "quantity":10000, // "quantity_scale":6, // "leavesQty":0, // "leavesQty_scale":6, // "cumQty":10000, // "cumQty_scale":6, // "lastPx":175622, // "lastPx_scale":2, // "avgPx":175622, // "avgPx_scale":2, // "lastQty":10000, // "lastQty_scale":6 // } // return this.parseOrder (response); } async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { const request = { 'ordStatus': '2', // '0' = New, '1' = Partially filled, '2' = Filled, '4' = Cancelled, '8' = Rejected, 'C' = Expired }; return await this.fetchOrders (symbol, since, limit, this.extend (request, params)); } async fetchCanceledOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { const request = { 'ordStatus': '4', // '0' = New, '1' = Partially filled, '2' = Filled, '4' = Cancelled, '8' = Rejected, 'C' = Expired }; return await this.fetchOrders (symbol, since, limit, this.extend (request, params)); } async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); let market = undefined; const request = { // 'account': id, // for institutional users // 'symbol': marketSymbol, // cannot be used with instrumentId // 'instrumentId': market['numericId'], // 'limit': limit, // 'execType': execType, // '0' = New, '4' = Canceled, '5' = Replace, '8' = Rejected, 'C' = Expired, 'F' = Fill Status, 'I' = Order Status // 'ordStatus': ordStatus, // '0' = New, '1' = Partially filled, '2' = Filled, '4' = Cancelled, '8' = Rejected, 'C' = Expired }; if (symbol !== undefined) { market = this.market (symbol); request['instrumentId'] = parseInt (market['id']); } if (limit !== undefined) { request['limit'] = limit; } const response = await this.privatePostGetOrders (this.extend (request, params)); // // { // "isInitialSnap":false, // "orders":[ // { // "orderId":385613629, // "orderUpdateSeq":1, // "clOrdId":"1613037448945798198", // "symbol":"ETH/USDC", // "instrumentId":53, // "side":"1", // "userId":3583, // "account":3583, // "execType":"4", // "ordType":"2", // "ordStatus":"C", // "timeInForce":"3", // "timeStamp":"20210211-09:57:28.944", // "execId":0, // "targetStrategy":0, // "isHidden":false, // "isReduceOnly":false, // "isLiquidation":false, // "fee":0, // "feeTotal":0, // "fee_scale":0, // "feeInstrumentId":0, // "price":999, // "price_scale":2, // "quantity":10000000, // "quantity_scale":6, // "leavesQty":10000000, // "leavesQty_scale":6, // "cumQty":0, // "cumQty_scale":0, // "lastPx":0, // "lastPx_scale":2, // "avgPx":0, // "avgPx_scale":0, // "lastQty":0, // "lastQty_scale":6 // } // ] // } // const orders = this.safeValue (response, 'orders', []); return this.parseOrders (orders, market, since, limit, params); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const request = { // 'account': 123, // for institutional users // 'instrumentId': market['id'], // 'startTime': since, // 'endTime': this.milliseconds (), }; let market = undefined; if (symbol !== undefined) { market = this.market (symbol); request['instrumentId'] = market['id']; } if (since !== undefined) { request['startTime'] = since; } const response = await this.privatePostUserTrades (this.extend (request, params)); // // { // "trades":[ // { // "account":3583, // "commission":"-0.015805", // "commCurrency":"USDC", // "execId":265757, // "ordType":"2", // "ordStatus":"2", // "execType":"F", // "aggressorIndicator":true, // "orderId":388953019, // "price":"1842.04", // "qty":"0.010000", // "lastPx":"1756.22", // "avgPx":"1756.22", // "cumQty":"0.010000", // "quoteQty":"0.010000", // "side":"BUY", // "symbol":"ETH/USDC", // "clOrdId":"1613106766970339107", // "submitterId":3583, // "targetStrategy":"0", // "time":1613106766971, // "date":"20210212-05:12:46.971" // } // ] // } // const trades = this.safeValue (response, 'trades', []); return this.parseTrades (trades, market, since, limit, params); } async fetchDepositAddress (code, params = {}) { await this.loadMarkets (); const currency = this.currency (code); const request = { 'instrumentId': parseInt (currency['id']), }; const response = await this.privatePostGetDepositAddresses (this.extend (request, params)); // // { // "addresses":[ // {"instrumentId":1,"userId":3583,"symbol":"USDC","address":"0xdff47af071ea3c537e57278290516cda32a78b97","status":1} // ] // } // const addresses = this.safeValue (response, 'addresses', []); const address = this.safeValue (addresses, 0); return this.parseDepositAddress (address, currency); } parseDepositAddress (depositAddress, currency = undefined) { // // { // "instrumentId":1, // "userId":3583, // "symbol":"USDC", // "address":"0xdff47af071ea3c537e57278290516cda32a78b97", // "status":1 // } // const currencyId = this.safeString (depositAddress, 'symbol'); const code = this.safeCurrencyCode (currencyId, currency); const address = this.safeString (depositAddress, 'address'); this.checkAddress (address); return { 'currency': code, 'address': address, 'tag': undefined, 'network': undefined, 'info': depositAddress, }; } async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const request = {}; let currency = undefined; if (code !== undefined) { currency = this.currency (code); request['instrumentId'] = parseInt (currency['id']); } const response = await this.privatePostGetDepositHistory (this.extend (request, params)); // // { // "deposits":[ // { // "id":4309, // "instrumentId":1, // "userId":3583, // "symbol":"USDC", // "address":"null", // "timestamp":"1613021112189", // "status":1, // "balance":0.0, // "balance_change":100.0, // "confirms":1, // "transactionId":"caba4500-489f-424e-abd7-b4dabc09a800" // } // ] // } // const deposits = this.safeValue (response, 'deposits', []); return this.parseTransactions (deposits, currency, since, limit, { 'type': 'deposit' }); } async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const request = {}; let currency = undefined; if (code !== undefined) { currency = this.currency (code); request['instrumentId'] = parseInt (currency['id']); } const response = await this.privatePostGetWithdrawRequests (this.extend (request, params)); // // { // "addresses":[ // { // "id":3841, // "instrumentId":3, // "userId":4245, // "symbol":"BTC", // "address":"XXXXXYYYYYZZZZZ", // "timestamp":"20200806-11:04:35.053", // "status":0, // "balance":1, // "balance_scale":3, // "confirms":0, // "transactionId":"null" // } // ] // } // const withdrawals = this.safeValue (response, 'addresses', []); return this.parseTransactions (withdrawals, currency, since, limit, { 'type': 'withdrawal' }); } parseTransaction (transaction, currency = undefined) { // // fetchDeposits, fetchWithdrawals // // { // "id":4309, // "instrumentId":1, // "userId":3583, // "symbol":"USDC", // "address":"null", // "timestamp":"1613021112189", // "status":1, // "balance":0.0, // "balance_change":100.0, // "confirms":1, // "transactionId":"caba4500-489f-424e-abd7-b4dabc09a800" // } // // withdraw // // { // "instrumentId": 1, // "userId": 23750, // "symbol": "USDC", // "timestamp": "20200201-05:37:16.584", // "status": 1, // "userUuid": "b9e33713-c28f-468f-99bd-f6deab0dd854", // "currencyCode": "USDC", // "address": "2MvW97yT6E2Kq8bWc1aj1DqfbgMzjRNk2LE", // "quantity": 20, // "requestUuid": "56782b34-8a78-4f5f-b164-4b8f7d583b7f", // "transactionUuid": "1004eb0f-41e1-41e9-9d48-8eefcc6c09f2", // "transactionId": "WS23436", // "destinationWalletAlias": "Test", // "quantity_scale": 0 // } // const id = this.safeString (transaction, 'id', 'transactionId'); const txid = this.safeString (transaction, 'transactionUuid'); const timestamp = this.safeInteger (transaction, 'timestamp'); let address = this.safeString (transaction, 'address'); if (address === 'null') { address = undefined; } const type = this.safeString (transaction, 'type'); let amount = this.safeNumber (transaction, 'balance_change'); if (amount === undefined) { amount = this.safeString (transaction, 'quantity'); const amountScale = this.safeInteger (transaction, 'quantity_scale'); amount = this.parseNumber (this.convertFromScale (amount, amountScale)); } const currencyId = this.safeString (transaction, 'symbol'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); return { 'info':