UNPKG

@jmparsons/ccxt

Version:

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

1,142 lines (1,061 loc) 4.95 MB
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ /* A entry point for the browser bundle version. This gets compiled by: browserify --debug ./ccxt.browser.js > ./build/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. */ "use strict"; //----------------------------------------------------------------------------- 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.14.10' Exchange.ccxtVersion = version //----------------------------------------------------------------------------- const exchanges = { '_1broker': require ('./js/_1broker.js'), '_1btcxe': require ('./js/_1btcxe.js'), 'acx': require ('./js/acx.js'), 'allcoin': require ('./js/allcoin.js'), 'anxpro': require ('./js/anxpro.js'), 'bibox': require ('./js/bibox.js'), 'binance': require ('./js/binance.js'), 'bit2c': require ('./js/bit2c.js'), 'bitbank': require ('./js/bitbank.js'), 'bitbay': require ('./js/bitbay.js'), 'bitfinex': require ('./js/bitfinex.js'), 'bitfinex2': require ('./js/bitfinex2.js'), 'bitflyer': require ('./js/bitflyer.js'), 'bithumb': require ('./js/bithumb.js'), 'bitkk': require ('./js/bitkk.js'), 'bitlish': require ('./js/bitlish.js'), 'bitmarket': require ('./js/bitmarket.js'), 'bitmex': require ('./js/bitmex.js'), 'bitso': require ('./js/bitso.js'), 'bitstamp': require ('./js/bitstamp.js'), 'bitstamp1': require ('./js/bitstamp1.js'), 'bittrex': require ('./js/bittrex.js'), 'bitz': require ('./js/bitz.js'), 'bl3p': require ('./js/bl3p.js'), 'bleutrade': require ('./js/bleutrade.js'), 'braziliex': require ('./js/braziliex.js'), 'btcbox': require ('./js/btcbox.js'), 'btcchina': require ('./js/btcchina.js'), 'btcexchange': require ('./js/btcexchange.js'), 'btcmarkets': require ('./js/btcmarkets.js'), 'btctradeim': require ('./js/btctradeim.js'), 'btctradeua': require ('./js/btctradeua.js'), 'btcturk': require ('./js/btcturk.js'), 'btcx': require ('./js/btcx.js'), 'bxinth': require ('./js/bxinth.js'), 'ccex': require ('./js/ccex.js'), 'cex': require ('./js/cex.js'), 'chbtc': require ('./js/chbtc.js'), 'chilebit': require ('./js/chilebit.js'), 'cobinhood': require ('./js/cobinhood.js'), 'coincheck': require ('./js/coincheck.js'), 'coinegg': require ('./js/coinegg.js'), 'coinex': require ('./js/coinex.js'), 'coinexchange': require ('./js/coinexchange.js'), 'coinfloor': require ('./js/coinfloor.js'), 'coingi': require ('./js/coingi.js'), 'coinmarketcap': require ('./js/coinmarketcap.js'), 'coinmate': require ('./js/coinmate.js'), 'coinnest': require ('./js/coinnest.js'), 'coinone': require ('./js/coinone.js'), 'coinsecure': require ('./js/coinsecure.js'), 'coinspot': require ('./js/coinspot.js'), 'cointiger': require ('./js/cointiger.js'), 'coolcoin': require ('./js/coolcoin.js'), 'cryptopia': require ('./js/cryptopia.js'), 'dsx': require ('./js/dsx.js'), 'ethfinex': require ('./js/ethfinex.js'), 'exmo': require ('./js/exmo.js'), 'exx': require ('./js/exx.js'), 'flowbtc': require ('./js/flowbtc.js'), 'foxbit': require ('./js/foxbit.js'), 'fybse': require ('./js/fybse.js'), 'fybsg': require ('./js/fybsg.js'), 'gatecoin': require ('./js/gatecoin.js'), 'gateio': require ('./js/gateio.js'), 'gdax': require ('./js/gdax.js'), 'gemini': require ('./js/gemini.js'), 'getbtc': require ('./js/getbtc.js'), 'hadax': require ('./js/hadax.js'), 'hitbtc': require ('./js/hitbtc.js'), 'hitbtc2': require ('./js/hitbtc2.js'), 'huobi': require ('./js/huobi.js'), 'huobicny': require ('./js/huobicny.js'), 'huobipro': require ('./js/huobipro.js'), 'ice3x': require ('./js/ice3x.js'), 'independentreserve': require ('./js/independentreserve.js'), 'indodax': require ('./js/indodax.js'), 'itbit': require ('./js/itbit.js'), 'jubi': require ('./js/jubi.js'), 'kraken': require ('./js/kraken.js'), 'kucoin': require ('./js/kucoin.js'), 'kuna': require ('./js/kuna.js'), 'lakebtc': require ('./js/lakebtc.js'), 'lbank': require ('./js/lbank.js'), 'liqui': require ('./js/liqui.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'), 'negociecoins': require ('./js/negociecoins.js'), 'nova': require ('./js/nova.js'), 'okcoincny': require ('./js/okcoincny.js'), 'okcoinusd': require ('./js/okcoinusd.js'), 'okex': require ('./js/okex.js'), 'paymium': require ('./js/paymium.js'), 'poloniex': require ('./js/poloniex.js'), 'qryptos': require ('./js/qryptos.js'), 'quadrigacx': require ('./js/quadrigacx.js'), 'quoinex': require ('./js/quoinex.js'), 'southxchange': require ('./js/southxchange.js'), 'surbitcoin': require ('./js/surbitcoin.js'), 'therock': require ('./js/therock.js'), 'tidebit': require ('./js/tidebit.js'), 'tidex': require ('./js/tidex.js'), 'urdubit': require ('./js/urdubit.js'), 'vaultoro': require ('./js/vaultoro.js'), 'vbtc': require ('./js/vbtc.js'), 'virwox': require ('./js/virwox.js'), 'wex': require ('./js/wex.js'), 'xbtce': require ('./js/xbtce.js'), 'yobit': require ('./js/yobit.js'), 'yunbi': require ('./js/yunbi.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/_1broker.js":3,"./js/_1btcxe.js":4,"./js/acx.js":5,"./js/allcoin.js":6,"./js/anxpro.js":7,"./js/base/Exchange":8,"./js/base/errors":10,"./js/base/functions":11,"./js/bibox.js":22,"./js/binance.js":23,"./js/bit2c.js":24,"./js/bitbank.js":25,"./js/bitbay.js":26,"./js/bitfinex.js":27,"./js/bitfinex2.js":28,"./js/bitflyer.js":29,"./js/bithumb.js":30,"./js/bitkk.js":31,"./js/bitlish.js":32,"./js/bitmarket.js":33,"./js/bitmex.js":34,"./js/bitso.js":35,"./js/bitstamp.js":36,"./js/bitstamp1.js":37,"./js/bittrex.js":38,"./js/bitz.js":39,"./js/bl3p.js":40,"./js/bleutrade.js":41,"./js/braziliex.js":42,"./js/btcbox.js":43,"./js/btcchina.js":44,"./js/btcexchange.js":45,"./js/btcmarkets.js":46,"./js/btctradeim.js":47,"./js/btctradeua.js":48,"./js/btcturk.js":49,"./js/btcx.js":50,"./js/bxinth.js":51,"./js/ccex.js":52,"./js/cex.js":53,"./js/chbtc.js":54,"./js/chilebit.js":55,"./js/cobinhood.js":56,"./js/coincheck.js":57,"./js/coinegg.js":58,"./js/coinex.js":59,"./js/coinexchange.js":60,"./js/coinfloor.js":61,"./js/coingi.js":62,"./js/coinmarketcap.js":63,"./js/coinmate.js":64,"./js/coinnest.js":65,"./js/coinone.js":66,"./js/coinsecure.js":67,"./js/coinspot.js":68,"./js/cointiger.js":69,"./js/coolcoin.js":70,"./js/cryptopia.js":71,"./js/dsx.js":72,"./js/ethfinex.js":73,"./js/exmo.js":74,"./js/exx.js":75,"./js/flowbtc.js":76,"./js/foxbit.js":77,"./js/fybse.js":78,"./js/fybsg.js":79,"./js/gatecoin.js":80,"./js/gateio.js":81,"./js/gdax.js":82,"./js/gemini.js":83,"./js/getbtc.js":84,"./js/hadax.js":85,"./js/hitbtc.js":86,"./js/hitbtc2.js":87,"./js/huobi.js":88,"./js/huobicny.js":89,"./js/huobipro.js":90,"./js/ice3x.js":91,"./js/independentreserve.js":92,"./js/indodax.js":93,"./js/itbit.js":94,"./js/jubi.js":95,"./js/kraken.js":96,"./js/kucoin.js":97,"./js/kuna.js":98,"./js/lakebtc.js":99,"./js/lbank.js":100,"./js/liqui.js":101,"./js/livecoin.js":102,"./js/luno.js":103,"./js/lykke.js":104,"./js/mercado.js":105,"./js/mixcoins.js":106,"./js/negociecoins.js":107,"./js/nova.js":108,"./js/okcoincny.js":109,"./js/okcoinusd.js":110,"./js/okex.js":111,"./js/paymium.js":112,"./js/poloniex.js":113,"./js/qryptos.js":114,"./js/quadrigacx.js":115,"./js/quoinex.js":116,"./js/southxchange.js":117,"./js/surbitcoin.js":118,"./js/therock.js":119,"./js/tidebit.js":120,"./js/tidex.js":121,"./js/urdubit.js":122,"./js/vaultoro.js":123,"./js/vbtc.js":124,"./js/virwox.js":125,"./js/wex.js":126,"./js/xbtce.js":127,"./js/yobit.js":128,"./js/yunbi.js":129,"./js/zaif.js":130,"./js/zb.js":131}],3:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, NotSupported } = require ('./base/errors'); // --------------------------------------------------------------------------- module.exports = class _1broker extends Exchange { describe () { return this.deepExtend (super.describe (), { 'id': '_1broker', 'name': '1Broker', 'countries': 'US', 'rateLimit': 1500, 'version': 'v2', 'has': { 'publicAPI': false, 'CORS': true, 'fetchTrades': false, 'fetchOHLCV': true, }, 'timeframes': { '1m': '60', // not working for some reason, returns {"server_time":"2018-03-26T03:52:27.912Z","error":true,"warning":false,"response":null,"error_code":-1,"error_message":"Error while trying to fetch historical market data. An invalid resolution was probably used."} '15m': '900', '1h': '3600', '1d': '86400', }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/1294454/27766021-420bd9fc-5ecb-11e7-8ed6-56d0081efed2.jpg', 'api': 'https://1broker.com/api', 'www': 'https://1broker.com', 'doc': 'https://1broker.com/?c=en/content/api-documentation', }, 'requiredCredentials': { 'apiKey': true, 'secret': false, }, 'api': { 'private': { 'get': [ 'market/bars', 'market/categories', 'market/details', 'market/list', 'market/quotes', 'market/ticks', 'order/cancel', 'order/create', 'order/open', 'position/close', 'position/close_cancel', 'position/edit', 'position/history', 'position/open', 'position/shared/get', 'social/profile_statistics', 'social/profile_trades', 'user/bitcoin_deposit_address', 'user/details', 'user/overview', 'user/quota_status', 'user/transaction_log', ], }, }, }); } async fetchCategories () { let response = await this.privateGetMarketCategories (); // they return an empty string among their categories, wtf? let categories = response['response']; let result = []; for (let i = 0; i < categories.length; i++) { if (categories[i]) result.push (categories[i]); } return result; } async fetchMarkets () { let this_ = this; // workaround for Babel bug (not passing `this` to _recursive() call) let categories = await this.fetchCategories (); let result = []; for (let c = 0; c < categories.length; c++) { let category = categories[c]; let markets = await this_.privateGetMarketList ({ 'category': category.toLowerCase (), }); for (let p = 0; p < markets['response'].length; p++) { let market = markets['response'][p]; let id = market['symbol']; let symbol = undefined; let base = undefined; let quote = undefined; if ((category === 'FOREX') || (category === 'CRYPTO')) { symbol = market['name']; let parts = symbol.split ('/'); base = parts[0]; quote = parts[1]; } else { base = id; quote = 'USD'; symbol = base + '/' + quote; } base = this_.commonCurrencyCode (base); quote = this_.commonCurrencyCode (quote); result.push ({ 'id': id, 'symbol': symbol, 'base': base, 'quote': quote, 'info': market, }); } } return result; } async fetchBalance (params = {}) { await this.loadMarkets (); let balance = await this.privateGetUserOverview (); let response = balance['response']; let result = { 'info': response, }; let currencies = Object.keys (this.currencies); for (let c = 0; c < currencies.length; c++) { let currency = currencies[c]; result[currency] = this.account (); } let total = this.safeFloat (response, 'balance'); result['BTC']['free'] = total; result['BTC']['total'] = total; return this.parseBalance (result); } async fetchOrderBook (symbol, limit = undefined, params = {}) { await this.loadMarkets (); let response = await this.privateGetMarketQuotes (this.extend ({ 'symbols': this.marketId (symbol), }, params)); let orderbook = response['response'][0]; let timestamp = this.parse8601 (orderbook['updated']); let bidPrice = this.safeFloat (orderbook, 'bid'); let askPrice = this.safeFloat (orderbook, 'ask'); let bid = [ bidPrice, undefined ]; let ask = [ askPrice, undefined ]; return { 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'bids': [ bid ], 'asks': [ ask ], 'nonce': undefined, }; } async fetchTrades (symbol) { throw new NotSupported (this.id + ' fetchTrades () method not implemented yet'); } async fetchTicker (symbol, params = {}) { await this.loadMarkets (); let result = await this.privateGetMarketBars (this.extend ({ 'symbol': this.marketId (symbol), 'resolution': 60, 'limit': 1, }, params)); let ticker = result['response'][0]; let timestamp = this.parse8601 (ticker['date']); let open = this.safeFloat (ticker, 'o'); let close = this.safeFloat (ticker, 'c'); let change = close - open; return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': this.safeFloat (ticker, 'h'), 'low': this.safeFloat (ticker, 'l'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, 'vwap': undefined, 'open': open, 'close': close, 'last': close, 'previousClose': undefined, 'change': change, 'percentage': change / open * 100, 'average': undefined, 'baseVolume': undefined, 'quoteVolume': undefined, 'info': ticker, }; } parseOHLCV (ohlcv, market = undefined, timeframe = '1m', since = undefined, limit = undefined) { return [ this.parse8601 (ohlcv['date']), parseFloat (ohlcv['o']), parseFloat (ohlcv['h']), parseFloat (ohlcv['l']), parseFloat (ohlcv['c']), undefined, ]; } async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); let market = this.market (symbol); let request = { 'symbol': market['id'], 'resolution': this.timeframes[timeframe], }; if (typeof since !== 'undefined') request['date_start'] = this.iso8601 (since); // they also support date_end if (typeof limit !== 'undefined') request['limit'] = limit; let result = await this.privateGetMarketBars (this.extend (request, params)); return this.parseOHLCVs (result['response'], market, timeframe, since, limit); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { await this.loadMarkets (); let order = { 'symbol': this.marketId (symbol), 'margin': amount, 'direction': (side === 'sell') ? 'short' : 'long', 'leverage': 1, 'type': side, }; if (type === 'limit') order['price'] = price; else order['type'] += '_market'; let result = await this.privateGetOrderCreate (this.extend (order, params)); return { 'info': result, 'id': result['response']['order_id'], }; } async cancelOrder (id, symbol = undefined, params = {}) { await this.loadMarkets (); return await this.privatePostOrderCancel ({ 'order_id': id }); } sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { this.checkRequiredCredentials (); let url = this.urls['api'] + '/' + this.version + '/' + path + '.php'; let query = this.extend ({ 'token': this.apiKey }, params); url += '?' + this.urlencode (query); return { 'url': url, 'method': method, 'body': body, 'headers': headers }; } async request (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { let response = await this.fetch2 (path, api, method, params, headers, body); if ('warning' in response) if (response['warning']) throw new ExchangeError (this.id + ' ' + this.json (response)); if ('error' in response) if (response['error']) throw new ExchangeError (this.id + ' ' + this.json (response)); return response; } }; },{"./base/Exchange":8,"./base/errors":10}],4:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); // --------------------------------------------------------------------------- module.exports = class _1btcxe extends Exchange { describe () { return this.deepExtend (super.describe (), { 'id': '_1btcxe', 'name': '1BTCXE', 'countries': 'PA', // Panama 'comment': 'Crypto Capital API', 'has': { 'CORS': true, 'withdraw': true, }, 'timeframes': { '1d': '1year', }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/1294454/27766049-2b294408-5ecc-11e7-85cc-adaff013dc1a.jpg', 'api': 'https://1btcxe.com/api', 'www': 'https://1btcxe.com', 'doc': 'https://1btcxe.com/api-docs.php', }, 'api': { 'public': { 'get': [ 'stats', 'historical-prices', 'order-book', 'transactions', ], }, 'private': { 'post': [ 'balances-and-info', 'open-orders', 'user-transactions', 'btc-deposit-address/get', 'btc-deposit-address/new', 'deposits/get', 'withdrawals/get', 'orders/new', 'orders/edit', 'orders/cancel', 'orders/status', 'withdrawals/new', ], }, }, }); } async fetchMarkets () { return [ { 'id': 'USD', 'symbol': 'BTC/USD', 'base': 'BTC', 'quote': 'USD' }, { 'id': 'EUR', 'symbol': 'BTC/EUR', 'base': 'BTC', 'quote': 'EUR' }, { 'id': 'CNY', 'symbol': 'BTC/CNY', 'base': 'BTC', 'quote': 'CNY' }, { 'id': 'RUB', 'symbol': 'BTC/RUB', 'base': 'BTC', 'quote': 'RUB' }, { 'id': 'CHF', 'symbol': 'BTC/CHF', 'base': 'BTC', 'quote': 'CHF' }, { 'id': 'JPY', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY' }, { 'id': 'GBP', 'symbol': 'BTC/GBP', 'base': 'BTC', 'quote': 'GBP' }, { 'id': 'CAD', 'symbol': 'BTC/CAD', 'base': 'BTC', 'quote': 'CAD' }, { 'id': 'AUD', 'symbol': 'BTC/AUD', 'base': 'BTC', 'quote': 'AUD' }, { 'id': 'AED', 'symbol': 'BTC/AED', 'base': 'BTC', 'quote': 'AED' }, { 'id': 'BGN', 'symbol': 'BTC/BGN', 'base': 'BTC', 'quote': 'BGN' }, { 'id': 'CZK', 'symbol': 'BTC/CZK', 'base': 'BTC', 'quote': 'CZK' }, { 'id': 'DKK', 'symbol': 'BTC/DKK', 'base': 'BTC', 'quote': 'DKK' }, { 'id': 'HKD', 'symbol': 'BTC/HKD', 'base': 'BTC', 'quote': 'HKD' }, { 'id': 'HRK', 'symbol': 'BTC/HRK', 'base': 'BTC', 'quote': 'HRK' }, { 'id': 'HUF', 'symbol': 'BTC/HUF', 'base': 'BTC', 'quote': 'HUF' }, { 'id': 'ILS', 'symbol': 'BTC/ILS', 'base': 'BTC', 'quote': 'ILS' }, { 'id': 'INR', 'symbol': 'BTC/INR', 'base': 'BTC', 'quote': 'INR' }, { 'id': 'MUR', 'symbol': 'BTC/MUR', 'base': 'BTC', 'quote': 'MUR' }, { 'id': 'MXN', 'symbol': 'BTC/MXN', 'base': 'BTC', 'quote': 'MXN' }, { 'id': 'NOK', 'symbol': 'BTC/NOK', 'base': 'BTC', 'quote': 'NOK' }, { 'id': 'NZD', 'symbol': 'BTC/NZD', 'base': 'BTC', 'quote': 'NZD' }, { 'id': 'PLN', 'symbol': 'BTC/PLN', 'base': 'BTC', 'quote': 'PLN' }, { 'id': 'RON', 'symbol': 'BTC/RON', 'base': 'BTC', 'quote': 'RON' }, { 'id': 'SEK', 'symbol': 'BTC/SEK', 'base': 'BTC', 'quote': 'SEK' }, { 'id': 'SGD', 'symbol': 'BTC/SGD', 'base': 'BTC', 'quote': 'SGD' }, { 'id': 'THB', 'symbol': 'BTC/THB', 'base': 'BTC', 'quote': 'THB' }, { 'id': 'TRY', 'symbol': 'BTC/TRY', 'base': 'BTC', 'quote': 'TRY' }, { 'id': 'ZAR', 'symbol': 'BTC/ZAR', 'base': 'BTC', 'quote': 'ZAR' }, ]; } async fetchBalance (params = {}) { let response = await this.privatePostBalancesAndInfo (); let balance = response['balances-and-info']; let result = { 'info': balance }; let currencies = Object.keys (this.currencies); for (let i = 0; i < currencies.length; i++) { let currency = currencies[i]; let account = this.account (); account['free'] = this.safeFloat (balance['available'], currency, 0.0); account['used'] = this.safeFloat (balance['on_hold'], currency, 0.0); account['total'] = this.sum (account['free'], account['used']); result[currency] = account; } return this.parseBalance (result); } async fetchOrderBook (symbol, limit = undefined, params = {}) { let response = await this.publicGetOrderBook (this.extend ({ 'currency': this.marketId (symbol), }, params)); return this.parseOrderBook (response['order-book'], undefined, 'bid', 'ask', 'price', 'order_amount'); } async fetchTicker (symbol, params = {}) { let response = await this.publicGetStats (this.extend ({ 'currency': this.marketId (symbol), }, params)); let ticker = response['stats']; let last = this.safeFloat (ticker, 'last_price'); return { 'symbol': symbol, 'timestamp': undefined, 'datetime': undefined, 'high': this.safeFloat (ticker, 'max'), 'low': this.safeFloat (ticker, 'min'), 'bid': this.safeFloat (ticker, 'bid'), 'bidVolume': undefined, 'ask': this.safeFloat (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': this.safeFloat (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': this.safeFloat (ticker, 'daily_change'), 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, 'quoteVolume': this.safeFloat (ticker, 'total_btc_traded'), 'info': ticker, }; } parseOHLCV (ohlcv, market = undefined, timeframe = '1d', since = undefined, limit = undefined) { return [ this.parse8601 (ohlcv['date'] + ' 00:00:00'), undefined, undefined, undefined, parseFloat (ohlcv['price']), undefined, ]; } async fetchOHLCV (symbol, timeframe = '1d', since = undefined, limit = undefined, params = {}) { let market = this.market (symbol); let response = await this.publicGetHistoricalPrices (this.extend ({ 'currency': market['id'], 'timeframe': this.timeframes[timeframe], }, params)); let ohlcvs = this.omit (response['historical-prices'], 'request_currency'); return this.parseOHLCVs (ohlcvs, market, timeframe, since, limit); } parseTrade (trade, market) { let timestamp = parseInt (trade['timestamp']) * 1000; return { 'id': trade['id'], 'info': trade, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'symbol': market['symbol'], 'order': undefined, 'type': undefined, 'side': trade['maker_type'], 'price': this.safeFloat (trade, 'price'), 'amount': this.safeFloat (trade, 'amount'), }; } async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { let market = this.market (symbol); let response = await this.publicGetTransactions (this.extend ({ 'currency': market['id'], }, params)); let trades = this.omit (response['transactions'], 'request_currency'); return this.parseTrades (trades, market, since, limit); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { let order = { 'side': side, 'type': type, 'currency': this.marketId (symbol), 'amount': amount, }; if (type === 'limit') order['limit_price'] = price; let result = await this.privatePostOrdersNew (this.extend (order, params)); return { 'info': result, 'id': result, }; } async cancelOrder (id, symbol = undefined, params = {}) { return await this.privatePostOrdersCancel ({ 'id': id }); } async withdraw (currency, amount, address, tag = undefined, params = {}) { this.checkAddress (address); await this.loadMarkets (); let response = await this.privatePostWithdrawalsNew (this.extend ({ 'currency': currency, 'amount': parseFloat (amount), 'address': address, }, params)); return { 'info': response, 'id': response['result']['uuid'], }; } sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { if (this.id === 'cryptocapital') throw new ExchangeError (this.id + ' is an abstract base API for _1btcxe'); let url = this.urls['api'] + '/' + path; if (api === 'public') { if (Object.keys (params).length) url += '?' + this.urlencode (params); } else { this.checkRequiredCredentials (); let query = this.extend ({ 'api_key': this.apiKey, 'nonce': this.nonce (), }, params); let request = this.json (query); query['signature'] = this.hmac (this.encode (request), this.encode (this.secret)); body = this.json (query); headers = { 'Content-Type': 'application/json' }; } return { 'url': url, 'method': method, 'body': body, 'headers': headers }; } async request (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { let response = await this.fetch2 (path, api, method, params, headers, body); if ('errors' in response) { let errors = []; for (let e = 0; e < response['errors'].length; e++) { let error = response['errors'][e]; errors.push (error['code'] + ': ' + error['message']); } errors = errors.join (' '); throw new ExchangeError (this.id + ' ' + errors); } return response; } }; },{"./base/Exchange":8,"./base/errors":10}],5:[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': { 'CORS': true, 'fetchTickers': true, 'fetchOHLCV': true, 'withdraw': true, 'fetchOrder': 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. }, }, 'exceptions': { '2002': InsufficientFunds, '2003': OrderNotFound, }, }); } async fetchMarkets () { let markets = await this.publicGetMarkets (); let result = []; for (let p = 0; p < markets.length; p++) { let market = markets[p]; let id = market['id']; let symbol = market['name']; let [ base, quote ] = symbol.split ('/'); base = this.commonCurrencyCode (base); quote = this.commonCurrencyCode (quote); result.push ({ 'id': id, 'symbol': symbol, 'base': base, 'quote': quote, 'info': market, }); } return result; } async fetchBalance (params = {}) { await this.loadMarkets (); let response = await this.privateGetMembersMe (); let balances = response['accounts']; let result = { 'info': balances }; for (let b = 0; b < balances.length; b++) { let balance = balances[b]; let currency = balance['currency']; let uppercase = currency.toUpperCase (); let account = { 'free': parseFloat (balance['balance']), 'used': parseFloat (balance['locked']), 'total': 0.0, }; account['total'] = this.sum (account['free'], account['used']); result[uppercase] = account; } return this.parseBalance (result); } async fetchOrderBook (symbol, limit = undefined, params = {}) { await this.loadMarkets (); let market = this.market (symbol); let request = { 'market': market['id'], }; if (typeof limit !== 'undefined') request['limit'] = limit; // default = 300 let orderbook = await this.publicGetDepth (this.extend (request, params)); let timestamp = orderbook['timestamp'] * 1000; return this.parseOrderBook (orderbook, timestamp); } parseTicker (ticker, market = undefined) { let timestamp = ticker['at'] * 1000; ticker = ticker['ticker']; let symbol = undefined; if (market) symbol = market['symbol']; let 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 (); let tickers = await this.publicGetTickers (params); let ids = Object.keys (tickers); let result = {}; for (let i = 0; i < ids.length; i++) { let 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.commonCurrencyCode (base); quote = this.commonCurrencyCode (quote); symbol = base + '/' + quote; } let ticker = tickers[id]; result[symbol] = this.parseTicker (ticker, market); } return result; } async fetchTicker (symbol, params = {}) { await this.loadMarkets (); let market = this.market (symbol); let response = await this.publicGetTickersMarket (this.extend ({ 'market': market['id'], }, params)); return this.parseTicker (response, market); } parseTrade (trade, market = undefined) { let timestamp = this.parse8601 (trade['created_at']); return { 'id': trade['id'].toString (), 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'symbol': market['symbol'], 'type': undefined, 'side': undefined, 'price': this.safeFloat (trade, 'price'), 'amount': this.safeFloat (trade, 'volume'), 'cost': this.safeFloat (trade, 'funds'), 'info': trade, }; } async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); let market = this.market (symbol); let response = await this.publicGetTrades (this.extend ({ 'market': market['id'], }, params)); return this.parseTrades (response, market, since, limit); } parseOHLCV (ohlcv, market = undefined, timeframe = '1m', since = undefined, limit = undefined) { return [ ohlcv[0] * 1000, ohlcv[1], ohlcv[2], ohlcv[3], ohlcv[4], ohlcv[5], ]; } async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); let market = this.market (symbol); if (!limit) limit = 500; // default is 30 let request = { 'market': market['id'], 'period': this.timeframes[timeframe], 'limit': limit, }; if (typeof since !== 'undefined') request['timestamp'] = since; let response = await this.publicGetK (this.extend (request, params)); return this.parseOHLCVs (response, market, timeframe, since, limit); } parseOrder (order, market = undefined) { let symbol = undefined; if (market) { symbol = market['symbol']; } else { let marketId = order['market']; symbol = this.markets_by_id[marketId]['symbol']; } let timestamp = this.parse8601 (order['created_at']); let state = order['state']; let status = undefined; if (state === 'done') { status = 'closed'; } else if (state === 'wait') { status = 'open'; } else if (state === 'cancel') { status = 'canceled'; } return { 'id': order['id'].toString (), 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'lastTradeTimestamp': undefined, 'status': status, 'symbol': symbol, 'type': order['ord_type'], 'side': order['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, }; } async fetchOrder (id, symbol = undefined, params = {}) { await this.loadMarkets (); let response = await this.privateGetOrder (this.extend ({ 'id': parseInt (id), }, params)); return this.parseOrder (response); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { await this.loadMarkets (); let order = { 'market': this.marketId (symbol), 'side': side, 'volume': amount.toString (), 'ord_type': type, }; if (type === 'limit') { order['price'] = price.toString (); } let response = await this.privatePostOrders (this.extend (order, params)); let market = this.markets_by_id[response['market']]; return this.parseOrder (response, market); } async cancelOrder (id, symbol = undefined, params = {}) { await this.loadMarkets (); let result = await this.privatePostOrderDelete ({ 'id': id }); let order = this.parseOrder (result); let status = order['status']; if (status === 'closed' || status === 'canceled') { throw new OrderNotFound (this.id + ' ' + this.json (order)); } return order; } async withdraw (currency, amount, address, tag = undefined, params = {}) { this.checkAddress (address); await this.loadMarkets (); let result = await this.privatePostWithdraw (this.extend ({ 'currency': currency.toLowerCase (), 'sum': amount, 'address': address, }, params)); return { 'info': result, 'id': undefined, }; } nonce () { return this.milliseconds (); } encodeParams (params) { if ('orders' in params) { let orders = params['orders']; let query = this.urlencode (this.keysort (this.omit (params, 'orders'))); for (let i = 0; i < orders.length; i++) { let order = orders[i]; let keys = Object.keys (order); for (let k = 0; k < keys.length; k++) { let key = keys[k]; let 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']; let 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 (); let nonce = this.nonce ().toString (); let query = this.encodeParams (this.extend ({ 'access_key': this.apiKey, 'tonce': nonce, }, params)); let auth = method + '|' + request + '|' + query; let signature = this.hmac (this.encode (auth), this.encode (this.secret)); let suffix = query + '&signature=' + signature; 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) { if (code === 400) { const response = JSON.parse (body); const error = this.safeValue (response, 'error'); const errorCode = this.safeString (error, 'code'); const feedback = this.id + ' ' + this.json (response); const exceptions = this.exceptions; if (errorCode in exceptions) { throw new exceptions[errorCode] (feedback); } // fallback to default error handler } } }; },{"./base/Exchange":8,"./base/errors":10}],6:[function(require,module,exports){ 'use strict'; // -----------