UNPKG

ccxt-compiled

Version:

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

1,102 lines (992 loc) 3.57 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 > ./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 ('./lib/base/Exchange'); const functions = require ('./lib/base/functions'); const errors = require ('./lib/base/errors'); //----------------------------------------------------------------------------- // this is updated by vss.js when building const version = '1.0.0' Exchange.ccxtVersion = version //----------------------------------------------------------------------------- const exchanges = { '_1broker': require ('./lib/_1broker.js'), '_1btcxe': require ('./lib/_1btcxe.js'), 'acx': require ('./lib/acx.js'), 'allcoin': require ('./lib/allcoin.js'), 'anxpro': require ('./lib/anxpro.js'), 'binance': require ('./lib/binance.js'), 'bit2c': require ('./lib/bit2c.js'), 'bitbay': require ('./lib/bitbay.js'), 'bitcoincoid': require ('./lib/bitcoincoid.js'), 'bitfinex': require ('./lib/bitfinex.js'), 'bitfinex2': require ('./lib/bitfinex2.js'), 'bitflyer': require ('./lib/bitflyer.js'), 'bithumb': require ('./lib/bithumb.js'), 'bitlish': require ('./lib/bitlish.js'), 'bitmarket': require ('./lib/bitmarket.js'), 'bitmex': require ('./lib/bitmex.js'), 'bitso': require ('./lib/bitso.js'), 'bitstamp': require ('./lib/bitstamp.js'), 'bitstamp1': require ('./lib/bitstamp1.js'), 'bittrex': require ('./lib/bittrex.js'), 'bl3p': require ('./lib/bl3p.js'), 'bleutrade': require ('./lib/bleutrade.js'), 'btcbox': require ('./lib/btcbox.js'), 'btcchina': require ('./lib/btcchina.js'), 'btcexchange': require ('./lib/btcexchange.js'), 'btcmarkets': require ('./lib/btcmarkets.js'), 'btctradeua': require ('./lib/btctradeua.js'), 'btcturk': require ('./lib/btcturk.js'), 'btcx': require ('./lib/btcx.js'), 'bter': require ('./lib/bter.js'), 'bxinth': require ('./lib/bxinth.js'), 'ccex': require ('./lib/ccex.js'), 'cex': require ('./lib/cex.js'), 'chbtc': require ('./lib/chbtc.js'), 'chilebit': require ('./lib/chilebit.js'), 'coincheck': require ('./lib/coincheck.js'), 'coinfloor': require ('./lib/coinfloor.js'), 'coingi': require ('./lib/coingi.js'), 'coinmarketcap': require ('./lib/coinmarketcap.js'), 'coinmate': require ('./lib/coinmate.js'), 'coinsecure': require ('./lib/coinsecure.js'), 'coinspot': require ('./lib/coinspot.js'), 'cryptopia': require ('./lib/cryptopia.js'), 'dsx': require ('./lib/dsx.js'), 'exmo': require ('./lib/exmo.js'), 'flowbtc': require ('./lib/flowbtc.js'), 'foxbit': require ('./lib/foxbit.js'), 'fybse': require ('./lib/fybse.js'), 'fybsg': require ('./lib/fybsg.js'), 'gatecoin': require ('./lib/gatecoin.js'), 'gateio': require ('./lib/gateio.js'), 'gdax': require ('./lib/gdax.js'), 'gemini': require ('./lib/gemini.js'), 'getbtc': require ('./lib/getbtc.js'), 'hitbtc': require ('./lib/hitbtc.js'), 'hitbtc2': require ('./lib/hitbtc2.js'), 'huobi': require ('./lib/huobi.js'), 'huobicny': require ('./lib/huobicny.js'), 'huobipro': require ('./lib/huobipro.js'), 'independentreserve': require ('./lib/independentreserve.js'), 'itbit': require ('./lib/itbit.js'), 'jubi': require ('./lib/jubi.js'), 'kraken': require ('./lib/kraken.js'), 'kucoin': require ('./lib/kucoin.js'), 'kuna': require ('./lib/kuna.js'), 'lakebtc': require ('./lib/lakebtc.js'), 'liqui': require ('./lib/liqui.js'), 'livecoin': require ('./lib/livecoin.js'), 'luno': require ('./lib/luno.js'), 'mercado': require ('./lib/mercado.js'), 'mixcoins': require ('./lib/mixcoins.js'), 'nova': require ('./lib/nova.js'), 'okcoincny': require ('./lib/okcoincny.js'), 'okcoinusd': require ('./lib/okcoinusd.js'), 'okex': require ('./lib/okex.js'), 'paymium': require ('./lib/paymium.js'), 'poloniex': require ('./lib/poloniex.js'), 'qryptos': require ('./lib/qryptos.js'), 'quadrigacx': require ('./lib/quadrigacx.js'), 'quoine': require ('./lib/quoine.js'), 'southxchange': require ('./lib/southxchange.js'), 'surbitcoin': require ('./lib/surbitcoin.js'), 'therock': require ('./lib/therock.js'), 'tidex': require ('./lib/tidex.js'), 'urdubit': require ('./lib/urdubit.js'), 'vaultoro': require ('./lib/vaultoro.js'), 'vbtc': require ('./lib/vbtc.js'), 'virwox': require ('./lib/virwox.js'), 'wex': require ('./lib/wex.js'), 'xbtce': require ('./lib/xbtce.js'), 'yobit': require ('./lib/yobit.js'), 'yunbi': require ('./lib/yunbi.js'), 'zaif': require ('./lib/zaif.js'), 'zb': require ('./lib/zb.js'), } //----------------------------------------------------------------------------- module.exports = Object.assign ({ version, Exchange, exchanges: Object.keys (exchanges) }, exchanges, functions, errors) //----------------------------------------------------------------------------- },{"./lib/_1broker.js":3,"./lib/_1btcxe.js":4,"./lib/acx.js":5,"./lib/allcoin.js":6,"./lib/anxpro.js":7,"./lib/base/Exchange":8,"./lib/base/errors":10,"./lib/base/functions":11,"./lib/binance.js":13,"./lib/bit2c.js":14,"./lib/bitbay.js":15,"./lib/bitcoincoid.js":16,"./lib/bitfinex.js":17,"./lib/bitfinex2.js":18,"./lib/bitflyer.js":19,"./lib/bithumb.js":20,"./lib/bitlish.js":21,"./lib/bitmarket.js":22,"./lib/bitmex.js":23,"./lib/bitso.js":24,"./lib/bitstamp.js":25,"./lib/bitstamp1.js":26,"./lib/bittrex.js":27,"./lib/bl3p.js":28,"./lib/bleutrade.js":29,"./lib/btcbox.js":30,"./lib/btcchina.js":31,"./lib/btcexchange.js":32,"./lib/btcmarkets.js":33,"./lib/btctradeua.js":34,"./lib/btcturk.js":35,"./lib/btcx.js":36,"./lib/bter.js":37,"./lib/bxinth.js":38,"./lib/ccex.js":39,"./lib/cex.js":40,"./lib/chbtc.js":41,"./lib/chilebit.js":42,"./lib/coincheck.js":43,"./lib/coinfloor.js":44,"./lib/coingi.js":45,"./lib/coinmarketcap.js":46,"./lib/coinmate.js":47,"./lib/coinsecure.js":48,"./lib/coinspot.js":49,"./lib/cryptopia.js":50,"./lib/dsx.js":51,"./lib/exmo.js":52,"./lib/flowbtc.js":53,"./lib/foxbit.js":54,"./lib/fybse.js":55,"./lib/fybsg.js":56,"./lib/gatecoin.js":57,"./lib/gateio.js":58,"./lib/gdax.js":59,"./lib/gemini.js":60,"./lib/getbtc.js":61,"./lib/hitbtc.js":62,"./lib/hitbtc2.js":63,"./lib/huobi.js":64,"./lib/huobicny.js":65,"./lib/huobipro.js":66,"./lib/independentreserve.js":67,"./lib/itbit.js":68,"./lib/jubi.js":69,"./lib/kraken.js":70,"./lib/kucoin.js":71,"./lib/kuna.js":72,"./lib/lakebtc.js":73,"./lib/liqui.js":74,"./lib/livecoin.js":75,"./lib/luno.js":76,"./lib/mercado.js":77,"./lib/mixcoins.js":78,"./lib/nova.js":79,"./lib/okcoincny.js":80,"./lib/okcoinusd.js":81,"./lib/okex.js":82,"./lib/paymium.js":83,"./lib/poloniex.js":84,"./lib/qryptos.js":85,"./lib/quadrigacx.js":86,"./lib/quoine.js":87,"./lib/southxchange.js":88,"./lib/surbitcoin.js":89,"./lib/therock.js":90,"./lib/tidex.js":91,"./lib/urdubit.js":92,"./lib/vaultoro.js":93,"./lib/vbtc.js":94,"./lib/virwox.js":95,"./lib/wex.js":96,"./lib/xbtce.js":97,"./lib/yobit.js":98,"./lib/yunbi.js":99,"./lib/zaif.js":100,"./lib/zb.js":101}],3:[function(require,module,exports){ "use strict"; // --------------------------------------------------------------------------- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } const Exchange = require('./base/Exchange'); const { ExchangeError, AuthenticationError } = 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', 'hasPublicAPI': false, 'hasCORS': true, 'hasFetchTrades': false, 'hasFetchOHLCV': true, 'timeframes': { '1m': '60', '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'] } } }); } fetchCategories() { var _this = this; return _asyncToGenerator(function* () { let response = yield _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; })(); } fetchMarkets() { var _this2 = this; return _asyncToGenerator(function* () { let this_ = _this2; // workaround for Babel bug (not passing `this` to _recursive() call) let categories = yield _this2.fetchCategories(); let result = []; for (let c = 0; c < categories.length; c++) { let category = categories[c]; let markets = yield 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; })(); } fetchBalance(params = {}) { var _this3 = this; return _asyncToGenerator(function* () { yield _this3.loadMarkets(); let balance = yield _this3.privateGetUserOverview(); let response = balance['response']; let result = { 'info': response }; let currencies = Object.keys(_this3.currencies); for (let c = 0; c < currencies.length; c++) { let currency = currencies[c]; result[currency] = _this3.account(); } let total = parseFloat(response['balance']); result['BTC']['free'] = total; result['BTC']['total'] = total; return _this3.parseBalance(result); })(); } fetchOrderBook(symbol, params = {}) { var _this4 = this; return _asyncToGenerator(function* () { yield _this4.loadMarkets(); let response = yield _this4.privateGetMarketQuotes(_this4.extend({ 'symbols': _this4.marketId(symbol) }, params)); let orderbook = response['response'][0]; let timestamp = _this4.parse8601(orderbook['updated']); let bidPrice = parseFloat(orderbook['bid']); let askPrice = parseFloat(orderbook['ask']); let bid = [bidPrice, undefined]; let ask = [askPrice, undefined]; return { 'timestamp': timestamp, 'datetime': _this4.iso8601(timestamp), 'bids': [bid], 'asks': [ask] }; })(); } fetchTrades(symbol) { var _this5 = this; return _asyncToGenerator(function* () { throw new ExchangeError(_this5.id + ' fetchTrades () method not implemented yet'); })(); } fetchTicker(symbol, params = {}) { var _this6 = this; return _asyncToGenerator(function* () { yield _this6.loadMarkets(); let result = yield _this6.privateGetMarketBars(_this6.extend({ 'symbol': _this6.marketId(symbol), 'resolution': 60, 'limit': 1 }, params)); let orderbook = yield _this6.fetchOrderBook(symbol); let ticker = result['response'][0]; let timestamp = _this6.parse8601(ticker['date']); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': _this6.iso8601(timestamp), 'high': parseFloat(ticker['h']), 'low': parseFloat(ticker['l']), 'bid': orderbook['bids'][0][0], 'ask': orderbook['asks'][0][0], 'vwap': undefined, 'open': parseFloat(ticker['o']), 'close': parseFloat(ticker['c']), 'first': undefined, 'last': undefined, 'change': undefined, 'percentage': undefined, '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]; } fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { var _this7 = this; return _asyncToGenerator(function* () { yield _this7.loadMarkets(); let market = _this7.market(symbol); let request = { 'symbol': market['id'], 'resolution': _this7.timeframes[timeframe] }; if (since) request['date_start'] = _this7.iso8601(since); // they also support date_end if (limit) request['limit'] = limit; let result = yield _this7.privateGetMarketBars(_this7.extend(request, params)); return _this7.parseOHLCVs(result['response'], market, timeframe, since, limit); })(); } createOrder(symbol, type, side, amount, price = undefined, params = {}) { var _this8 = this; return _asyncToGenerator(function* () { yield _this8.loadMarkets(); let order = { 'symbol': _this8.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 = yield _this8.privateGetOrderCreate(_this8.extend(order, params)); return { 'info': result, 'id': result['response']['order_id'] }; })(); } cancelOrder(id, symbol = undefined, params = {}) { var _this9 = this; return _asyncToGenerator(function* () { yield _this9.loadMarkets(); return yield _this9.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 }; } request(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { var _this10 = this; return _asyncToGenerator(function* () { let response = yield _this10.fetch2(path, api, method, params, headers, body); if ('warning' in response) if (response['warning']) throw new ExchangeError(_this10.id + ' ' + _this10.json(response)); if ('error' in response) if (response['error']) throw new ExchangeError(_this10.id + ' ' + _this10.json(response)); return response; })(); } }; },{"./base/Exchange":8,"./base/errors":10}],4:[function(require,module,exports){ "use strict"; // --------------------------------------------------------------------------- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } 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', 'hasCORS': true, 'hasFetchOHLCV': true, 'hasWithdraw': 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'] } }, 'markets': { 'BTC/USD': { 'id': 'USD', 'symbol': 'BTC/USD', 'base': 'BTC', 'quote': 'USD' }, 'BTC/EUR': { 'id': 'EUR', 'symbol': 'BTC/EUR', 'base': 'BTC', 'quote': 'EUR' }, 'BTC/CNY': { 'id': 'CNY', 'symbol': 'BTC/CNY', 'base': 'BTC', 'quote': 'CNY' }, 'BTC/RUB': { 'id': 'RUB', 'symbol': 'BTC/RUB', 'base': 'BTC', 'quote': 'RUB' }, 'BTC/CHF': { 'id': 'CHF', 'symbol': 'BTC/CHF', 'base': 'BTC', 'quote': 'CHF' }, 'BTC/JPY': { 'id': 'JPY', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY' }, 'BTC/GBP': { 'id': 'GBP', 'symbol': 'BTC/GBP', 'base': 'BTC', 'quote': 'GBP' }, 'BTC/CAD': { 'id': 'CAD', 'symbol': 'BTC/CAD', 'base': 'BTC', 'quote': 'CAD' }, 'BTC/AUD': { 'id': 'AUD', 'symbol': 'BTC/AUD', 'base': 'BTC', 'quote': 'AUD' }, 'BTC/AED': { 'id': 'AED', 'symbol': 'BTC/AED', 'base': 'BTC', 'quote': 'AED' }, 'BTC/BGN': { 'id': 'BGN', 'symbol': 'BTC/BGN', 'base': 'BTC', 'quote': 'BGN' }, 'BTC/CZK': { 'id': 'CZK', 'symbol': 'BTC/CZK', 'base': 'BTC', 'quote': 'CZK' }, 'BTC/DKK': { 'id': 'DKK', 'symbol': 'BTC/DKK', 'base': 'BTC', 'quote': 'DKK' }, 'BTC/HKD': { 'id': 'HKD', 'symbol': 'BTC/HKD', 'base': 'BTC', 'quote': 'HKD' }, 'BTC/HRK': { 'id': 'HRK', 'symbol': 'BTC/HRK', 'base': 'BTC', 'quote': 'HRK' }, 'BTC/HUF': { 'id': 'HUF', 'symbol': 'BTC/HUF', 'base': 'BTC', 'quote': 'HUF' }, 'BTC/ILS': { 'id': 'ILS', 'symbol': 'BTC/ILS', 'base': 'BTC', 'quote': 'ILS' }, 'BTC/INR': { 'id': 'INR', 'symbol': 'BTC/INR', 'base': 'BTC', 'quote': 'INR' }, 'BTC/MUR': { 'id': 'MUR', 'symbol': 'BTC/MUR', 'base': 'BTC', 'quote': 'MUR' }, 'BTC/MXN': { 'id': 'MXN', 'symbol': 'BTC/MXN', 'base': 'BTC', 'quote': 'MXN' }, 'BTC/NOK': { 'id': 'NOK', 'symbol': 'BTC/NOK', 'base': 'BTC', 'quote': 'NOK' }, 'BTC/NZD': { 'id': 'NZD', 'symbol': 'BTC/NZD', 'base': 'BTC', 'quote': 'NZD' }, 'BTC/PLN': { 'id': 'PLN', 'symbol': 'BTC/PLN', 'base': 'BTC', 'quote': 'PLN' }, 'BTC/RON': { 'id': 'RON', 'symbol': 'BTC/RON', 'base': 'BTC', 'quote': 'RON' }, 'BTC/SEK': { 'id': 'SEK', 'symbol': 'BTC/SEK', 'base': 'BTC', 'quote': 'SEK' }, 'BTC/SGD': { 'id': 'SGD', 'symbol': 'BTC/SGD', 'base': 'BTC', 'quote': 'SGD' }, 'BTC/THB': { 'id': 'THB', 'symbol': 'BTC/THB', 'base': 'BTC', 'quote': 'THB' }, 'BTC/TRY': { 'id': 'TRY', 'symbol': 'BTC/TRY', 'base': 'BTC', 'quote': 'TRY' }, 'BTC/ZAR': { 'id': 'ZAR', 'symbol': 'BTC/ZAR', 'base': 'BTC', 'quote': 'ZAR' } } }); } fetchBalance(params = {}) { var _this = this; return _asyncToGenerator(function* () { let response = yield _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); })(); } fetchOrderBook(symbol, params = {}) { var _this2 = this; return _asyncToGenerator(function* () { let response = yield _this2.publicGetOrderBook(_this2.extend({ 'currency': _this2.marketId(symbol) }, params)); return _this2.parseOrderBook(response['order-book'], undefined, 'bid', 'ask', 'price', 'order_amount'); })(); } fetchTicker(symbol, params = {}) { var _this3 = this; return _asyncToGenerator(function* () { let response = yield _this3.publicGetStats(_this3.extend({ 'currency': _this3.marketId(symbol) }, params)); let ticker = response['stats']; let timestamp = _this3.milliseconds(); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': _this3.iso8601(timestamp), 'high': parseFloat(ticker['max']), 'low': parseFloat(ticker['min']), 'bid': parseFloat(ticker['bid']), 'ask': parseFloat(ticker['ask']), 'vwap': undefined, 'open': parseFloat(ticker['open']), 'close': undefined, 'first': undefined, 'last': parseFloat(ticker['last_price']), 'change': parseFloat(ticker['daily_change']), 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, 'quoteVolume': parseFloat(ticker['total_btc_traded']) }; })(); } 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]; } fetchOHLCV(symbol, timeframe = '1d', since = undefined, limit = undefined, params = {}) { var _this4 = this; return _asyncToGenerator(function* () { let market = _this4.market(symbol); let response = yield _this4.publicGetHistoricalPrices(_this4.extend({ 'currency': market['id'], 'timeframe': _this4.timeframes[timeframe] }, params)); let ohlcvs = _this4.omit(response['historical-prices'], 'request_currency'); return _this4.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': parseFloat(trade['price']), 'amount': parseFloat(trade['amount']) }; } fetchTrades(symbol, since = undefined, limit = undefined, params = {}) { var _this5 = this; return _asyncToGenerator(function* () { let market = _this5.market(symbol); let response = yield _this5.publicGetTransactions(_this5.extend({ 'currency': market['id'] }, params)); let trades = _this5.omit(response['transactions'], 'request_currency'); return _this5.parseTrades(trades, market, since, limit); })(); } createOrder(symbol, type, side, amount, price = undefined, params = {}) { var _this6 = this; return _asyncToGenerator(function* () { let order = { 'side': side, 'type': type, 'currency': _this6.marketId(symbol), 'amount': amount }; if (type == 'limit') order['limit_price'] = price; let result = yield _this6.privatePostOrdersNew(_this6.extend(order, params)); return { 'info': result, 'id': result }; })(); } cancelOrder(id, symbol = undefined, params = {}) { var _this7 = this; return _asyncToGenerator(function* () { return yield _this7.privatePostOrdersCancel({ 'id': id }); })(); } withdraw(currency, amount, address, params = {}) { var _this8 = this; return _asyncToGenerator(function* () { yield _this8.loadMarkets(); let response = yield _this8.privatePostWithdrawalsNew(_this8.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 }; } request(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { var _this9 = this; return _asyncToGenerator(function* () { let response = yield _this9.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(_this9.id + ' ' + errors); } return response; })(); } }; },{"./base/Exchange":8,"./base/errors":10}],5:[function(require,module,exports){ "use strict"; // --------------------------------------------------------------------------- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } const Exchange = require('./base/Exchange'); const { ExchangeError, 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', 'hasCORS': true, 'hasFetchTickers': true, 'hasFetchOHLCV': true, 'hasWithdraw': 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': ['markets', // Get all available markets 'tickers', // Get ticker of all markets 'tickers/{market}', // Get ticker of specific market 'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order. 'order_book', // Get the order book of specified market 'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest. 'k', // Get OHLC(k line) of specific market '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 'timestamp'] }, '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'], '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'] } }, 'fees': { 'trading': { 'tierBased': false, 'percentage': true, 'maker': 0.0, 'taker': 0.0 }, 'funding': { 'tierBased': false, 'percentage': true, 'withdraw': 0.0 // There is only 1% fee on withdrawals to your bank account. } } }); } fetchMarkets() { var _this = this; return _asyncToGenerator(function* () { let markets = yield _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; })(); } fetchBalance(params = {}) { var _this2 = this; return _asyncToGenerator(function* () { yield _this2.loadMarkets(); let response = yield _this2.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'] = _this2.sum(account['free'], account['used']); result[uppercase] = account; } return _this2.parseBalance(result); })(); } fetchOrderBook(symbol, params = {}) { var _this3 = this; return _asyncToGenerator(function* () { yield _this3.loadMarkets(); let market = _this3.market(symbol); let orderbook = yield _this3.publicGetDepth(_this3.extend({ 'market': market['id'], 'limit': 300 }, params)); let timestamp = orderbook['timestamp'] * 1000; let result = _this3.parseOrderBook(orderbook, timestamp); result['bids'] = _this3.sortBy(result['bids'], 0, true); result['asks'] = _this3.sortBy(result['asks'], 0); return result; })(); } parseTicker(ticker, market = undefined) { let timestamp = ticker['at'] * 1000; ticker = ticker['ticker']; let symbol = undefined; if (market) symbol = market['symbol']; return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601(timestamp), 'high': this.safeFloat(ticker, 'high', undefined), 'low': this.safeFloat(ticker, 'low', undefined), 'bid': this.safeFloat(ticker, 'buy', undefined), 'ask': this.safeFloat(ticker, 'sell', undefined), 'vwap': undefined, 'open': undefined, 'close': undefined, 'first': undefined, 'last': this.safeFloat(ticker, 'last', undefined), 'change': undefined, 'percentage': undefined, 'average': undefined, 'baseVolume': this.safeFloat(ticker, 'vol', undefined), 'quoteVolume': undefined, 'info': ticker }; } fetchTickers(symbols = undefined, params = {}) { var _this4 = this; return _asyncToGenerator(function* () { yield _this4.loadMarkets(); let tickers = yield _this4.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 _this4.markets_by_id) { market = _this4.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 = _this4.commonCurrencyCode(base); quote = _this4.commonCurrencyCode(quote); let symbol = base + '/' + quote; } let ticker = tickers[id]; result[symbol] = _this4.parseTicker(ticker, market); } return result; })(); } fetchTicker(symbol, params = {}) { var _this5 = this; return _asyncToGenerator(function* () { yield _this5.loadMarkets(); let market = _this5.market(symbol); let response = yield _this5.publicGetTickersMarket(_this5.extend({ 'market': market['id'] }, params)); return _this5.parseTicker(response, market); })(); } parseTrade(trade, market = undefined) { let timestamp = trade['timestamp'] * 1000; let side = trade['type'] == 'bid' ? 'buy' : 'sell'; return { 'info': trade, 'id': trade['tid'].toString(), 'timestamp': timestamp, 'datetime': this.iso8601(timestamp), 'symbol': market['symbol'], 'type': undefined, 'side': side, 'price': trade['price'], 'amount': trade['amount'] }; } fetchTrades(symbol, since = undefined, limit = undefined, params = {}) { var _this6 = this; return _asyncToGenerator(function* () { yield _this6.loadMarkets(); let market = _this6.market(symbol); let response = yield _this6.publicGetTrades(_this6.extend({ 'market': market['id'] }, params)); // looks like they switched this endpoint off // it returns 503 Service Temporarily Unavailable always // return this.parseTrades (response, market, since, limit); return response; })(); } parseOHLCV(ohlcv, market = undefined, timeframe = '1m', since = undefined, limit = undefined) { return [ohlcv[0] * 1000, ohlcv[1], ohlcv[2], ohlcv[3], ohlcv[4], ohlcv[5]]; } fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { var _this7 = this; return _asyncToGenerator(function* () { yield _this7.loadMarkets(); let market = _this7.market(symbol); if (!limit) limit = 500; // default is 30 let request = { 'market': market['id'], 'period': _this7.timeframes[timeframe], 'limit': limit }; if (since) request['timestamp'] = since; let response = yield _this7.publicGetK(_this7.extend(request, params)); return _this7.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.marketsById[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'], 'timestamp': timestamp, 'datetime': this.iso8601(timestamp), 'status': status, 'symbol': symbol, 'type': order['ord_type'], 'side': order['side'], 'price': parseFloat(order['price']), 'amount': parseFloat(order['volume']), 'filled': parseFloat(order['executed_volume']), 'remaining': parseFloat(order['remaining_volume']), 'trades': undefined, 'fee': undefined, 'info': order }; } createOrder(symbol, type, side, amount, price = undefined, params = {}) { var _this8 = this; return _asyncToGenerator(function* () { yield _this8.loadMarkets(); let order = { 'market': _this8.marketId(symbol), 'side': side, 'volume': amount.toString(), 'ord_type': type }; if (type == 'limit') { order['price'] = price.toString(); } let response = yield _this8.privatePostOrders(_this8.extend(order, params)); let market = _this8.marketsById[response['market']]; return _this8.parseOrder(response, market); })(); } cancelOrder(id, symbol = undefined, params = {}) { var _this9 = this; return _asyncToGenerator(function* () { yield _this9.loadMarkets(); let result = yield _this9.privatePostOrderDelete({ 'id': id }); let order = _this9.parseOrder(result); if (order['status'] == 'closed') { throw new OrderNotFound(_this9.id + ' ' + result); } return order; })(); } withdraw(currency, amount, address, params = {}) { var _this10 = this; return _asyncToGenerator(function* () { yield _this10.loadMarkets(); let result = yield _this10.privatePostWithdraw(_this10.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' };