UNPKG

ccxt

Version:

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

1,179 lines (1,177 loc) 107 kB
'use strict'; var poloniex$1 = require('./abstract/poloniex.js'); var errors = require('./base/errors.js'); var Precise = require('./base/Precise.js'); var number = require('./base/functions/number.js'); var sha256 = require('./static_dependencies/noble-hashes/sha256.js'); // ---------------------------------------------------------------------------- // --------------------------------------------------------------------------- /** * @class poloniex * @augments Exchange */ class poloniex extends poloniex$1 { describe() { return this.deepExtend(super.describe(), { 'id': 'poloniex', 'name': 'Poloniex', 'countries': ['US'], // 200 requests per second for some unauthenticated market endpoints => 1000ms / 200 = 5ms between requests 'rateLimit': 5, 'certified': false, 'pro': true, 'has': { 'CORS': undefined, 'spot': true, 'margin': undefined, 'swap': false, 'future': false, 'option': false, 'cancelAllOrders': true, 'cancelOrder': true, 'createDepositAddress': true, 'createMarketBuyOrderWithCost': true, 'createMarketOrderWithCost': false, 'createMarketSellOrderWithCost': false, 'createOrder': true, 'createStopOrder': true, 'createTriggerOrder': true, 'editOrder': true, 'fetchBalance': true, 'fetchClosedOrder': false, 'fetchCurrencies': true, 'fetchDepositAddress': true, 'fetchDepositAddresses': false, 'fetchDepositAddressesByNetwork': false, 'fetchDeposits': true, 'fetchDepositsWithdrawals': true, 'fetchDepositWithdrawFee': 'emulated', 'fetchDepositWithdrawFees': true, 'fetchFundingHistory': false, 'fetchFundingInterval': false, 'fetchFundingIntervals': false, 'fetchFundingRate': false, 'fetchFundingRateHistory': false, 'fetchFundingRates': false, 'fetchMarginMode': false, 'fetchMarkets': true, 'fetchMyTrades': true, 'fetchOHLCV': true, 'fetchOpenInterestHistory': false, 'fetchOpenOrder': false, 'fetchOpenOrders': true, 'fetchOrder': true, 'fetchOrderBook': true, 'fetchOrderBooks': false, 'fetchOrderTrades': true, 'fetchPosition': false, 'fetchPositionMode': false, 'fetchTicker': true, 'fetchTickers': true, 'fetchTime': true, 'fetchTrades': true, 'fetchTradingFee': false, 'fetchTradingFees': true, 'fetchTransactions': 'emulated', 'fetchTransfer': false, 'fetchTransfers': false, 'fetchWithdrawals': true, 'sandbox': true, 'transfer': true, 'withdraw': true, }, 'timeframes': { '1m': 'MINUTE_1', '5m': 'MINUTE_5', '10m': 'MINUTE_10', '15m': 'MINUTE_15', '30m': 'MINUTE_30', '1h': 'HOUR_1', '2h': 'HOUR_2', '4h': 'HOUR_4', '6h': 'HOUR_6', '12h': 'HOUR_12', '1d': 'DAY_1', '3d': 'DAY_3', '1w': 'WEEK_1', '1M': 'MONTH_1', }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/1294454/27766817-e9456312-5ee6-11e7-9b3c-b628ca5626a5.jpg', 'api': { 'rest': 'https://api.poloniex.com', }, 'test': { 'rest': 'https://sand-spot-api-gateway.poloniex.com', }, 'www': 'https://www.poloniex.com', 'doc': 'https://api-docs.poloniex.com/spot/', 'fees': 'https://poloniex.com/fees', 'referral': 'https://poloniex.com/signup?c=UBFZJRPJ', }, 'api': { 'public': { 'get': { 'markets': 20, 'markets/{symbol}': 1, 'currencies': 20, 'currencies/{currency}': 20, 'v2/currencies': 20, 'v2/currencies/{currency}': 20, 'timestamp': 1, 'markets/price': 1, 'markets/{symbol}/price': 1, 'markets/markPrice': 1, 'markets/{symbol}/markPrice': 1, 'markets/{symbol}/markPriceComponents': 1, 'markets/{symbol}/orderBook': 1, 'markets/{symbol}/candles': 1, 'markets/{symbol}/trades': 20, 'markets/ticker24h': 20, 'markets/{symbol}/ticker24h': 20, 'markets/collateralInfo': 1, 'markets/{currency}/collateralInfo': 1, 'markets/borrowRatesInfo': 1, }, }, 'private': { 'get': { 'accounts': 4, 'accounts/balances': 4, 'accounts/{id}/balances': 4, 'accounts/activity': 20, 'accounts/transfer': 20, 'accounts/transfer/{id}': 4, 'feeinfo': 20, 'accounts/interest/history': 1, 'subaccounts': 4, 'subaccounts/balances': 20, 'subaccounts/{id}/balances': 4, 'subaccounts/transfer': 20, 'subaccounts/transfer/{id}': 4, 'wallets/addresses': 20, 'wallets/addresses/{currency}': 20, 'wallets/activity': 20, 'margin/accountMargin': 4, 'margin/borrowStatus': 4, 'margin/maxSize': 4, 'orders': 20, 'orders/{id}': 4, 'orders/killSwitchStatus': 4, 'smartorders': 20, 'smartorders/{id}': 4, 'orders/history': 20, 'smartorders/history': 20, 'trades': 20, 'orders/{id}/trades': 4, }, 'post': { 'accounts/transfer': 4, 'subaccounts/transfer': 20, 'wallets/address': 20, 'wallets/withdraw': 20, 'v2/wallets/withdraw': 20, 'orders': 4, 'orders/batch': 20, 'orders/killSwitch': 4, 'smartorders': 4, }, 'delete': { 'orders/{id}': 4, 'orders/cancelByIds': 20, 'orders': 20, 'smartorders/{id}': 4, 'smartorders/cancelByIds': 20, 'smartorders': 20, }, 'put': { 'orders/{id}': 20, 'smartorders/{id}': 20, }, }, }, 'fees': { 'trading': { 'feeSide': 'get', // starting from Jan 8 2020 'maker': this.parseNumber('0.0009'), 'taker': this.parseNumber('0.0009'), }, 'funding': {}, }, 'commonCurrencies': { 'AIR': 'AirCoin', 'APH': 'AphroditeCoin', 'BCC': 'BTCtalkcoin', 'BCHABC': 'BCHABC', 'BDG': 'Badgercoin', 'BTM': 'Bitmark', 'CON': 'Coino', 'ETHTRON': 'ETH', 'GOLD': 'GoldEagles', 'GPUC': 'GPU', 'HOT': 'Hotcoin', 'ITC': 'Information Coin', 'KEY': 'KEYCoin', 'MASK': 'NFTX Hashmasks Index', 'MEME': 'Degenerator Meme', 'PLX': 'ParallaxCoin', 'REPV2': 'REP', 'STR': 'XLM', 'SOC': 'SOCC', 'TRADE': 'Unitrade', 'TRXETH': 'TRX', 'XAP': 'API Coin', // this is not documented in the API docs for Poloniex // https://github.com/ccxt/ccxt/issues/7084 // when the user calls withdraw ('USDT', amount, address, tag, params) // with params = { 'currencyToWithdrawAs': 'USDTTRON' } // or params = { 'currencyToWithdrawAs': 'USDTETH' } // fetchWithdrawals ('USDT') returns the corresponding withdrawals // with a USDTTRON or a USDTETH currency id, respectfully // therefore we have map them back to the original code USDT // otherwise the returned withdrawals are filtered out 'USDTBSC': 'USDT', 'USDTTRON': 'USDT', 'USDTETH': 'USDT', 'UST': 'USTC', }, 'options': { 'createMarketBuyOrderRequiresPrice': true, 'networks': { 'BEP20': 'BSC', 'ERC20': 'ETH', 'TRC20': 'TRON', }, 'limits': { 'cost': { 'min': { 'BTC': 0.0001, 'ETH': 0.0001, 'USDT': 1.0, 'TRX': 100, 'BNB': 0.06, 'USDC': 1.0, 'USDJ': 1.0, 'TUSD': 0.0001, 'DAI': 1.0, 'PAX': 1.0, 'BUSD': 1.0, }, }, }, 'accountsByType': { 'spot': 'spot', 'future': 'futures', }, 'accountsById': { 'exchange': 'spot', 'futures': 'future', }, }, 'features': { 'default': { 'sandbox': true, 'createOrder': { 'marginMode': true, 'triggerPrice': true, 'triggerPriceType': undefined, 'triggerDirection': false, 'stopLossPrice': false, 'takeProfitPrice': false, 'attachedStopLossTakeProfit': undefined, 'timeInForce': { 'IOC': true, 'FOK': true, 'PO': false, 'GTD': false, }, 'hedged': false, 'leverage': false, 'marketBuyByCost': true, 'marketBuyRequiresPrice': false, 'selfTradePrevention': true, 'trailing': false, 'iceberg': false, }, 'createOrders': undefined, 'fetchMyTrades': { 'marginMode': false, 'limit': 1000, 'daysBack': 100000, 'untilDays': 100000, 'symbolRequired': false, }, 'fetchOrder': { 'marginMode': false, 'trigger': false, 'trailing': false, 'symbolRequired': false, }, 'fetchOpenOrders': { 'marginMode': false, 'limit': 2000, 'trigger': false, 'trailing': false, 'symbolRequired': false, }, 'fetchOrders': undefined, 'fetchClosedOrders': undefined, 'fetchOHLCV': { 'limit': 500, }, }, 'spot': { 'extends': 'default', }, 'swap': { 'linear': undefined, 'inverse': undefined, }, 'future': { 'linear': undefined, 'inverse': undefined, }, }, 'precisionMode': number.TICK_SIZE, 'exceptions': { 'exact': { // General '500': errors.ExchangeNotAvailable, '603': errors.RequestTimeout, '601': errors.BadRequest, '415': errors.ExchangeError, '602': errors.ArgumentsRequired, // Accounts '21604': errors.BadRequest, '21600': errors.AuthenticationError, '21605': errors.AuthenticationError, '21102': errors.ExchangeError, '21100': errors.AuthenticationError, '21704': errors.AuthenticationError, '21700': errors.BadRequest, '21705': errors.BadRequest, '21707': errors.ExchangeError, '21708': errors.BadRequest, '21601': errors.AccountSuspended, '21711': errors.ExchangeError, '21709': errors.InsufficientFunds, '250000': errors.ExchangeError, '250001': errors.BadRequest, '250002': errors.BadRequest, '250003': errors.BadRequest, '250004': errors.BadRequest, '250005': errors.InsufficientFunds, '250008': errors.BadRequest, '250012': errors.ExchangeError, // Trading '21110': errors.BadRequest, '10040': errors.BadSymbol, '10060': errors.ExchangeError, '10020': errors.BadSymbol, '10041': errors.BadSymbol, '21340': errors.OnMaintenance, '21341': errors.InvalidOrder, '21342': errors.InvalidOrder, '21343': errors.InvalidOrder, '21351': errors.AccountSuspended, '21352': errors.BadSymbol, '21353': errors.PermissionDenied, '21354': errors.PermissionDenied, '21359': errors.OrderNotFound, '21360': errors.InvalidOrder, '24106': errors.BadRequest, '24201': errors.ExchangeNotAvailable, // Orders '21301': errors.OrderNotFound, '21302': errors.ExchangeError, '21304': errors.ExchangeError, '21305': errors.OrderNotFound, '21307': errors.ExchangeError, '21309': errors.InvalidOrder, '21310': errors.InvalidOrder, '21311': errors.InvalidOrder, '21312': errors.InvalidOrder, '21314': errors.InvalidOrder, '21315': errors.InvalidOrder, '21317': errors.InvalidOrder, '21319': errors.InvalidOrder, '21320': errors.InvalidOrder, '21321': errors.InvalidOrder, '21322': errors.InvalidOrder, '21324': errors.BadRequest, '21327': errors.InvalidOrder, '21328': errors.InvalidOrder, '21330': errors.InvalidOrder, '21335': errors.InvalidOrder, '21336': errors.InvalidOrder, '21337': errors.InvalidOrder, '21344': errors.InvalidOrder, '21345': errors.InvalidOrder, '21346': errors.InvalidOrder, '21348': errors.InvalidOrder, '21347': errors.InvalidOrder, '21349': errors.InvalidOrder, '21350': errors.InvalidOrder, '21355': errors.ExchangeError, '21356': errors.BadRequest, '21721': errors.InsufficientFunds, '24101': errors.BadSymbol, '24102': errors.InvalidOrder, '24103': errors.InvalidOrder, '24104': errors.InvalidOrder, '24105': errors.InvalidOrder, '25020': errors.InvalidOrder, // Smartorders '25000': errors.InvalidOrder, '25001': errors.InvalidOrder, '25002': errors.InvalidOrder, '25003': errors.ExchangeError, '25004': errors.InvalidOrder, '25005': errors.ExchangeError, '25006': errors.InvalidOrder, '25007': errors.InvalidOrder, '25008': errors.InvalidOrder, '25009': errors.ExchangeError, '25010': errors.PermissionDenied, '25011': errors.InvalidOrder, '25012': errors.ExchangeError, '25013': errors.OrderNotFound, '25014': errors.OrderNotFound, '25015': errors.OrderNotFound, '25016': errors.ExchangeError, '25017': errors.ExchangeError, '25018': errors.BadRequest, '25019': errors.BadSymbol, // Invalid symbol }, 'broad': {}, }, }); } parseOHLCV(ohlcv, market = undefined) { // // [ // [ // "22814.01", // "22937.42", // "22832.57", // "22937.42", // "3916.58764051", // "0.171199", // "2982.64647063", // "0.130295", // 33, // 0, // "22877.449915304470460711", // "MINUTE_5", // 1659664800000, // 1659665099999 // ] // ] // return [ this.safeInteger(ohlcv, 12), this.safeNumber(ohlcv, 2), this.safeNumber(ohlcv, 1), this.safeNumber(ohlcv, 0), this.safeNumber(ohlcv, 3), this.safeNumber(ohlcv, 5), ]; } /** * @method * @name poloniex#fetchOHLCV * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market * @see https://api-docs.poloniex.com/spot/api/public/market-data#candles * @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} [since] timestamp in ms of the earliest candle to fetch * @param {int} [limit] the maximum amount of candles to fetch * @param {object} [params] extra parameters specific to the exchange API endpoint * @param {int} [params.until] timestamp in ms * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params) * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume */ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets(); let paginate = false; [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate', false); if (paginate) { return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 500); } const market = this.market(symbol); let request = { 'symbol': market['id'], 'interval': this.safeString(this.timeframes, timeframe, timeframe), }; if (since !== undefined) { request['startTime'] = since; } if (limit !== undefined) { // limit should in between 100 and 500 request['limit'] = limit; } [request, params] = this.handleUntilOption('endTime', request, params); const response = await this.publicGetMarketsSymbolCandles(this.extend(request, params)); // // [ // [ // "22814.01", // "22937.42", // "22832.57", // "22937.42", // "3916.58764051", // "0.171199", // "2982.64647063", // "0.130295", // 33, // 0, // "22877.449915304470460711", // "MINUTE_5", // 1659664800000, // 1659665099999 // ] // ] // return this.parseOHLCVs(response, market, timeframe, since, limit); } async loadMarkets(reload = false, params = {}) { const markets = await super.loadMarkets(reload, params); const currenciesByNumericId = this.safeValue(this.options, 'currenciesByNumericId'); if ((currenciesByNumericId === undefined) || reload) { this.options['currenciesByNumericId'] = this.indexBy(this.currencies, 'numericId'); } return markets; } /** * @method * @name poloniex#fetchMarkets * @description retrieves data on all markets for poloniex * @see https://api-docs.poloniex.com/spot/api/public/reference-data#symbol-information * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {object[]} an array of objects representing market data */ async fetchMarkets(params = {}) { const markets = await this.publicGetMarkets(params); // // [ // { // "symbol" : "BTS_BTC", // "baseCurrencyName" : "BTS", // "quoteCurrencyName" : "BTC", // "displayName" : "BTS/BTC", // "state" : "NORMAL", // "visibleStartTime" : 1659018816626, // "tradableStartTime" : 1659018816626, // "symbolTradeLimit" : { // "symbol" : "BTS_BTC", // "priceScale" : 10, // "quantityScale" : 0, // "amountScale" : 8, // "minQuantity" : "100", // "minAmount" : "0.00001", // "highestBid" : "0", // "lowestAsk" : "0" // } // } // ] // return this.parseMarkets(markets); } parseMarket(market) { const id = this.safeString(market, 'symbol'); const baseId = this.safeString(market, 'baseCurrencyName'); const quoteId = this.safeString(market, 'quoteCurrencyName'); const base = this.safeCurrencyCode(baseId); const quote = this.safeCurrencyCode(quoteId); const state = this.safeString(market, 'state'); const active = state === 'NORMAL'; const symbolTradeLimit = this.safeValue(market, 'symbolTradeLimit'); // these are known defaults return { 'id': id, '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': active, 'contract': false, 'linear': undefined, 'inverse': undefined, 'contractSize': undefined, 'expiry': undefined, 'expiryDatetime': undefined, 'strike': undefined, 'optionType': undefined, 'precision': { 'amount': this.parseNumber(this.parsePrecision(this.safeString(symbolTradeLimit, 'quantityScale'))), 'price': this.parseNumber(this.parsePrecision(this.safeString(symbolTradeLimit, 'priceScale'))), }, 'limits': { 'amount': { 'min': this.safeNumber(symbolTradeLimit, 'minQuantity'), 'max': undefined, }, 'price': { 'min': undefined, 'max': undefined, }, 'cost': { 'min': this.safeNumber(symbolTradeLimit, 'minAmount'), 'max': undefined, }, }, 'created': this.safeInteger(market, 'tradableStartTime'), 'info': market, }; } /** * @method * @name poloniex#fetchTime * @description fetches the current integer timestamp in milliseconds from the exchange server * @see https://api-docs.poloniex.com/spot/api/public/reference-data#system-timestamp * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {int} the current integer timestamp in milliseconds from the exchange server */ async fetchTime(params = {}) { const response = await this.publicGetTimestamp(params); return this.safeInteger(response, 'serverTime'); } parseTicker(ticker, market = undefined) { // // { // "symbol" : "BTC_USDT", // "open" : "26053.33", // "low" : "26053.33", // "high" : "26798.02", // "close" : "26447.58", // "quantity" : "6116.210188", // "amount" : "161082122.88450926", // "tradeCount" : "134709", // "startTime" : "1692784440000", // "closeTime" : "1692870839630", // "displayName" : "BTC/USDT", // "dailyChange" : "0.0151", // "bid" : "26447.57", // "bidQuantity" : "0.016313", // "ask" : "26447.58", // "askQuantity" : "0.068307", // "ts" : "1692870845446", // "markPrice" : "26444.11" // } // const timestamp = this.safeInteger(ticker, 'ts'); const marketId = this.safeString(ticker, 'symbol'); market = this.safeMarket(marketId); const close = this.safeString(ticker, 'close'); const relativeChange = this.safeString(ticker, 'dailyChange'); const percentage = Precise["default"].stringMul(relativeChange, '100'); const bidVolume = this.safeString(ticker, 'bidQuantity'); const askVolume = this.safeString(ticker, 'askQuantity'); return this.safeTicker({ 'id': marketId, 'symbol': market['symbol'], 'timestamp': timestamp, 'datetime': this.iso8601(timestamp), 'high': this.safeString(ticker, 'high'), 'low': this.safeString(ticker, 'low'), 'bid': this.safeString(ticker, 'bid'), 'bidVolume': bidVolume, 'ask': this.safeString(ticker, 'ask'), 'askVolume': askVolume, 'vwap': undefined, 'open': this.safeString(ticker, 'open'), 'close': close, 'last': close, 'previousClose': undefined, 'change': undefined, 'percentage': percentage, 'average': undefined, 'baseVolume': this.safeString(ticker, 'quantity'), 'quoteVolume': this.safeString(ticker, 'amount'), 'markPrice': this.safeString(ticker, 'markPrice'), 'info': ticker, }, market); } /** * @method * @name poloniex#fetchTickers * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market * @see https://api-docs.poloniex.com/spot/api/public/market-data#ticker * @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 exchange API endpoint * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure} */ async fetchTickers(symbols = undefined, params = {}) { await this.loadMarkets(); symbols = this.marketSymbols(symbols); const response = await this.publicGetMarketsTicker24h(params); // // [ // { // "symbol" : "BTC_USDT", // "open" : "26053.33", // "low" : "26053.33", // "high" : "26798.02", // "close" : "26447.58", // "quantity" : "6116.210188", // "amount" : "161082122.88450926", // "tradeCount" : "134709", // "startTime" : "1692784440000", // "closeTime" : "1692870839630", // "displayName" : "BTC/USDT", // "dailyChange" : "0.0151", // "bid" : "26447.57", // "bidQuantity" : "0.016313", // "ask" : "26447.58", // "askQuantity" : "0.068307", // "ts" : "1692870845446", // "markPrice" : "26444.11" // } // ] // return this.parseTickers(response, symbols); } /** * @method * @name poloniex#fetchCurrencies * @description fetches all available currencies on an exchange * @see https://api-docs.poloniex.com/spot/api/public/reference-data#currency-information * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {object} an associative dictionary of currencies */ async fetchCurrencies(params = {}) { const response = await this.publicGetCurrencies(this.extend(params, { 'includeMultiChainCurrencies': true })); // // [ // { // "1CR": { // "id": 1, // "name": "1CRedit", // "description": "BTC Clone", // "type": "address", // "withdrawalFee": "0.01000000", // "minConf": 10000, // "depositAddress": null, // "blockchain": "1CR", // "delisted": false, // "tradingState": "NORMAL", // "walletState": "DISABLED", // "walletDepositState": "DISABLED", // "walletWithdrawalState": "DISABLED", // "parentChain": null, // "isMultiChain": false, // "isChildChain": false, // "childChains": [] // } // } // ] // const result = {}; for (let i = 0; i < response.length; i++) { const item = this.safeValue(response, i); const ids = Object.keys(item); const id = this.safeValue(ids, 0); const currency = this.safeValue(item, id); const code = this.safeCurrencyCode(id); const name = this.safeString(currency, 'name'); const networkId = this.safeString(currency, 'blockchain'); let networkCode = undefined; if (networkId !== undefined) { networkCode = this.networkIdToCode(networkId, code); } const delisted = this.safeValue(currency, 'delisted'); const walletEnabled = this.safeString(currency, 'walletState') === 'ENABLED'; const depositEnabled = this.safeString(currency, 'walletDepositState') === 'ENABLED'; const withdrawEnabled = this.safeString(currency, 'walletWithdrawalState') === 'ENABLED'; const active = !delisted && walletEnabled && depositEnabled && withdrawEnabled; const numericId = this.safeInteger(currency, 'id'); const feeString = this.safeString(currency, 'withdrawalFee'); const parentChain = this.safeValue(currency, 'parentChain'); const noParentChain = parentChain === undefined; if (this.safeValue(result, code) === undefined) { result[code] = { 'id': id, 'code': code, 'info': undefined, 'name': name, 'active': active, 'deposit': depositEnabled, 'withdraw': withdrawEnabled, 'fee': this.parseNumber(feeString), 'precision': undefined, 'limits': { 'amount': { 'min': undefined, 'max': undefined, }, 'deposit': { 'min': undefined, 'max': undefined, }, 'withdraw': { 'min': undefined, 'max': undefined, }, }, }; } let minFeeString = this.safeString(result[code], 'fee'); if (feeString !== undefined) { minFeeString = (minFeeString === undefined) ? feeString : Precise["default"].stringMin(feeString, minFeeString); } let depositAvailable = this.safeValue(result[code], 'deposit'); depositAvailable = (depositEnabled) ? depositEnabled : depositAvailable; let withdrawAvailable = this.safeValue(result[code], 'withdraw'); withdrawAvailable = (withdrawEnabled) ? withdrawEnabled : withdrawAvailable; const networks = this.safeValue(result[code], 'networks', {}); if (networkCode !== undefined) { networks[networkCode] = { 'info': currency, 'id': networkId, 'network': networkCode, 'currencyId': id, 'numericId': numericId, 'deposit': depositEnabled, 'withdraw': withdrawEnabled, 'active': active, 'fee': this.parseNumber(feeString), 'precision': undefined, 'limits': { 'amount': { 'min': undefined, 'max': undefined, }, 'withdraw': { 'min': undefined, 'max': undefined, }, 'deposit': { 'min': undefined, 'max': undefined, }, }, }; } result[code]['networks'] = networks; const info = this.safeValue(result[code], 'info', []); const rawInfo = {}; rawInfo[id] = currency; info.push(rawInfo); result[code]['info'] = info; if (noParentChain) { result[code]['id'] = id; result[code]['name'] = name; } result[code]['active'] = depositAvailable && withdrawAvailable; result[code]['deposit'] = depositAvailable; result[code]['withdraw'] = withdrawAvailable; result[code]['fee'] = this.parseNumber(minFeeString); } return result; } /** * @method * @name poloniex#fetchTicker * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market * @see https://api-docs.poloniex.com/spot/api/public/market-data#ticker * @param {string} symbol unified symbol of the market to fetch the ticker for * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure} */ async fetchTicker(symbol, params = {}) { await this.loadMarkets(); const market = this.market(symbol); const request = { 'symbol': market['id'], }; const response = await this.publicGetMarketsSymbolTicker24h(this.extend(request, params)); // // { // "symbol" : "BTC_USDT", // "open" : "26053.33", // "low" : "26053.33", // "high" : "26798.02", // "close" : "26447.58", // "quantity" : "6116.210188", // "amount" : "161082122.88450926", // "tradeCount" : "134709", // "startTime" : "1692784440000", // "closeTime" : "1692870839630", // "displayName" : "BTC/USDT", // "dailyChange" : "0.0151", // "bid" : "26447.57", // "bidQuantity" : "0.016313", // "ask" : "26447.58", // "askQuantity" : "0.068307", // "ts" : "1692870845446", // "markPrice" : "26444.11" // } // return this.parseTicker(response, market); } parseTrade(trade, market = undefined) { // // fetchTrades // // { // "id" : "60014521", // "price" : "23162.94", // "quantity" : "0.00009", // "amount" : "2.0846646", // "takerSide" : "SELL", // "ts" : 1659684602042, // "createTime" : 1659684602036 // } // // fetchMyTrades // // { // "id": "32164924331503616", // "symbol": "LINK_USDT", // "accountType": "SPOT", // "orderId": "32164923987566592", // "side": "SELL", // "type": "MARKET", // "matchRole": "TAKER", // "createTime": 1648635115525, // "price": "11", // "quantity": "0.5", // "amount": "5.5", // "feeCurrency": "USDT", // "feeAmount": "0.007975", // "pageId": "32164924331503616", // "clientOrderId": "myOwnId-321" // } // // fetchOrderTrades (taker trades) // // { // "id": "30341456333942784", // "symbol": "LINK_USDT", // "accountType": "SPOT", // "orderId": "30249408733945856", // "side": "BUY", // "type": "LIMIT", // "matchRole": "MAKER", // "createTime": 1648200366864, // "price": "3.1", // "quantity": "1", // "amount": "3.1", // "feeCurrency": "LINK", // "feeAmount": "0.00145", // "pageId": "30341456333942784", // "clientOrderId": "" // } // // const id = this.safeString2(trade, 'id', 'tradeID'); const orderId = this.safeString(trade, 'orderId'); const timestamp = this.safeInteger2(trade, 'ts', 'createTime'); const marketId = this.safeString(trade, 'symbol'); market = this.safeMarket(marketId, market, '_'); const symbol = market['symbol']; const side = this.safeStringLower2(trade, 'side', 'takerSide'); let fee = undefined; const priceString = this.safeString(trade, 'price'); const amountString = this.safeString(trade, 'quantity'); const costString = this.safeString(trade, 'amount'); const feeCurrencyId = this.safeString(trade, 'feeCurrency'); const feeCostString = this.safeString(trade, 'feeAmount'); if (feeCostString !== undefined) { const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId); fee = { 'cost': feeCostString, 'currency': feeCurrencyCode, }; } return this.safeTrade({ 'id': id, 'info': trade, 'timestamp': timestamp, 'datetime': this.iso8601(timestamp), 'symbol': symbol, 'order': orderId, 'type': this.safeStringLower(trade, 'type'), 'side': side, 'takerOrMaker': this.safeStringLower(trade, 'matchRole'), 'price': priceString, 'amount': amountString, 'cost': costString, 'fee': fee, }, market); } /** * @method * @name poloniex#fetchTrades * @description get the list of most recent trades for a particular symbol * @see https://api-docs.poloniex.com/spot/api/public/market-data#trades * @param {string} symbol unified symbol of the market to fetch trades for * @param {int} [since] timestamp in ms of the earliest trade to fetch * @param {int} [limit] the maximum amount of trades to fetch * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades} */ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) { await this.loadMarkets(); const market = this.market(symbol); const request = { 'symbol': market['id'], }; if (limit !== undefined) { request['limit'] = limit; } const trades = await this.publicGetMarketsSymbolTrades(this.extend(request, params)); // // [ // { // "id" : "60014521", // "price" : "23162.94", // "quantity" : "0.00009", // "amount" : "2.0846646", // "takerSide" : "SELL", // "ts" : 1659684602042, // "createTime" : 1659684602036 // } // ] // return this.parseTrades(trades, market, since, limit); } /** * @method * @name poloniex#fetchMyTrades * @description fetch all trades made by the user * @see https://api-docs.poloniex.com/spot/api/private/trade#trade-history * @param {string} symbol unified market symbol * @param {int} [since] the earliest time in ms to fetch trades for * @param {int} [limit] the maximum number of trades structures to retrieve * @param {object} [params] extra parameters specific to the exchange API endpoint * @param {int} [params.until] the latest time in ms to fetch entries for * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params) * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure} */ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) { await this.loadMarkets(); let paginate = false; [paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate'); if (paginate) { return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params); } let market = undefined; if (symbol !== undefined) { market = this.market(symbol); } let request = { // 'from': 12345678, // A 'trade Id'. The query begins at ‘from'. // 'direction': 'PRE', // PRE, NEXT The direction before or after ‘from'. }; if (since !== undefined) { request['startTime'] = since; } if (limit !== undefined) { request['limit'] = limit; } [request, params] = this.handleUntilOption('endTime', request, params); const response = await this.privateGetTrades(this.extend(request, params)); // // [ // { // "id": "32164924331503616", // "symbol": "LINK_USDT", // "accountType": "SPOT", // "orderId": "32164923987566592", // "side": "SELL", // "type": "MARKET", // "matchRole": "TAKER", // "createTime": 1648635115525, // "price": "11", // "quantity": "0.5", // "amount": "5.5", // "feeCurrency": "USDT", // "feeAmount": "0.007975", // "pageId": "32164924331503616", // "clientOrderId": "myOwnId-321" // } // ] // const result = this.parseTrades(response, market, since, limit); return result; } parseOrderStatus(status) { const statuses = { 'NEW': 'open', 'PARTIALLY_FILLED': 'open', 'FILLED': 'closed', 'PENDING_CANCEL': 'canceled', 'PARTIALLY_CANCELED': 'canceled', 'CANCELED': 'canceled', 'FAILED': 'canceled', }; return this.safeString(statuses, status, status); } parseOrder(order, market = undefined) { // // fetchOpenOrder // // { // "id" : "7xxxxxxxxxxxxxxx6", // "clientOrderId" : "", // "symbol" : "ETH_USDT", // "state" : "NEW", // "accountType" : "SPOT", // "side" : "BUY", // "type" : "LIMIT", // "timeInForce" : "GTC", // "quantity" : "0.001", // "price" : "1600", // "avgPrice" : "0", // "amount" : "0", // "filledQuantity" : "0", // "filledAmount" : "0", // "createTime" : 16xxxxxxxxx26, // "updateTime" : 16xxxxxxxxx36 // } // // fetchOpenOrders // // { // "id": "24993088082542592", // "clientOrderId": "", // "symbol": "ELON_USDC", // "state": "NEW", // "accountType": "SPOT", // "side": "SELL", // "type": "MARKET", // "timeInForce": "GTC", // "quantity": "1.00", // "price": "0.00", // "avgPrice": "0.00", // "amount": "0.00", // "filledQuantity": "0.00", // "filledAmount": "0.00", // "createTime": 1646925216548, // "updateTime": 1646925216548 // } // // createOrder, editOrder // // { // "id": "29772698821328896", // "clientOrderId": "1234Abc" // } // let timestamp = this.safeInteger2(order, 'timestamp', 'createTime'); if (timestamp === undefined) { timestamp = this.parse8601(this.safeString(order, 'date')); } const marketId = this.safeString(order, 'symbol'); market = this.safeMarket(marketId,