UNPKG

@madnai/ccxt

Version:

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

1,136 lines (1,078 loc) 6 MB
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ /* A entry point for the browser bundle version. This gets compiled by: browserify --debug ./ccxt.browser.js > ./dist/ccxt.browser.js */ window.ccxt = require ('./ccxt') },{"./ccxt":2}],2:[function(require,module,exports){ "use strict"; /* MIT License Copyright (c) 2017 Igor Kroitor Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ //----------------------------------------------------------------------------- const Exchange = require ('./js/base/Exchange') , functions = require ('./js/base/functions') , errors = require ('./js/base/errors') //----------------------------------------------------------------------------- // this is updated by vss.js when building const version = '1.37.83' Exchange.ccxtVersion = version //----------------------------------------------------------------------------- const exchanges = { 'acx': require ('./js/acx.js'), 'aofex': require ('./js/aofex.js'), 'bcex': require ('./js/bcex.js'), 'bequant': require ('./js/bequant.js'), 'bibox': require ('./js/bibox.js'), 'bigone': require ('./js/bigone.js'), 'binance': require ('./js/binance.js'), 'binanceus': require ('./js/binanceus.js'), 'bit2c': require ('./js/bit2c.js'), 'bitbank': require ('./js/bitbank.js'), 'bitbay': require ('./js/bitbay.js'), 'bitcoincom': require ('./js/bitcoincom.js'), 'bitfinex': require ('./js/bitfinex.js'), 'bitfinex2': require ('./js/bitfinex2.js'), 'bitflyer': require ('./js/bitflyer.js'), 'bitforex': require ('./js/bitforex.js'), 'bitget': require ('./js/bitget.js'), 'bithumb': require ('./js/bithumb.js'), 'bitkk': require ('./js/bitkk.js'), 'bitmart': require ('./js/bitmart.js'), 'bitmax': require ('./js/bitmax.js'), 'bitmex': require ('./js/bitmex.js'), 'bitpanda': require ('./js/bitpanda.js'), 'bitso': require ('./js/bitso.js'), 'bitstamp': require ('./js/bitstamp.js'), 'bitstamp1': require ('./js/bitstamp1.js'), 'bittrex': require ('./js/bittrex.js'), 'bitvavo': require ('./js/bitvavo.js'), 'bitz': require ('./js/bitz.js'), 'bkex': require ('./js/bkex.js'), 'bl3p': require ('./js/bl3p.js'), 'bleutrade': require ('./js/bleutrade.js'), 'braziliex': require ('./js/braziliex.js'), 'btcalpha': require ('./js/btcalpha.js'), 'btcbox': require ('./js/btcbox.js'), 'btcmarkets': require ('./js/btcmarkets.js'), 'btctradeua': require ('./js/btctradeua.js'), 'btcturk': require ('./js/btcturk.js'), 'buda': require ('./js/buda.js'), 'bw': require ('./js/bw.js'), 'bybit': require ('./js/bybit.js'), 'bytetrade': require ('./js/bytetrade.js'), 'cex': require ('./js/cex.js'), 'chilebit': require ('./js/chilebit.js'), 'coinbase': require ('./js/coinbase.js'), 'coinbaseprime': require ('./js/coinbaseprime.js'), 'coinbasepro': require ('./js/coinbasepro.js'), 'coinbene': require ('./js/coinbene.js'), 'coincheck': require ('./js/coincheck.js'), 'coineal': require ('./js/coineal.js'), 'coinegg': require ('./js/coinegg.js'), 'coinex': require ('./js/coinex.js'), 'coinfalcon': require ('./js/coinfalcon.js'), 'coinfloor': require ('./js/coinfloor.js'), 'coingi': require ('./js/coingi.js'), 'coinmarketcap': require ('./js/coinmarketcap.js'), 'coinmate': require ('./js/coinmate.js'), 'coinone': require ('./js/coinone.js'), 'coinspot': require ('./js/coinspot.js'), 'coss': require ('./js/coss.js'), 'crex24': require ('./js/crex24.js'), 'currencycom': require ('./js/currencycom.js'), 'deribit': require ('./js/deribit.js'), 'digifinex': require ('./js/digifinex.js'), 'dsx': require ('./js/dsx.js'), 'eterbase': require ('./js/eterbase.js'), 'exmo': require ('./js/exmo.js'), 'exx': require ('./js/exx.js'), 'fcoin': require ('./js/fcoin.js'), 'fcoinjp': require ('./js/fcoinjp.js'), 'flowbtc': require ('./js/flowbtc.js'), 'foxbit': require ('./js/foxbit.js'), 'ftx': require ('./js/ftx.js'), 'gateio': require ('./js/gateio.js'), 'gemini': require ('./js/gemini.js'), 'hbtc': require ('./js/hbtc.js'), 'hitbtc': require ('./js/hitbtc.js'), 'hollaex': require ('./js/hollaex.js'), 'hotbit': require ('./js/hotbit.js'), 'huobijp': require ('./js/huobijp.js'), 'huobipro': require ('./js/huobipro.js'), 'huobiru': require ('./js/huobiru.js'), 'ice3x': require ('./js/ice3x.js'), 'idex': require ('./js/idex.js'), 'independentreserve': require ('./js/independentreserve.js'), 'indodax': require ('./js/indodax.js'), 'itbit': require ('./js/itbit.js'), 'kraken': require ('./js/kraken.js'), 'kucoin': require ('./js/kucoin.js'), 'kuna': require ('./js/kuna.js'), 'lakebtc': require ('./js/lakebtc.js'), 'latoken': require ('./js/latoken.js'), 'lbank': require ('./js/lbank.js'), 'liquid': require ('./js/liquid.js'), 'livecoin': require ('./js/livecoin.js'), 'luno': require ('./js/luno.js'), 'lykke': require ('./js/lykke.js'), 'mercado': require ('./js/mercado.js'), 'mixcoins': require ('./js/mixcoins.js'), 'mxc': require ('./js/mxc.js'), 'novadax': require ('./js/novadax.js'), 'oceanex': require ('./js/oceanex.js'), 'okcoin': require ('./js/okcoin.js'), 'okex': require ('./js/okex.js'), 'paymium': require ('./js/paymium.js'), 'phemex': require ('./js/phemex.js'), 'poloniex': require ('./js/poloniex.js'), 'probit': require ('./js/probit.js'), 'qtrade': require ('./js/qtrade.js'), 'rightbtc': require ('./js/rightbtc.js'), 'ripio': require ('./js/ripio.js'), 'southxchange': require ('./js/southxchange.js'), 'stex': require ('./js/stex.js'), 'surbitcoin': require ('./js/surbitcoin.js'), 'therock': require ('./js/therock.js'), 'tidebit': require ('./js/tidebit.js'), 'tidex': require ('./js/tidex.js'), 'timex': require ('./js/timex.js'), 'upbit': require ('./js/upbit.js'), 'vaultoro': require ('./js/vaultoro.js'), 'vbtc': require ('./js/vbtc.js'), 'wavesexchange': require ('./js/wavesexchange.js'), 'wbf': require ('./js/wbf.js'), 'whitebit': require ('./js/whitebit.js'), 'xbtce': require ('./js/xbtce.js'), 'xena': require ('./js/xena.js'), 'yobit': require ('./js/yobit.js'), 'zaif': require ('./js/zaif.js'), 'zb': require ('./js/zb.js'), } //----------------------------------------------------------------------------- module.exports = Object.assign ({ version, Exchange, 'exchanges': Object.keys (exchanges) }, exchanges, functions, errors) //----------------------------------------------------------------------------- },{"./js/acx.js":3,"./js/aofex.js":4,"./js/base/Exchange":5,"./js/base/errors":7,"./js/base/functions":8,"./js/bcex.js":19,"./js/bequant.js":20,"./js/bibox.js":21,"./js/bigone.js":22,"./js/binance.js":23,"./js/binanceus.js":24,"./js/bit2c.js":25,"./js/bitbank.js":26,"./js/bitbay.js":27,"./js/bitcoincom.js":28,"./js/bitfinex.js":29,"./js/bitfinex2.js":30,"./js/bitflyer.js":31,"./js/bitforex.js":32,"./js/bitget.js":33,"./js/bithumb.js":34,"./js/bitkk.js":35,"./js/bitmart.js":36,"./js/bitmax.js":37,"./js/bitmex.js":38,"./js/bitpanda.js":39,"./js/bitso.js":40,"./js/bitstamp.js":41,"./js/bitstamp1.js":42,"./js/bittrex.js":43,"./js/bitvavo.js":44,"./js/bitz.js":45,"./js/bkex.js":46,"./js/bl3p.js":47,"./js/bleutrade.js":48,"./js/braziliex.js":49,"./js/btcalpha.js":50,"./js/btcbox.js":51,"./js/btcmarkets.js":52,"./js/btctradeua.js":53,"./js/btcturk.js":54,"./js/buda.js":55,"./js/bw.js":56,"./js/bybit.js":57,"./js/bytetrade.js":58,"./js/cex.js":59,"./js/chilebit.js":60,"./js/coinbase.js":61,"./js/coinbaseprime.js":62,"./js/coinbasepro.js":63,"./js/coinbene.js":64,"./js/coincheck.js":65,"./js/coineal.js":66,"./js/coinegg.js":67,"./js/coinex.js":68,"./js/coinfalcon.js":69,"./js/coinfloor.js":70,"./js/coingi.js":71,"./js/coinmarketcap.js":72,"./js/coinmate.js":73,"./js/coinone.js":74,"./js/coinspot.js":75,"./js/coss.js":76,"./js/crex24.js":77,"./js/currencycom.js":78,"./js/deribit.js":79,"./js/digifinex.js":80,"./js/dsx.js":81,"./js/eterbase.js":82,"./js/exmo.js":83,"./js/exx.js":84,"./js/fcoin.js":85,"./js/fcoinjp.js":86,"./js/flowbtc.js":87,"./js/foxbit.js":88,"./js/ftx.js":89,"./js/gateio.js":90,"./js/gemini.js":91,"./js/hbtc.js":92,"./js/hitbtc.js":93,"./js/hollaex.js":94,"./js/hotbit.js":95,"./js/huobijp.js":96,"./js/huobipro.js":97,"./js/huobiru.js":98,"./js/ice3x.js":99,"./js/idex.js":100,"./js/independentreserve.js":101,"./js/indodax.js":102,"./js/itbit.js":103,"./js/kraken.js":104,"./js/kucoin.js":105,"./js/kuna.js":106,"./js/lakebtc.js":107,"./js/latoken.js":108,"./js/lbank.js":109,"./js/liquid.js":110,"./js/livecoin.js":111,"./js/luno.js":112,"./js/lykke.js":113,"./js/mercado.js":114,"./js/mixcoins.js":115,"./js/mxc.js":116,"./js/novadax.js":117,"./js/oceanex.js":118,"./js/okcoin.js":119,"./js/okex.js":120,"./js/paymium.js":121,"./js/phemex.js":122,"./js/poloniex.js":123,"./js/probit.js":124,"./js/qtrade.js":125,"./js/rightbtc.js":126,"./js/ripio.js":127,"./js/southxchange.js":128,"./js/stex.js":169,"./js/surbitcoin.js":170,"./js/therock.js":171,"./js/tidebit.js":172,"./js/tidex.js":173,"./js/timex.js":174,"./js/upbit.js":175,"./js/vaultoro.js":176,"./js/vbtc.js":177,"./js/wavesexchange.js":178,"./js/wbf.js":179,"./js/whitebit.js":180,"./js/xbtce.js":181,"./js/xena.js":182,"./js/yobit.js":183,"./js/zaif.js":184,"./js/zb.js":185}],3:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { InsufficientFunds, OrderNotFound } = require ('./base/errors'); // --------------------------------------------------------------------------- module.exports = class acx extends Exchange { describe () { return this.deepExtend (super.describe (), { 'id': 'acx', 'name': 'ACX', 'countries': [ 'AU' ], 'rateLimit': 1000, 'version': 'v2', 'has': { 'cancelOrder': true, 'CORS': true, 'createOrder': true, 'fetchBalance': true, 'fetchMarkets': true, 'fetchOHLCV': true, 'fetchOrder': true, 'fetchOrderBook': true, 'fetchTicker': true, 'fetchTickers': true, 'fetchTime': true, 'fetchTrades': true, 'withdraw': true, }, 'timeframes': { '1m': '1', '5m': '5', '15m': '15', '30m': '30', '1h': '60', '2h': '120', '4h': '240', '12h': '720', '1d': '1440', '3d': '4320', '1w': '10080', }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/1294454/30247614-1fe61c74-9621-11e7-9e8c-f1a627afa279.jpg', 'extension': '.json', 'api': 'https://acx.io/api', 'www': 'https://acx.io', 'doc': 'https://acx.io/documents/api_v2', }, 'api': { 'public': { 'get': [ 'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest. 'k_with_pending_trades', // Get K data with pending trades, which are the trades not included in K data yet, because there's delay between trade generated and processed by K data generator 'k', // Get OHLC(k line) of specific market 'markets', // Get all available markets 'order_book', // Get the order book of specified market 'order_book/{market}', 'tickers', // Get ticker of all markets 'tickers/{market}', // Get ticker of specific market 'timestamp', // Get server current time, in seconds since Unix epoch 'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order. 'trades/{market}', ], }, 'private': { 'get': [ 'members/me', // Get your profile and accounts info 'deposits', // Get your deposits history 'deposit', // Get details of specific deposit 'deposit_address', // Where to deposit The address field could be empty when a new address is generating (e.g. for bitcoin), you should try again later in that case. 'orders', // Get your orders, results is paginated 'order', // Get information of specified order 'trades/my', // Get your executed trades Trades are sorted in reverse creation order. 'withdraws', // Get your cryptocurrency withdraws 'withdraw', // Get your cryptocurrency withdraw ], 'post': [ 'orders', // Create a Sell/Buy order 'orders/multi', // Create multiple sell/buy orders 'orders/clear', // Cancel all my orders 'order/delete', // Cancel an order 'withdraw', // Create a withdraw ], }, }, 'fees': { 'trading': { 'tierBased': false, 'percentage': true, 'maker': 0.2 / 100, 'taker': 0.2 / 100, }, 'funding': { 'tierBased': false, 'percentage': true, 'withdraw': {}, // There is only 1% fee on withdrawals to your bank account. }, }, 'commonCurrencies': { 'PLA': 'Plair', }, 'exceptions': { '2002': InsufficientFunds, '2003': OrderNotFound, }, }); } async fetchMarkets (params = {}) { const markets = await this.publicGetMarkets (params); const result = []; for (let i = 0; i < markets.length; i++) { const market = markets[i]; const id = market['id']; const symbol = market['name']; let baseId = this.safeString (market, 'base_unit'); let quoteId = this.safeString (market, 'quote_unit'); if ((baseId === undefined) || (quoteId === undefined)) { const ids = symbol.split ('/'); baseId = ids[0].toLowerCase (); quoteId = ids[1].toLowerCase (); } let base = baseId.toUpperCase (); let quote = quoteId.toUpperCase (); base = this.safeCurrencyCode (base); quote = this.safeCurrencyCode (quote); // todo: find out their undocumented precision and limits const precision = { 'amount': 8, 'price': 8, }; result.push ({ 'id': id, 'symbol': symbol, 'base': base, 'quote': quote, 'baseId': baseId, 'quoteId': quoteId, 'precision': precision, 'info': market, 'active': undefined, 'limits': this.limits, }); } return result; } async fetchBalance (params = {}) { await this.loadMarkets (); const response = await this.privateGetMembersMe (params); const balances = this.safeValue (response, 'accounts'); const result = { 'info': balances }; for (let i = 0; i < balances.length; i++) { const balance = balances[i]; const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); account['free'] = this.safeFloat (balance, 'balance'); account['used'] = this.safeFloat (balance, 'locked'); result[code] = account; } return this.parseBalance (result); } async fetchOrderBook (symbol, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'market': market['id'], }; if (limit !== undefined) { request['limit'] = limit; // default = 300 } const orderbook = await this.publicGetDepth (this.extend (request, params)); const timestamp = this.safeTimestamp (orderbook, 'timestamp'); return this.parseOrderBook (orderbook, timestamp); } parseTicker (ticker, market = undefined) { const timestamp = this.safeTimestamp (ticker, 'at'); ticker = ticker['ticker']; let symbol = undefined; if (market) { symbol = market['symbol']; } const last = this.safeFloat (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': this.safeFloat (ticker, 'high'), 'low': this.safeFloat (ticker, 'low'), 'bid': this.safeFloat (ticker, 'buy'), 'bidVolume': undefined, 'ask': this.safeFloat (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': this.safeFloat (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, 'baseVolume': this.safeFloat (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; } async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTickers (params); const ids = Object.keys (response); const result = {}; for (let i = 0; i < ids.length; i++) { const id = ids[i]; let market = undefined; let symbol = id; if (id in this.markets_by_id) { market = this.markets_by_id[id]; symbol = market['symbol']; } else { let base = id.slice (0, 3); let quote = id.slice (3, 6); base = base.toUpperCase (); quote = quote.toUpperCase (); base = this.safeCurrencyCode (base); quote = this.safeCurrencyCode (quote); symbol = base + '/' + quote; } result[symbol] = this.parseTicker (response[id], market); } return this.filterByArray (result, 'symbol', symbols); } async fetchTicker (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'market': market['id'], }; const response = await this.publicGetTickersMarket (this.extend (request, params)); return this.parseTicker (response, market); } parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); const id = this.safeString (trade, 'tid'); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } return { 'info': trade, 'id': id, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'symbol': symbol, 'type': undefined, 'side': undefined, 'order': undefined, 'takerOrMaker': undefined, 'price': this.safeFloat (trade, 'price'), 'amount': this.safeFloat (trade, 'volume'), 'cost': this.safeFloat (trade, 'funds'), 'fee': undefined, }; } async fetchTime (params = {}) { const response = await this.publicGetTimestamp (params); // // 1594911427 // return response * 1000; } async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'market': market['id'], }; const response = await this.publicGetTrades (this.extend (request, params)); return this.parseTrades (response, market, since, limit); } parseOHLCV (ohlcv, market = undefined) { return [ this.safeTimestamp (ohlcv, 0), this.safeFloat (ohlcv, 1), this.safeFloat (ohlcv, 2), this.safeFloat (ohlcv, 3), this.safeFloat (ohlcv, 4), this.safeFloat (ohlcv, 5), ]; } async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); if (limit === undefined) { limit = 500; // default is 30 } const request = { 'market': market['id'], 'period': this.timeframes[timeframe], 'limit': limit, }; if (since !== undefined) { request['timestamp'] = parseInt (since / 1000); } const response = await this.publicGetK (this.extend (request, params)); return this.parseOHLCVs (response, market, timeframe, since, limit); } parseOrderStatus (status) { const statuses = { 'done': 'closed', 'wait': 'open', 'cancel': 'canceled', }; return this.safeString (statuses, status, status); } parseOrder (order, market = undefined) { const marketId = this.safeString (order, 'market'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const status = this.parseOrderStatus (this.safeString (order, 'state')); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); const id = this.safeString (order, 'id'); return { 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'lastTradeTimestamp': undefined, 'status': status, 'symbol': symbol, 'type': type, 'side': side, 'price': this.safeFloat (order, 'price'), 'amount': this.safeFloat (order, 'volume'), 'filled': this.safeFloat (order, 'executed_volume'), 'remaining': this.safeFloat (order, 'remaining_volume'), 'trades': undefined, 'fee': undefined, 'info': order, 'cost': undefined, 'average': undefined, }; } async fetchOrder (id, symbol = undefined, params = {}) { await this.loadMarkets (); const request = { 'id': parseInt (id), }; const response = await this.privateGetOrder (this.extend (request, params)); return this.parseOrder (response); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { await this.loadMarkets (); const request = { 'market': this.marketId (symbol), 'side': side, 'volume': amount.toString (), 'ord_type': type, }; if (type === 'limit') { request['price'] = price.toString (); } const response = await this.privatePostOrders (this.extend (request, params)); const marketId = this.safeValue (response, 'market'); const market = this.safeValue (this.markets_by_id, marketId); return this.parseOrder (response, market); } async cancelOrder (id, symbol = undefined, params = {}) { await this.loadMarkets (); const request = { 'id': id, }; const response = await this.privatePostOrderDelete (this.extend (request, params)); const order = this.parseOrder (response); const status = order['status']; if (status === 'closed' || status === 'canceled') { throw new OrderNotFound (this.id + ' ' + this.json (order)); } return order; } async withdraw (code, amount, address, tag = undefined, params = {}) { this.checkAddress (address); await this.loadMarkets (); const currency = this.currency (code); // they have XRP but no docs on memo/tag const request = { 'currency': currency['id'], 'sum': amount, 'address': address, }; const response = await this.privatePostWithdraw (this.extend (request, params)); // withdrawal response is undocumented return { 'info': response, 'id': undefined, }; } nonce () { return this.milliseconds (); } encodeParams (params) { if ('orders' in params) { const orders = params['orders']; let query = this.urlencode (this.keysort (this.omit (params, 'orders'))); for (let i = 0; i < orders.length; i++) { const order = orders[i]; const keys = Object.keys (order); for (let k = 0; k < keys.length; k++) { const key = keys[k]; const value = order[key]; query += '&orders%5B%5D%5B' + key + '%5D=' + value.toString (); } } return query; } return this.urlencode (this.keysort (params)); } sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { let request = '/api/' + this.version + '/' + this.implodeParams (path, params); if ('extension' in this.urls) { request += this.urls['extension']; } const query = this.omit (params, this.extractParams (path)); let url = this.urls['api'] + request; if (api === 'public') { if (Object.keys (query).length) { url += '?' + this.urlencode (query); } } else { this.checkRequiredCredentials (); const nonce = this.nonce ().toString (); const query = this.encodeParams (this.extend ({ 'access_key': this.apiKey, 'tonce': nonce, }, params)); const auth = method + '|' + request + '|' + query; const signed = this.hmac (this.encode (auth), this.encode (this.secret)); const suffix = query + '&signature=' + signed; if (method === 'GET') { url += '?' + suffix; } else { body = suffix; headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; } } return { 'url': url, 'method': method, 'body': body, 'headers': headers }; } handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) { if (response === undefined) { return; } if (code === 400) { const error = this.safeValue (response, 'error'); const errorCode = this.safeString (error, 'code'); const feedback = this.id + ' ' + this.json (response); this.throwExactlyMatchedException (this.exceptions, errorCode, feedback); // fallback to default error handler } } }; },{"./base/Exchange":5,"./base/errors":7}],4:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, ExchangeError, BadSymbol, InvalidOrder, PermissionDenied, InvalidAddress, AuthenticationError, InvalidNonce, BadRequest, InsufficientFunds, OrderNotFound } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); // --------------------------------------------------------------------------- module.exports = class aofex extends Exchange { describe () { return this.deepExtend (super.describe (), { 'id': 'aofex', 'name': 'AOFEX', 'countries': [ 'GB' ], 'rateLimit': 1000, 'has': { 'fetchMarkets': true, 'fetchCurrencies': false, 'fetchOrderBook': true, 'fetchTrades': true, 'fetchTicker': true, 'fetchTickers': true, 'fetchOHLCV': true, 'fetchBalance': true, 'createOrder': true, 'cancelOrder': true, 'cancelAllOrders': true, 'fetchOpenOrders': true, 'fetchClosedOrders': true, 'fetchClosedOrder': true, 'fetchOrderTrades': true, 'fetchTradingFee': true, }, 'timeframes': { '1m': '1min', '5m': '5min', '15m': '15min', '30m': '30min', '1h': '1hour', '6h': '6hour', '12h': '12hour', '1d': '1day', '1w': '1week', }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/51840849/77670271-056d1080-6f97-11ea-9ac2-4268e9ed0c1f.jpg', 'api': { 'public': 'https://openapi.aofex.com/openApi', 'private': 'https://openapi.aofex.com/openApi', }, 'www': 'https://aofex.com', 'doc': 'https://aofex.zendesk.com/hc/en-us/sections/360005576574-API', 'fees': 'https://aofex.zendesk.com/hc/en-us/articles/360025814934-Fees-on-AOFEX', 'referral': 'https://aofex.com/#/register?key=9763840', }, 'api': { 'public': { 'get': [ 'market/symbols', 'market/trade', 'market/depth', 'market/kline', 'market/precision', 'market/24kline', 'market/gears_depth', 'market/detail', ], }, 'private': { 'get': [ 'entrust/currentList', 'entrust/historyList', 'entrust/rate', 'wallet/list', 'entrust/detail', ], 'post': [ 'entrust/add', 'entrust/cancel', ], }, }, 'fees': { 'trading': { 'maker': 0.0019, 'taker': 0.002, }, }, 'exceptions': { 'exact': { '20001': ExchangeError, // request failure '20401': PermissionDenied, // no permission '20500': ExchangeError, // system error '20501': BadSymbol, // base symbol error '20502': ExchangeError, // base currency error '20503': ExchangeError, // base date error '20504': InsufficientFunds, // account frozen balance insufficient error '20505': BadRequest, // bad argument '20506': AuthenticationError, // api signature not valid '20507': ExchangeError, // gateway internal error '20508': InvalidAddress, // ad ethereum addresss '20509': InsufficientFunds, // order accountbalance error '20510': InvalidOrder, // order limitorder price error '20511': InvalidOrder, // order limitorder amount error '20512': InvalidOrder, // order orderprice precision error '20513': InvalidOrder, // order orderamount precision error '20514': InvalidOrder, // order marketorder amount error '20515': InvalidOrder, // order queryorder invalid '20516': InvalidOrder, // order orderstate error '20517': InvalidOrder, // order datelimit error '50518': InvalidOrder, // order update error '20519': InvalidNonce, // the nonce has been used '20520': InvalidNonce, // nonce expires, please verify server time '20521': BadRequest, // incomplete header parameters '20522': ExchangeError, // not getting the current user '20523': AuthenticationError, // please authenticate '20524': PermissionDenied, // btc account lockout '20525': AuthenticationError, // get API Key error '20526': PermissionDenied, // no query permission '20527': PermissionDenied, // no deal permission '20528': PermissionDenied, // no withdrawal permission '20529': AuthenticationError, // API Key expired '20530': PermissionDenied, // no permission }, 'broad': { }, }, 'options': { 'fetchBalance': { 'show_all': '0', // '1' to show zero balances }, }, }); } async fetchMarkets (params = {}) { let markets = await this.publicGetMarketSymbols (params); // // { // errno: 0, // errmsg: 'success', // result: [ // { // id: 2, // symbol: 'BTC-USDT', // base_currency: 'BTC', // quote_currency: 'USDT', // min_size: 0.00008, // max_size: 1300, // min_price: 1000, // max_price: 110000, // maker_fee: 1, // taker_fee: 1, // isHot: null, // isNew: null, // crown: null // }, // ] // } // let precisions = await this.publicGetMarketPrecision (); // // { // errno: 0, // errmsg: 'success', // result: { // 'MANA-USDT': { // amount: '2', // minQuantity: '32', // maxQuantity: '46000000', // price: '4', // minPrice: '0.003', // maxPrice: '0.35' // }, // } // } // precisions = this.safeValue (precisions, 'result', {}); markets = this.safeValue (markets, 'result', []); const result = []; for (let i = 0; i < markets.length; i++) { const market = markets[i]; const id = this.safeString (market, 'symbol'); const baseId = this.safeString (market, 'base_currency'); const quoteId = this.safeString (market, 'quote_currency'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const numericId = this.safeInteger (market, 'id'); const precision = this.safeValue (precisions, id, {}); const makerFee = this.safeFloat (market, 'maker_fee'); const takerFee = this.safeFloat (market, 'taker_fee'); result.push ({ 'id': id, 'numericId': numericId, 'symbol': symbol, 'baseId': baseId, 'quoteId': quoteId, 'base': base, 'quote': quote, 'active': undefined, 'maker': makerFee / 1000, 'taker': takerFee / 1000, 'precision': { 'amount': this.safeInteger (precision, 'amount'), 'price': this.safeInteger (precision, 'price'), }, 'limits': { 'amount': { 'min': this.safeFloat (market, 'min_size'), 'max': this.safeFloat (market, 'max_size'), }, 'price': { 'min': this.safeFloat (market, 'min_price'), 'max': this.safeFloat (market, 'max_price'), }, 'cost': { 'min': undefined, 'max': undefined, }, }, 'info': market, }); } return result; } parseOHLCV (ohlcv, market = undefined) { // // { // id: 1584950100, // amount: "329.196", // count: 81, // open: "0.021155", // close: "0.021158", // low: "0.021144", // high: "0.021161", // vol: "6.963557767" // } // return [ this.safeTimestamp (ohlcv, 'id'), this.safeFloat (ohlcv, 'open'), this.safeFloat (ohlcv, 'high'), this.safeFloat (ohlcv, 'low'), this.safeFloat (ohlcv, 'close'), this.safeFloat (ohlcv, 'amount'), ]; } async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); if (limit === undefined) { limit = 150; // default 150, max 2000 } const request = { 'symbol': market['id'], 'period': this.timeframes[timeframe], 'size': limit, // default 150, max 2000 }; const response = await this.publicGetMarketKline (this.extend (request, params)); // // { // errno: 0, // errmsg: "success", // result: { // ts: 1584950139003, // symbol: "ETH-BTC", // period: "1min", // data: [ // { // id: 1584950100, // amount: "329.196", // count: 81, // open: "0.021155", // close: "0.021158", // low: "0.021144", // high: "0.021161", // vol: "6.963557767" // }, // { // id: 1584950040, // amount: "513.265", // count: 151, // open: "0.021165", // close: "0.021155", // low: "0.021151", // high: "0.02118", // vol: "10.862806573" // }, // ] // } // } // const result = this.safeValue (response, 'result', {}); const data = this.safeValue (result, 'data', []); return this.parseOHLCVs (data, market, since, limit); } async fetchBalance (params = {}) { await this.loadMarkets (); const options = this.safeValue (this.options, 'fetchBalance', {}); const showAll = this.safeValue (options, 'show_all', '0'); const request = { // 'currency': 'BTC', 'show_all': showAll, // required to show zero balances }; const response = await this.privateGetWalletList (this.extend (request, params)); // // { // "errno": 0, // "errmsg": "success", // "result": [ // { "available": "0", "frozen": "0", "currency": "BTC" } // ] // } // const result = { 'info': response }; const balances = this.safeValue (response, 'result', []); for (let i = 0; i < balances.length; i++) { const balance = balances[i]; const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); account['free'] = this.safeFloat (balance, 'available'); account['used'] = this.safeFloat (balance, 'frozen'); result[code] = account; } return this.parseBalance (result); } async fetchTradingFee (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'symbol': market['id'], }; const response = await this.privateGetEntrustRate (this.extend (request, params)); // // { // "errno":0, // "errmsg":"success", // "result": { // "toFee":"0.002","fromFee":"0.002" // } // } // const result = this.safeValue (response, 'result', {}); return { 'info': response, 'symbol': symbol, 'maker': this.safeFloat (result, 'fromFee'), 'taker': this.safeFloat (result, 'toFee'), }; } async fetchOrderBook (symbol, limit = undefined, params = {}) { await this.loadMarkets (); const request = { 'symbol': this.marketId (symbol), }; const response = await this.publicGetMarketDepth (this.extend (request, params)); // // { // errno: 0, // errmsg: "success", // result: { // buyType: 1, // sellType: 1, // ts: 1584950701050, // symbol: "ETH-BTC", // asks: [ // ["0.021227", "0.182"], // ["0.021249", "0.035"], // ["0.021253", "0.058"], // ], // bids: [ // ["0.021207", "0.039"], // ["0.021203", "0.051"], // ["0.02117", "2.326"], // ] // } // } // const result = this.safeValue (response, 'result', {}); const timestamp = this.safeInteger (result, 'ts'); return this.parseOrderBook (result, timestamp); } parseTicker (ticker, market = undefined) { // // fetchTicker // // { // id: 1584890087, // amount: '150032.919', // count: 134538, // open: '0.021394', // close: '0.021177', // low: '0.021053', // high: '0.021595', // vol: '3201.72451442' // } // const timestamp = this.safeTimestamp (ticker, 'id'); let symbol = undefined; if (market) { symbol = market['symbol']; } const open = this.safeFloat (ticker, 'open'); const last = this.safeFloat (ticker, 'close'); let change = undefined; if (symbol !== undefined) { change = parseFloat (this.priceToPrecision (symbol, last - open)); } else { change = last - open; } const average = this.sum (last, open) / 2; const percentage = change / open * 100; const baseVolume = this.safeFloat (ticker, 'amount'); const quoteVolume = this.safeFloat (ticker, 'vol'); let vwap = this.vwap (baseVolume, quoteVolume); if (vwap !== undefined) { vwap = parseFloat (this.priceToPrecision (symbol, vwap)); } return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': this.safeFloat (ticker, 'high'), 'low': this.safeFloat (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, 'vwap': vwap, 'open': open, 'close': last, 'last': last, 'previousClose': undefined, 'change': change, 'percentage': percentage, 'average': average, 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, 'info': ticker, }; } async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const request = {}; if (symbols !== undefined) { const ids = this.marketIds (symbols); request['symbol'] = ids.join (','); } const response = await this.publicGetMarket24kline (this.extend (request, par