UNPKG

ccxt-bybit

Version:

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

1,105 lines (1,036 loc) 4.72 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.23.51' Exchange.ccxtVersion = version //----------------------------------------------------------------------------- const exchanges = { '_1btcxe': require ('./js/_1btcxe.js'), 'acx': require ('./js/acx.js'), 'adara': require ('./js/adara.js'), 'anxpro': require ('./js/anxpro.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'), 'binanceje': require ('./js/binanceje.js'), 'binanceus': require ('./js/binanceus.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'), 'bitforex': require ('./js/bitforex.js'), 'bithumb': require ('./js/bithumb.js'), 'bitkk': require ('./js/bitkk.js'), 'bitlish': require ('./js/bitlish.js'), 'bitmart': require ('./js/bitmart.js'), 'bitmax': require ('./js/bitmax.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'), 'btcalpha': require ('./js/btcalpha.js'), 'btcbox': require ('./js/btcbox.js'), 'btcchina': require ('./js/btcchina.js'), 'btcmarkets': require ('./js/btcmarkets.js'), 'btctradeim': require ('./js/btctradeim.js'), 'btctradeua': require ('./js/btctradeua.js'), 'btcturk': require ('./js/btcturk.js'), 'buda': require ('./js/buda.js'), 'bw': require ('./js/bw.js'), 'bytetrade': require ('./js/bytetrade.js'), 'cex': require ('./js/cex.js'), 'chilebit': require ('./js/chilebit.js'), 'cobinhood': require ('./js/cobinhood.js'), 'coinbase': require ('./js/coinbase.js'), 'coinbaseprime': require ('./js/coinbaseprime.js'), 'coinbasepro': require ('./js/coinbasepro.js'), 'coincheck': require ('./js/coincheck.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'), 'coolcoin': require ('./js/coolcoin.js'), 'coss': require ('./js/coss.js'), 'crex24': require ('./js/crex24.js'), 'deribit': require ('./js/deribit.js'), 'digifinex': require ('./js/digifinex.js'), 'dsx': require ('./js/dsx.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'), 'fybse': require ('./js/fybse.js'), 'gateio': require ('./js/gateio.js'), 'gemini': require ('./js/gemini.js'), 'hitbtc': require ('./js/hitbtc.js'), 'hitbtc2': require ('./js/hitbtc2.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'), 'kkex': require ('./js/kkex.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'), 'oceanex': require ('./js/oceanex.js'), 'okcoincny': require ('./js/okcoincny.js'), 'okcoinusd': require ('./js/okcoinusd.js'), 'okex': require ('./js/okex.js'), 'okex3': require ('./js/okex3.js'), 'paymium': require ('./js/paymium.js'), 'poloniex': require ('./js/poloniex.js'), 'rightbtc': require ('./js/rightbtc.js'), 'southxchange': require ('./js/southxchange.js'), 'stex': require ('./js/stex.js'), 'stronghold': require ('./js/stronghold.js'), 'surbitcoin': require ('./js/surbitcoin.js'), 'theocean': require ('./js/theocean.js'), 'therock': require ('./js/therock.js'), 'tidebit': require ('./js/tidebit.js'), 'tidex': require ('./js/tidex.js'), 'timex': require ('./js/timex.js'), 'topq': require ('./js/topq.js'), 'upbit': require ('./js/upbit.js'), 'vaultoro': require ('./js/vaultoro.js'), 'vbtc': require ('./js/vbtc.js'), 'whitebit': require ('./js/whitebit.js'), 'xbtce': require ('./js/xbtce.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/_1btcxe.js":3,"./js/acx.js":4,"./js/adara.js":5,"./js/anxpro.js":6,"./js/base/Exchange":7,"./js/base/errors":9,"./js/base/functions":10,"./js/bcex.js":21,"./js/bequant.js":22,"./js/bibox.js":23,"./js/bigone.js":24,"./js/binance.js":25,"./js/binanceje.js":26,"./js/binanceus.js":27,"./js/bit2c.js":28,"./js/bitbank.js":29,"./js/bitbay.js":30,"./js/bitfinex.js":31,"./js/bitfinex2.js":32,"./js/bitflyer.js":33,"./js/bitforex.js":34,"./js/bithumb.js":35,"./js/bitkk.js":36,"./js/bitlish.js":37,"./js/bitmart.js":38,"./js/bitmax.js":39,"./js/bitmex.js":40,"./js/bitso.js":41,"./js/bitstamp.js":42,"./js/bitstamp1.js":43,"./js/bittrex.js":44,"./js/bitz.js":45,"./js/bl3p.js":46,"./js/bleutrade.js":47,"./js/braziliex.js":48,"./js/btcalpha.js":49,"./js/btcbox.js":50,"./js/btcchina.js":51,"./js/btcmarkets.js":52,"./js/btctradeim.js":53,"./js/btctradeua.js":54,"./js/btcturk.js":55,"./js/buda.js":56,"./js/bw.js":57,"./js/bytetrade.js":58,"./js/cex.js":59,"./js/chilebit.js":60,"./js/cobinhood.js":61,"./js/coinbase.js":62,"./js/coinbaseprime.js":63,"./js/coinbasepro.js":64,"./js/coincheck.js":65,"./js/coinegg.js":66,"./js/coinex.js":67,"./js/coinfalcon.js":68,"./js/coinfloor.js":69,"./js/coingi.js":70,"./js/coinmarketcap.js":71,"./js/coinmate.js":72,"./js/coinone.js":73,"./js/coinspot.js":74,"./js/coolcoin.js":75,"./js/coss.js":76,"./js/crex24.js":77,"./js/deribit.js":78,"./js/digifinex.js":79,"./js/dsx.js":80,"./js/exmo.js":81,"./js/exx.js":82,"./js/fcoin.js":83,"./js/fcoinjp.js":84,"./js/flowbtc.js":85,"./js/foxbit.js":86,"./js/ftx.js":87,"./js/fybse.js":88,"./js/gateio.js":89,"./js/gemini.js":90,"./js/hitbtc.js":91,"./js/hitbtc2.js":92,"./js/huobipro.js":93,"./js/huobiru.js":94,"./js/ice3x.js":95,"./js/idex.js":96,"./js/independentreserve.js":97,"./js/indodax.js":98,"./js/itbit.js":99,"./js/kkex.js":100,"./js/kraken.js":101,"./js/kucoin.js":102,"./js/kuna.js":103,"./js/lakebtc.js":104,"./js/latoken.js":105,"./js/lbank.js":106,"./js/liquid.js":107,"./js/livecoin.js":108,"./js/luno.js":109,"./js/lykke.js":110,"./js/mercado.js":111,"./js/mixcoins.js":112,"./js/oceanex.js":113,"./js/okcoincny.js":114,"./js/okcoinusd.js":115,"./js/okex.js":116,"./js/okex3.js":117,"./js/paymium.js":118,"./js/poloniex.js":119,"./js/rightbtc.js":120,"./js/southxchange.js":121,"./js/stex.js":159,"./js/stronghold.js":160,"./js/surbitcoin.js":161,"./js/theocean.js":162,"./js/therock.js":163,"./js/tidebit.js":164,"./js/tidex.js":165,"./js/timex.js":166,"./js/topq.js":167,"./js/upbit.js":168,"./js/vaultoro.js":169,"./js/vbtc.js":170,"./js/whitebit.js":171,"./js/xbtce.js":172,"./js/yobit.js":173,"./js/zaif.js":174,"./js/zb.js":175}],3:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable } = 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 (params = {}) { return [ { 'id': 'USD', 'symbol': 'BTC/USD', 'base': 'BTC', 'quote': 'USD', 'baseId': 'BTC', 'quoteId': 'USD' }, { 'id': 'EUR', 'symbol': 'BTC/EUR', 'base': 'BTC', 'quote': 'EUR', 'baseId': 'BTC', 'quoteId': 'EUR' }, { 'id': 'CNY', 'symbol': 'BTC/CNY', 'base': 'BTC', 'quote': 'CNY', 'baseId': 'BTC', 'quoteId': 'CNY' }, { 'id': 'RUB', 'symbol': 'BTC/RUB', 'base': 'BTC', 'quote': 'RUB', 'baseId': 'BTC', 'quoteId': 'RUB' }, { 'id': 'CHF', 'symbol': 'BTC/CHF', 'base': 'BTC', 'quote': 'CHF', 'baseId': 'BTC', 'quoteId': 'CHF' }, { 'id': 'JPY', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY', 'baseId': 'BTC', 'quoteId': 'JPY' }, { 'id': 'GBP', 'symbol': 'BTC/GBP', 'base': 'BTC', 'quote': 'GBP', 'baseId': 'BTC', 'quoteId': 'GBP' }, { 'id': 'CAD', 'symbol': 'BTC/CAD', 'base': 'BTC', 'quote': 'CAD', 'baseId': 'BTC', 'quoteId': 'CAD' }, { 'id': 'AUD', 'symbol': 'BTC/AUD', 'base': 'BTC', 'quote': 'AUD', 'baseId': 'BTC', 'quoteId': 'AUD' }, { 'id': 'AED', 'symbol': 'BTC/AED', 'base': 'BTC', 'quote': 'AED', 'baseId': 'BTC', 'quoteId': 'AED' }, { 'id': 'BGN', 'symbol': 'BTC/BGN', 'base': 'BTC', 'quote': 'BGN', 'baseId': 'BTC', 'quoteId': 'BGN' }, { 'id': 'CZK', 'symbol': 'BTC/CZK', 'base': 'BTC', 'quote': 'CZK', 'baseId': 'BTC', 'quoteId': 'CZK' }, { 'id': 'DKK', 'symbol': 'BTC/DKK', 'base': 'BTC', 'quote': 'DKK', 'baseId': 'BTC', 'quoteId': 'DKK' }, { 'id': 'HKD', 'symbol': 'BTC/HKD', 'base': 'BTC', 'quote': 'HKD', 'baseId': 'BTC', 'quoteId': 'HKD' }, { 'id': 'HRK', 'symbol': 'BTC/HRK', 'base': 'BTC', 'quote': 'HRK', 'baseId': 'BTC', 'quoteId': 'HRK' }, { 'id': 'HUF', 'symbol': 'BTC/HUF', 'base': 'BTC', 'quote': 'HUF', 'baseId': 'BTC', 'quoteId': 'HUF' }, { 'id': 'ILS', 'symbol': 'BTC/ILS', 'base': 'BTC', 'quote': 'ILS', 'baseId': 'BTC', 'quoteId': 'ILS' }, { 'id': 'INR', 'symbol': 'BTC/INR', 'base': 'BTC', 'quote': 'INR', 'baseId': 'BTC', 'quoteId': 'INR' }, { 'id': 'MUR', 'symbol': 'BTC/MUR', 'base': 'BTC', 'quote': 'MUR', 'baseId': 'BTC', 'quoteId': 'MUR' }, { 'id': 'MXN', 'symbol': 'BTC/MXN', 'base': 'BTC', 'quote': 'MXN', 'baseId': 'BTC', 'quoteId': 'MXN' }, { 'id': 'NOK', 'symbol': 'BTC/NOK', 'base': 'BTC', 'quote': 'NOK', 'baseId': 'BTC', 'quoteId': 'NOK' }, { 'id': 'NZD', 'symbol': 'BTC/NZD', 'base': 'BTC', 'quote': 'NZD', 'baseId': 'BTC', 'quoteId': 'NZD' }, { 'id': 'PLN', 'symbol': 'BTC/PLN', 'base': 'BTC', 'quote': 'PLN', 'baseId': 'BTC', 'quoteId': 'PLN' }, { 'id': 'RON', 'symbol': 'BTC/RON', 'base': 'BTC', 'quote': 'RON', 'baseId': 'BTC', 'quoteId': 'RON' }, { 'id': 'SEK', 'symbol': 'BTC/SEK', 'base': 'BTC', 'quote': 'SEK', 'baseId': 'BTC', 'quoteId': 'SEK' }, { 'id': 'SGD', 'symbol': 'BTC/SGD', 'base': 'BTC', 'quote': 'SGD', 'baseId': 'BTC', 'quoteId': 'SGD' }, { 'id': 'THB', 'symbol': 'BTC/THB', 'base': 'BTC', 'quote': 'THB', 'baseId': 'BTC', 'quoteId': 'THB' }, { 'id': 'TRY', 'symbol': 'BTC/TRY', 'base': 'BTC', 'quote': 'TRY', 'baseId': 'BTC', 'quoteId': 'TRY' }, { 'id': 'ZAR', 'symbol': 'BTC/ZAR', 'base': 'BTC', 'quote': 'ZAR', 'baseId': 'BTC', 'quoteId': 'ZAR' }, ]; } async fetchBalance (params = {}) { await this.loadMarkets (); const response = await this.privatePostBalancesAndInfo (params); const balance = response['balances-and-info']; const result = { 'info': balance }; const codes = Object.keys (this.currencies); for (let i = 0; i < codes.length; i++) { const code = codes[i]; const currency = this.currency (code); const currencyId = currency['id']; const account = this.account (); account['free'] = this.safeFloat (balance['available'], currencyId); account['used'] = this.safeFloat (balance['on_hold'], currencyId); result[code] = account; } return this.parseBalance (result); } async fetchOrderBook (symbol, limit = undefined, params = {}) { await this.loadMarkets (); const request = { 'currency': this.marketId (symbol), }; const response = await this.publicGetOrderBook (this.extend (request, params)); return this.parseOrderBook (response['order-book'], undefined, 'bid', 'ask', 'price', 'order_amount'); } async fetchTicker (symbol, params = {}) { await this.loadMarkets (); const request = { 'currency': this.marketId (symbol), }; const response = await this.publicGetStats (this.extend (request, params)); const ticker = this.safeValue (response, 'stats', {}); const 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, this.safeFloat (ohlcv, 'price'), undefined, ]; } async fetchOHLCV (symbol, timeframe = '1d', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const response = await this.publicGetHistoricalPrices (this.extend ({ 'currency': market['id'], 'timeframe': this.timeframes[timeframe], }, params)); const ohlcvs = this.toArray (this.omit (response['historical-prices'], 'request_currency')); return this.parseOHLCVs (ohlcvs, market, timeframe, since, limit); } parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'timestamp'); const id = this.safeString (trade, 'id'); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } const type = undefined; const side = this.safeString (trade, 'maker_type'); const price = this.safeFloat (trade, 'price'); const amount = this.safeFloat (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { cost = amount * price; } } return { 'id': id, 'info': trade, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'symbol': symbol, 'order': undefined, 'type': type, 'side': side, 'takerOrMaker': undefined, 'price': price, 'amount': amount, 'cost': cost, 'fee': undefined, }; } async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'currency': market['id'], }; if (limit !== undefined) { request['limit'] = limit; } const response = await this.publicGetTransactions (this.extend (request, params)); const trades = this.toArray (this.omit (response['transactions'], 'request_currency')); return this.parseTrades (trades, market, since, limit); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { await this.loadMarkets (); const request = { 'side': side, 'type': type, 'currency': this.marketId (symbol), 'amount': amount, }; if (type === 'limit') { request['limit_price'] = price; } const result = await this.privatePostOrdersNew (this.extend (request, params)); return { 'info': result, 'id': result, }; } async cancelOrder (id, symbol = undefined, params = {}) { await this.loadMarkets (); const request = { 'id': id, }; return await this.privatePostOrdersCancel (this.extend (request, params)); } async withdraw (code, amount, address, tag = undefined, params = {}) { this.checkAddress (address); await this.loadMarkets (); const currency = this.currency (code); const request = { 'currency': currency['id'], 'amount': parseFloat (amount), 'address': address, }; const response = await this.privatePostWithdrawalsNew (this.extend (request, 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 (); const query = this.extend ({ 'api_key': this.apiKey, 'nonce': this.nonce (), }, params); const 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) { const response = await this.fetch2 (path, api, method, params, headers, body); if (typeof response === 'string') { if (response.indexOf ('Maintenance') >= 0) { throw new ExchangeNotAvailable (this.id + ' on maintenance'); } } if ('errors' in response) { let errors = []; for (let e = 0; e < response['errors'].length; e++) { const error = response['errors'][e]; errors.push (error['code'] + ': ' + error['message']); } errors = errors.join (' '); throw new ExchangeError (this.id + ' ' + errors); } return response; } }; },{"./base/Exchange":7,"./base/errors":9}],4:[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. }, }, '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, }); } 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 result; } 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 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, 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 (); 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) { let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } else { const marketId = this.safeString (order, 'market'); symbol = this.markets_by_id[marketId]['symbol']; } 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, '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, }; } 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":7,"./base/errors":9}],5:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest, AuthenticationError, InvalidOrder, InsufficientFunds, OrderNotFound } = require ('./base/errors'); // --------------------------------------------------------------------------- module.exports = class adara extends Exchange { describe () { return this.deepExtend (super.describe (), { 'id': 'adara', 'name': 'Adara', 'countries': [ 'MT' ], 'version': 'v1', 'rateLimit': 1000, 'certified': false, // new metainfo interface 'has': { 'CORS': false, 'fetchCurrencies': true, 'fetchOrderBooks': false, 'createMarketOrder': false, 'fetchDepositAddress': false, 'fetchClosedOrders': true, 'fetchMyTrades': false, 'fetchOHLCV': false, 'fetchOrder': true, 'fetchOpenOrders': true, 'fetchTickers': true, 'withdraw': false, 'fetchDeposits': false, 'fetchWithdrawals': false, 'fetchTransactions': false, }, 'requiredCredentials': { 'apiKey': true, 'secret': true, 'token': false, }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/1294454/49189583-0466a780-f380-11e8-9248-57a631aad2d6.jpg', 'api': 'https://api.adara.io', 'www': 'https://adara.io', 'doc': 'https://api.adara.io/v1', 'fees': 'https://adara.io/fees', }, 'api': { 'public': { 'get': [ 'currencies', 'limits', 'market', 'marketDepth', 'marketInfo', 'orderBook', 'quote/', 'quote/{id}', 'symbols', 'trade', ], 'post': [ 'confirmContactEmail', 'restorePassword', 'user', // sign up ], }, 'private': { 'get': [ 'balance', 'order', 'order/{id}', 'currencyBalance', 'apiKey', // the list of apiKeys 'user/{id}', ], 'post': [ 'order', 'recovery', 'user', 'apiKey', // sign in and optionally create an apiKey 'contact', ], 'patch': [ 'order/{id}', 'user/{id}', // change password 'customer', // update user info ], 'delete': [ 'apiKey', ], }, }, 'fees': { 'trading': { 'tierBased': false, 'percentage': true, 'maker': 0.001, 'taker': 0.001, }, 'funding': { 'tierBased': false, 'percentage': false, 'withdraw': {}, 'deposit': {}, }, }, 'exceptions': { 'exact': { 'Insufficient funds': InsufficientFunds, 'Amount is too small': InvalidOrder, 'operation has invalid value': InvalidOrder, "closed order can't be changed": InvalidOrder, 'Order is not found': OrderNotFound, 'AUTH': AuthenticationError, 'You are not authorized': AuthenticationError, 'Bad Request': BadRequest, '500': ExchangeError, }, 'broad': {}, }, }); } async fetchMarkets (params = {}) { const request = { 'include': 'from,to', }; const response = await this.publicGetSymbols (this.extend (request, params)); const included = this.safeValue (response, 'included', []); const includedByType = this.groupBy (included, 'type'); const currencies = this.safeValue (includedByType, 'currency', []); const currenciesById = this.indexBy (currencies, 'id'); // // { meta: { total: 61 }, // data: [ { id: "XRPUSD", // type: "symbol", // attributes: { allowTrade: false, // createdAt: "2018-10-23T09:31:06.830Z", // digits: 5, // fullName: "XRPUSD", // makerFee: "0.0250", // name: "XRPUSD",