ccxt-look 1.81.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cache/eslintcache +1 -0
- package/.dockerignore +6 -0
- package/.eslintignore +1 -0
- package/.gitattributes +5 -0
- package/.readthedocs.yaml +16 -0
- package/CONTRIBUTING.md +1049 -0
- package/LICENSE.txt +21 -0
- package/README.md +537 -0
- package/SECURITY.md +5 -0
- package/build/cleanup-old-tags.js +94 -0
- package/build/countries.js +256 -0
- package/build/export-exchanges.js +520 -0
- package/build/fs.js +51 -0
- package/build/transpile.js +1772 -0
- package/build/vss.js +78 -0
- package/ccxt.browser.js +7 -0
- package/ccxt.d.ts +692 -0
- package/ccxt.js +171 -0
- package/cleanup.sh +2 -0
- package/composer-install.sh +20 -0
- package/dist/ccxt.browser.js +208383 -0
- package/gource.sh +3 -0
- package/index.html +7 -0
- package/js/.eslintrc +87 -0
- package/js/aax.js +2686 -0
- package/js/ascendex.js +2584 -0
- package/js/base/.eslintrc.js +43 -0
- package/js/base/Exchange.js +2371 -0
- package/js/base/Precise.js +283 -0
- package/js/base/errorHierarchy.js +47 -0
- package/js/base/errors.js +55 -0
- package/js/base/functions/crypto.js +158 -0
- package/js/base/functions/encode.js +118 -0
- package/js/base/functions/generic.js +270 -0
- package/js/base/functions/misc.js +138 -0
- package/js/base/functions/number.js +329 -0
- package/js/base/functions/platform.js +38 -0
- package/js/base/functions/string.js +21 -0
- package/js/base/functions/throttle.js +79 -0
- package/js/base/functions/time.js +210 -0
- package/js/base/functions/type.js +66 -0
- package/js/base/functions.js +28 -0
- package/js/bequant.js +32 -0
- package/js/bibox.js +1407 -0
- package/js/bigone.js +1366 -0
- package/js/binance.js +5652 -0
- package/js/binancecoinm.js +46 -0
- package/js/binanceus.js +46 -0
- package/js/binanceusdm.js +49 -0
- package/js/bit2c.js +535 -0
- package/js/bitbank.js +842 -0
- package/js/bitbay.js +16 -0
- package/js/bitbns.js +1073 -0
- package/js/bitcoincom.js +15 -0
- package/js/bitfinex.js +1433 -0
- package/js/bitfinex2.js +2025 -0
- package/js/bitflyer.js +840 -0
- package/js/bitforex.js +614 -0
- package/js/bitget.js +2397 -0
- package/js/bithumb.js +980 -0
- package/js/bitmart.js +2516 -0
- package/js/bitmex.js +1809 -0
- package/js/bitopro.js +1443 -0
- package/js/bitpanda.js +1782 -0
- package/js/bitrue.js +1747 -0
- package/js/bitso.js +1062 -0
- package/js/bitstamp.js +1757 -0
- package/js/bitstamp1.js +343 -0
- package/js/bittrex.js +1876 -0
- package/js/bitvavo.js +1579 -0
- package/js/bkex.js +1233 -0
- package/js/bl3p.js +346 -0
- package/js/blockchaincom.js +969 -0
- package/js/btcalpha.js +680 -0
- package/js/btcbox.js +477 -0
- package/js/btcmarkets.js +1022 -0
- package/js/btctradeua.js +466 -0
- package/js/btcturk.js +734 -0
- package/js/buda.js +946 -0
- package/js/bw.js +1265 -0
- package/js/bybit.js +3372 -0
- package/js/bytetrade.js +1336 -0
- package/js/cdax.js +1646 -0
- package/js/cex.js +1410 -0
- package/js/coinbase.js +1342 -0
- package/js/coinbaseprime.js +31 -0
- package/js/coinbasepro.js +1466 -0
- package/js/coincheck.js +755 -0
- package/js/coinex.js +3400 -0
- package/js/coinfalcon.js +880 -0
- package/js/coinmate.js +794 -0
- package/js/coinone.js +816 -0
- package/js/coinspot.js +345 -0
- package/js/crex24.js +1636 -0
- package/js/cryptocom.js +1832 -0
- package/js/currencycom.js +1748 -0
- package/js/delta.js +1547 -0
- package/js/deribit.js +2148 -0
- package/js/digifinex.js +1585 -0
- package/js/eqonex.js +1660 -0
- package/js/exmo.js +1670 -0
- package/js/fairdesk.js +1231 -0
- package/js/flowbtc.js +35 -0
- package/js/fmfwio.js +34 -0
- package/js/ftx.js +2751 -0
- package/js/ftxus.js +38 -0
- package/js/gateio.js +4174 -0
- package/js/gemini.js +1397 -0
- package/js/hitbtc.js +1343 -0
- package/js/hitbtc3.js +2329 -0
- package/js/hollaex.js +1486 -0
- package/js/huobi.js +5706 -0
- package/js/huobijp.js +1710 -0
- package/js/huobipro.js +18 -0
- package/js/idex.js +1439 -0
- package/js/independentreserve.js +649 -0
- package/js/indodax.js +742 -0
- package/js/itbit.js +722 -0
- package/js/kraken.js +2179 -0
- package/js/kucoin.js +2571 -0
- package/js/kucoinfutures.js +1771 -0
- package/js/kuna.js +809 -0
- package/js/latoken.js +1445 -0
- package/js/lbank.js +760 -0
- package/js/liquid.js +1432 -0
- package/js/luno.js +873 -0
- package/js/lykke.js +1147 -0
- package/js/mercado.js +771 -0
- package/js/mexc.js +3151 -0
- package/js/ndax.js +2233 -0
- package/js/novadax.js +1318 -0
- package/js/oceanex.js +816 -0
- package/js/okcoin.js +3841 -0
- package/js/okex.js +16 -0
- package/js/okex5.js +16 -0
- package/js/okx.js +4795 -0
- package/js/paymium.js +498 -0
- package/js/phemex.js +2957 -0
- package/js/poloniex.js +1674 -0
- package/js/probit.js +1346 -0
- package/js/qtrade.js +1588 -0
- package/js/ripio.js +1061 -0
- package/js/static_dependencies/BN/bn.js +3526 -0
- package/js/static_dependencies/README.md +1 -0
- package/js/static_dependencies/crypto-js/crypto-js.js +5988 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/base.js +375 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/edwards.js +433 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/index.js +8 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/mont.js +180 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/short.js +938 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curves.js +204 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/index.js +240 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/key.js +119 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/signature.js +24 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/index.js +145 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/key.js +100 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/signature.js +65 -0
- package/js/static_dependencies/elliptic/lib/elliptic/precomputed/secp256k1.js +780 -0
- package/js/static_dependencies/elliptic/lib/elliptic/utils.js +214 -0
- package/js/static_dependencies/elliptic/lib/elliptic.js +22 -0
- package/js/static_dependencies/elliptic/lib/hmac-drbg/hmac-drbg.js +114 -0
- package/js/static_dependencies/fetch-ponyfill/fetch-node.js +39 -0
- package/js/static_dependencies/node-fetch/index.js +1564 -0
- package/js/static_dependencies/node-rsa/NodeRSA.js +223 -0
- package/js/static_dependencies/node-rsa/asn1/ber/errors.js +13 -0
- package/js/static_dependencies/node-rsa/asn1/ber/index.js +21 -0
- package/js/static_dependencies/node-rsa/asn1/ber/reader.js +262 -0
- package/js/static_dependencies/node-rsa/asn1/ber/types.js +36 -0
- package/js/static_dependencies/node-rsa/asn1/index.js +17 -0
- package/js/static_dependencies/node-rsa/encryptEngines/js.js +34 -0
- package/js/static_dependencies/node-rsa/formats/components.js +71 -0
- package/js/static_dependencies/node-rsa/formats/formats.js +31 -0
- package/js/static_dependencies/node-rsa/formats/pkcs1.js +148 -0
- package/js/static_dependencies/node-rsa/formats/pkcs8.js +187 -0
- package/js/static_dependencies/node-rsa/libs/jsbn.js +1252 -0
- package/js/static_dependencies/node-rsa/libs/rsa.js +147 -0
- package/js/static_dependencies/node-rsa/schemes/pkcs1.js +176 -0
- package/js/static_dependencies/node-rsa/schemes/schemes.js +21 -0
- package/js/static_dependencies/node-rsa/utils.js +98 -0
- package/js/static_dependencies/qs/formats.js +18 -0
- package/js/static_dependencies/qs/index.js +11 -0
- package/js/static_dependencies/qs/parse.js +242 -0
- package/js/static_dependencies/qs/stringify.js +269 -0
- package/js/static_dependencies/qs/utils.js +230 -0
- package/js/stex.js +1925 -0
- package/js/test/.eslintrc.js +42 -0
- package/js/test/Exchange/test.balance.js +61 -0
- package/js/test/Exchange/test.borrowRate.js +32 -0
- package/js/test/Exchange/test.currency.js +52 -0
- package/js/test/Exchange/test.fetchBalance.js +23 -0
- package/js/test/Exchange/test.fetchBorrowInterest.js +59 -0
- package/js/test/Exchange/test.fetchBorrowRate.js +32 -0
- package/js/test/Exchange/test.fetchBorrowRates.js +28 -0
- package/js/test/Exchange/test.fetchClosedOrders.js +32 -0
- package/js/test/Exchange/test.fetchCurrencies.js +35 -0
- package/js/test/Exchange/test.fetchDeposits.js +31 -0
- package/js/test/Exchange/test.fetchFundingFees.js +19 -0
- package/js/test/Exchange/test.fetchFundingRateHistory.js +40 -0
- package/js/test/Exchange/test.fetchL2OrderBook.js +23 -0
- package/js/test/Exchange/test.fetchLedger.js +42 -0
- package/js/test/Exchange/test.fetchLeverageTiers.js +33 -0
- package/js/test/Exchange/test.fetchMarketLeverageTiers.js +22 -0
- package/js/test/Exchange/test.fetchMarkets.js +33 -0
- package/js/test/Exchange/test.fetchMyTrades.js +42 -0
- package/js/test/Exchange/test.fetchOHLCV.js +46 -0
- package/js/test/Exchange/test.fetchOpenOrders.js +36 -0
- package/js/test/Exchange/test.fetchOrderBook.js +25 -0
- package/js/test/Exchange/test.fetchOrderBooks.js +35 -0
- package/js/test/Exchange/test.fetchOrders.js +41 -0
- package/js/test/Exchange/test.fetchPositions.js +47 -0
- package/js/test/Exchange/test.fetchStatus.js +35 -0
- package/js/test/Exchange/test.fetchTicker.js +38 -0
- package/js/test/Exchange/test.fetchTickers.js +49 -0
- package/js/test/Exchange/test.fetchTrades.js +39 -0
- package/js/test/Exchange/test.fetchTradingFee.js +18 -0
- package/js/test/Exchange/test.fetchTradingFees.js +22 -0
- package/js/test/Exchange/test.fetchTransactions.js +31 -0
- package/js/test/Exchange/test.fetchWithdrawals.js +31 -0
- package/js/test/Exchange/test.ledgerItem.js +46 -0
- package/js/test/Exchange/test.leverageTier.js +33 -0
- package/js/test/Exchange/test.loadMarkets.js +35 -0
- package/js/test/Exchange/test.market.js +129 -0
- package/js/test/Exchange/test.ohlcv.js +33 -0
- package/js/test/Exchange/test.order.js +62 -0
- package/js/test/Exchange/test.orderbook.js +61 -0
- package/js/test/Exchange/test.position.js +21 -0
- package/js/test/Exchange/test.throttle.js +94 -0
- package/js/test/Exchange/test.ticker.js +95 -0
- package/js/test/Exchange/test.trade.js +68 -0
- package/js/test/Exchange/test.tradingFee.js +34 -0
- package/js/test/Exchange/test.transaction.js +35 -0
- package/js/test/base/.eslintrc +38 -0
- package/js/test/base/functions/test.crypto.js +110 -0
- package/js/test/base/functions/test.datetime.js +62 -0
- package/js/test/base/functions/test.generic.js +152 -0
- package/js/test/base/functions/test.number.js +362 -0
- package/js/test/base/functions/test.time.js +56 -0
- package/js/test/base/functions/test.type.js +53 -0
- package/js/test/base/test.base.js +193 -0
- package/js/test/errors/test.InsufficientFunds.js +86 -0
- package/js/test/errors/test.InvalidNonce.js +64 -0
- package/js/test/errors/test.InvalidOrder.js +35 -0
- package/js/test/errors/test.OrderNotFound.js +39 -0
- package/js/test/test.js +426 -0
- package/js/test/test.timeout_hang.js +12 -0
- package/js/therock.js +1431 -0
- package/js/tidebit.js +632 -0
- package/js/tidex.js +939 -0
- package/js/timex.js +1283 -0
- package/js/upbit.js +1622 -0
- package/js/vcc.js +1353 -0
- package/js/wavesexchange.js +2185 -0
- package/js/wazirx.js +732 -0
- package/js/whitebit.js +1352 -0
- package/js/woo.js +1577 -0
- package/js/xena.js +1948 -0
- package/js/yobit.js +1129 -0
- package/js/zaif.js +647 -0
- package/js/zb.js +4088 -0
- package/js/zipmex.js +40 -0
- package/js/zonda.js +1497 -0
- package/multilang.sh +159 -0
- package/package.json +591 -0
- package/postinstall.js +103 -0
package/js/btcalpha.js
ADDED
@@ -0,0 +1,680 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
// ---------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const Exchange = require ('./base/Exchange');
|
6
|
+
const { ExchangeError, AuthenticationError, DDoSProtection, InvalidOrder, InsufficientFunds } = require ('./base/errors');
|
7
|
+
const Precise = require ('./base/Precise');
|
8
|
+
|
9
|
+
// ---------------------------------------------------------------------------
|
10
|
+
|
11
|
+
module.exports = class btcalpha extends Exchange {
|
12
|
+
describe () {
|
13
|
+
return this.deepExtend (super.describe (), {
|
14
|
+
'id': 'btcalpha',
|
15
|
+
'name': 'BTC-Alpha',
|
16
|
+
'countries': [ 'US' ],
|
17
|
+
'version': 'v1',
|
18
|
+
'has': {
|
19
|
+
'CORS': undefined,
|
20
|
+
'spot': true,
|
21
|
+
'margin': false,
|
22
|
+
'swap': false,
|
23
|
+
'future': false,
|
24
|
+
'option': false,
|
25
|
+
'addMargin': false,
|
26
|
+
'cancelOrder': true,
|
27
|
+
'createOrder': true,
|
28
|
+
'createReduceOnlyOrder': false,
|
29
|
+
'fetchBalance': true,
|
30
|
+
'fetchBorrowRate': false,
|
31
|
+
'fetchBorrowRateHistories': false,
|
32
|
+
'fetchBorrowRateHistory': false,
|
33
|
+
'fetchBorrowRates': false,
|
34
|
+
'fetchBorrowRatesPerSymbol': false,
|
35
|
+
'fetchClosedOrders': true,
|
36
|
+
'fetchDeposit': false,
|
37
|
+
'fetchDeposits': true,
|
38
|
+
'fetchFundingHistory': false,
|
39
|
+
'fetchFundingRate': false,
|
40
|
+
'fetchFundingRateHistory': false,
|
41
|
+
'fetchFundingRates': false,
|
42
|
+
'fetchIndexOHLCV': false,
|
43
|
+
'fetchLeverage': false,
|
44
|
+
'fetchMarkets': true,
|
45
|
+
'fetchMarkOHLCV': false,
|
46
|
+
'fetchMyTrades': true,
|
47
|
+
'fetchOHLCV': true,
|
48
|
+
'fetchOpenOrders': true,
|
49
|
+
'fetchOrder': true,
|
50
|
+
'fetchOrderBook': true,
|
51
|
+
'fetchOrders': true,
|
52
|
+
'fetchPosition': false,
|
53
|
+
'fetchPositions': false,
|
54
|
+
'fetchPositionsRisk': false,
|
55
|
+
'fetchPremiumIndexOHLCV': false,
|
56
|
+
'fetchTicker': undefined,
|
57
|
+
'fetchTrades': true,
|
58
|
+
'fetchTradingFee': false,
|
59
|
+
'fetchTradingFees': false,
|
60
|
+
'fetchTransfer': false,
|
61
|
+
'fetchTransfers': false,
|
62
|
+
'fetchWithdrawal': false,
|
63
|
+
'fetchWithdrawals': true,
|
64
|
+
'reduceMargin': false,
|
65
|
+
'setLeverage': false,
|
66
|
+
'setMarginMode': false,
|
67
|
+
'setPositionMode': false,
|
68
|
+
'transfer': false,
|
69
|
+
'withdraw': false,
|
70
|
+
},
|
71
|
+
'timeframes': {
|
72
|
+
'1m': '1',
|
73
|
+
'5m': '5',
|
74
|
+
'15m': '15',
|
75
|
+
'30m': '30',
|
76
|
+
'1h': '60',
|
77
|
+
'4h': '240',
|
78
|
+
'1d': 'D',
|
79
|
+
},
|
80
|
+
'urls': {
|
81
|
+
'logo': 'https://user-images.githubusercontent.com/1294454/42625213-dabaa5da-85cf-11e8-8f99-aa8f8f7699f0.jpg',
|
82
|
+
'api': 'https://btc-alpha.com/api',
|
83
|
+
'www': 'https://btc-alpha.com',
|
84
|
+
'doc': 'https://btc-alpha.github.io/api-docs',
|
85
|
+
'fees': 'https://btc-alpha.com/fees/',
|
86
|
+
'referral': 'https://btc-alpha.com/?r=123788',
|
87
|
+
},
|
88
|
+
'api': {
|
89
|
+
'public': {
|
90
|
+
'get': [
|
91
|
+
'currencies/',
|
92
|
+
'pairs/',
|
93
|
+
'orderbook/{pair_name}/',
|
94
|
+
'exchanges/',
|
95
|
+
'charts/{pair}/{type}/chart/',
|
96
|
+
],
|
97
|
+
},
|
98
|
+
'private': {
|
99
|
+
'get': [
|
100
|
+
'wallets/',
|
101
|
+
'orders/own/',
|
102
|
+
'order/{id}/',
|
103
|
+
'exchanges/own/',
|
104
|
+
'deposits/',
|
105
|
+
'withdraws/',
|
106
|
+
],
|
107
|
+
'post': [
|
108
|
+
'order/',
|
109
|
+
'order-cancel/',
|
110
|
+
],
|
111
|
+
},
|
112
|
+
},
|
113
|
+
'fees': {
|
114
|
+
'trading': {
|
115
|
+
'maker': this.parseNumber ('0.002'),
|
116
|
+
'taker': this.parseNumber ('0.002'),
|
117
|
+
},
|
118
|
+
'funding': {
|
119
|
+
'withdraw': {},
|
120
|
+
},
|
121
|
+
},
|
122
|
+
'commonCurrencies': {
|
123
|
+
'CBC': 'Cashbery',
|
124
|
+
},
|
125
|
+
'exceptions': {
|
126
|
+
'exact': {},
|
127
|
+
'broad': {
|
128
|
+
'Out of balance': InsufficientFunds, // {"date":1570599531.4814300537,"error":"Out of balance -9.99243661 BTC"}
|
129
|
+
},
|
130
|
+
},
|
131
|
+
});
|
132
|
+
}
|
133
|
+
|
134
|
+
async fetchMarkets (params = {}) {
|
135
|
+
const response = await this.publicGetPairs (params);
|
136
|
+
//
|
137
|
+
// [
|
138
|
+
// {
|
139
|
+
// "name": "1INCH_USDT",
|
140
|
+
// "currency1": "1INCH",
|
141
|
+
// "currency2": "USDT",
|
142
|
+
// "price_precision": 4,
|
143
|
+
// "amount_precision": 2,
|
144
|
+
// "minimum_order_size": "0.01000000",
|
145
|
+
// "maximum_order_size": "900000.00000000",
|
146
|
+
// "minimum_order_value": "10.00000000",
|
147
|
+
// "liquidity_type": 10
|
148
|
+
// },
|
149
|
+
// ]
|
150
|
+
//
|
151
|
+
const result = [];
|
152
|
+
for (let i = 0; i < response.length; i++) {
|
153
|
+
const market = response[i];
|
154
|
+
const id = this.safeString (market, 'name');
|
155
|
+
const baseId = this.safeString (market, 'currency1');
|
156
|
+
const quoteId = this.safeString (market, 'currency2');
|
157
|
+
const base = this.safeCurrencyCode (baseId);
|
158
|
+
const quote = this.safeCurrencyCode (quoteId);
|
159
|
+
const pricePrecision = this.safeString (market, 'price_precision');
|
160
|
+
const priceLimit = this.parsePrecision (pricePrecision);
|
161
|
+
const amountLimit = this.safeString (market, 'minimum_order_size');
|
162
|
+
result.push ({
|
163
|
+
'id': id,
|
164
|
+
'symbol': base + '/' + quote,
|
165
|
+
'base': base,
|
166
|
+
'quote': quote,
|
167
|
+
'settle': undefined,
|
168
|
+
'baseId': baseId,
|
169
|
+
'quoteId': quoteId,
|
170
|
+
'settleId': undefined,
|
171
|
+
'type': 'spot',
|
172
|
+
'spot': true,
|
173
|
+
'margin': false,
|
174
|
+
'swap': false,
|
175
|
+
'future': false,
|
176
|
+
'option': false,
|
177
|
+
'active': true,
|
178
|
+
'contract': false,
|
179
|
+
'linear': undefined,
|
180
|
+
'inverse': undefined,
|
181
|
+
'contractSize': undefined,
|
182
|
+
'expiry': undefined,
|
183
|
+
'expiryDatetime': undefined,
|
184
|
+
'strike': undefined,
|
185
|
+
'optionType': undefined,
|
186
|
+
'precision': {
|
187
|
+
'amount': parseInt ('8'),
|
188
|
+
'price': parseInt (pricePrecision),
|
189
|
+
},
|
190
|
+
'limits': {
|
191
|
+
'leverage': {
|
192
|
+
'min': undefined,
|
193
|
+
'max': undefined,
|
194
|
+
},
|
195
|
+
'amount': {
|
196
|
+
'min': this.parseNumber (amountLimit),
|
197
|
+
'max': this.safeNumber (market, 'maximum_order_size'),
|
198
|
+
},
|
199
|
+
'price': {
|
200
|
+
'min': this.parseNumber (priceLimit),
|
201
|
+
'max': undefined,
|
202
|
+
},
|
203
|
+
'cost': {
|
204
|
+
'min': this.parseNumber (Precise.stringMul (priceLimit, amountLimit)),
|
205
|
+
'max': undefined,
|
206
|
+
},
|
207
|
+
},
|
208
|
+
'info': market,
|
209
|
+
});
|
210
|
+
}
|
211
|
+
return result;
|
212
|
+
}
|
213
|
+
|
214
|
+
async fetchOrderBook (symbol, limit = undefined, params = {}) {
|
215
|
+
await this.loadMarkets ();
|
216
|
+
const request = {
|
217
|
+
'pair_name': this.marketId (symbol),
|
218
|
+
};
|
219
|
+
if (limit) {
|
220
|
+
request['limit_sell'] = limit;
|
221
|
+
request['limit_buy'] = limit;
|
222
|
+
}
|
223
|
+
const response = await this.publicGetOrderbookPairName (this.extend (request, params));
|
224
|
+
return this.parseOrderBook (response, symbol, undefined, 'buy', 'sell', 'price', 'amount');
|
225
|
+
}
|
226
|
+
|
227
|
+
parseBidsAsks (bidasks, priceKey = 0, amountKey = 1) {
|
228
|
+
const result = [];
|
229
|
+
for (let i = 0; i < bidasks.length; i++) {
|
230
|
+
const bidask = bidasks[i];
|
231
|
+
if (bidask) {
|
232
|
+
result.push (this.parseBidAsk (bidask, priceKey, amountKey));
|
233
|
+
}
|
234
|
+
}
|
235
|
+
return result;
|
236
|
+
}
|
237
|
+
|
238
|
+
parseTrade (trade, market = undefined) {
|
239
|
+
//
|
240
|
+
// fetchTrades (public)
|
241
|
+
//
|
242
|
+
// {
|
243
|
+
// "id": "202203440",
|
244
|
+
// "timestamp": "1637856276.264215",
|
245
|
+
// "pair": "AAVE_USDT",
|
246
|
+
// "price": "320.79900000",
|
247
|
+
// "amount": "0.05000000",
|
248
|
+
// "type": "buy"
|
249
|
+
// }
|
250
|
+
//
|
251
|
+
// fetchMyTrades (private)
|
252
|
+
//
|
253
|
+
// {
|
254
|
+
// "id": "202203440",
|
255
|
+
// "timestamp": "1637856276.264215",
|
256
|
+
// "pair": "AAVE_USDT",
|
257
|
+
// "price": "320.79900000",
|
258
|
+
// "amount": "0.05000000",
|
259
|
+
// "type": "buy",
|
260
|
+
// "my_side": "buy"
|
261
|
+
// }
|
262
|
+
//
|
263
|
+
const marketId = this.safeString (trade, 'pair');
|
264
|
+
market = this.safeMarket (marketId, market, '_');
|
265
|
+
const timestamp = this.safeTimestamp (trade, 'timestamp');
|
266
|
+
const priceString = this.safeString (trade, 'price');
|
267
|
+
const amountString = this.safeString (trade, 'amount');
|
268
|
+
const id = this.safeString (trade, 'id');
|
269
|
+
const side = this.safeString2 (trade, 'my_side', 'type');
|
270
|
+
return this.safeTrade ({
|
271
|
+
'id': id,
|
272
|
+
'info': trade,
|
273
|
+
'timestamp': timestamp,
|
274
|
+
'datetime': this.iso8601 (timestamp),
|
275
|
+
'symbol': market['symbol'],
|
276
|
+
'order': id,
|
277
|
+
'type': 'limit',
|
278
|
+
'side': side,
|
279
|
+
'takerOrMaker': undefined,
|
280
|
+
'price': priceString,
|
281
|
+
'amount': amountString,
|
282
|
+
'cost': undefined,
|
283
|
+
'fee': undefined,
|
284
|
+
}, market);
|
285
|
+
}
|
286
|
+
|
287
|
+
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
|
288
|
+
await this.loadMarkets ();
|
289
|
+
let market = undefined;
|
290
|
+
const request = {};
|
291
|
+
if (symbol !== undefined) {
|
292
|
+
market = this.market (symbol);
|
293
|
+
request['pair'] = market['id'];
|
294
|
+
}
|
295
|
+
if (limit !== undefined) {
|
296
|
+
request['limit'] = limit;
|
297
|
+
}
|
298
|
+
const trades = await this.publicGetExchanges (this.extend (request, params));
|
299
|
+
return this.parseTrades (trades, market, since, limit);
|
300
|
+
}
|
301
|
+
|
302
|
+
async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
|
303
|
+
await this.loadMarkets ();
|
304
|
+
const response = await this.privateGetDeposits (params);
|
305
|
+
//
|
306
|
+
// [
|
307
|
+
// {
|
308
|
+
// "timestamp": 1485363039.18359,
|
309
|
+
// "id": 317,
|
310
|
+
// "currency": "BTC",
|
311
|
+
// "amount": 530.00000000
|
312
|
+
// }
|
313
|
+
// ]
|
314
|
+
//
|
315
|
+
return this.parseTransactions (response, code, since, limit, { 'type': 'deposit' });
|
316
|
+
}
|
317
|
+
|
318
|
+
async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
|
319
|
+
await this.loadMarkets ();
|
320
|
+
let currency = undefined;
|
321
|
+
const request = {};
|
322
|
+
if (code !== undefined) {
|
323
|
+
currency = this.currency (code);
|
324
|
+
request['currency_id'] = currency['id'];
|
325
|
+
}
|
326
|
+
const response = await this.privateGetWithdraws (this.extend (request, params));
|
327
|
+
//
|
328
|
+
// [
|
329
|
+
// {
|
330
|
+
// "id": 403,
|
331
|
+
// "timestamp": 1485363466.868539,
|
332
|
+
// "currency": "BTC",
|
333
|
+
// "amount": 0.53000000,
|
334
|
+
// "status": 20
|
335
|
+
// }
|
336
|
+
// ]
|
337
|
+
//
|
338
|
+
return this.parseTransactions (response, code, since, limit, { 'type': 'withdrawal' });
|
339
|
+
}
|
340
|
+
|
341
|
+
parseTransaction (transaction, currency = undefined) {
|
342
|
+
//
|
343
|
+
// deposit
|
344
|
+
// {
|
345
|
+
// "timestamp": 1485363039.18359,
|
346
|
+
// "id": 317,
|
347
|
+
// "currency": "BTC",
|
348
|
+
// "amount": 530.00000000
|
349
|
+
// }
|
350
|
+
//
|
351
|
+
// withdrawal
|
352
|
+
// {
|
353
|
+
// "id": 403,
|
354
|
+
// "timestamp": 1485363466.868539,
|
355
|
+
// "currency": "BTC",
|
356
|
+
// "amount": 0.53000000,
|
357
|
+
// "status": 20
|
358
|
+
// }
|
359
|
+
//
|
360
|
+
let timestamp = this.safeString (transaction, 'timestamp');
|
361
|
+
timestamp = Precise.stringMul (timestamp, '1000');
|
362
|
+
const currencyId = this.safeString (transaction, 'currency');
|
363
|
+
const statusId = this.safeString (transaction, 'status');
|
364
|
+
return {
|
365
|
+
'id': this.safeString (transaction, 'id'),
|
366
|
+
'info': transaction,
|
367
|
+
'timestamp': this.parseNumber (timestamp),
|
368
|
+
'datetime': this.iso8601 (timestamp),
|
369
|
+
'network': undefined,
|
370
|
+
'address': undefined,
|
371
|
+
'addressTo': undefined,
|
372
|
+
'addressFrom': undefined,
|
373
|
+
'tag': undefined,
|
374
|
+
'tagTo': undefined,
|
375
|
+
'tagFrom': undefined,
|
376
|
+
'currency': this.safeCurrencyCode (currencyId, currency),
|
377
|
+
'amount': this.safeNumber (transaction, 'amount'),
|
378
|
+
'txid': undefined,
|
379
|
+
'type': undefined,
|
380
|
+
'status': this.parseTransactionStatus (statusId),
|
381
|
+
'comment': undefined,
|
382
|
+
'fee': undefined,
|
383
|
+
'updated': undefined,
|
384
|
+
};
|
385
|
+
}
|
386
|
+
|
387
|
+
parseTransactionStatus (status) {
|
388
|
+
const statuses = {
|
389
|
+
'10': 'pending', // New
|
390
|
+
'20': 'pending', // Verified, waiting for approving
|
391
|
+
'30': 'ok', // Approved by moderator
|
392
|
+
'40': 'failed', // Refused by moderator. See your email for more details
|
393
|
+
'50': 'canceled', // Cancelled by user
|
394
|
+
};
|
395
|
+
return this.safeString (statuses, status, status);
|
396
|
+
}
|
397
|
+
|
398
|
+
parseOHLCV (ohlcv, market = undefined) {
|
399
|
+
//
|
400
|
+
// {
|
401
|
+
// "time":1591296000,
|
402
|
+
// "open":0.024746,
|
403
|
+
// "close":0.024728,
|
404
|
+
// "low":0.024728,
|
405
|
+
// "high":0.024753,
|
406
|
+
// "volume":16.624
|
407
|
+
// }
|
408
|
+
//
|
409
|
+
return [
|
410
|
+
this.safeTimestamp (ohlcv, 'time'),
|
411
|
+
this.safeNumber (ohlcv, 'open'),
|
412
|
+
this.safeNumber (ohlcv, 'high'),
|
413
|
+
this.safeNumber (ohlcv, 'low'),
|
414
|
+
this.safeNumber (ohlcv, 'close'),
|
415
|
+
this.safeNumber (ohlcv, 'volume'),
|
416
|
+
];
|
417
|
+
}
|
418
|
+
|
419
|
+
async fetchOHLCV (symbol, timeframe = '5m', since = undefined, limit = undefined, params = {}) {
|
420
|
+
await this.loadMarkets ();
|
421
|
+
const market = this.market (symbol);
|
422
|
+
const request = {
|
423
|
+
'pair': market['id'],
|
424
|
+
'type': this.timeframes[timeframe],
|
425
|
+
};
|
426
|
+
if (limit !== undefined) {
|
427
|
+
request['limit'] = limit;
|
428
|
+
}
|
429
|
+
if (since !== undefined) {
|
430
|
+
request['since'] = parseInt (since / 1000);
|
431
|
+
}
|
432
|
+
const response = await this.publicGetChartsPairTypeChart (this.extend (request, params));
|
433
|
+
//
|
434
|
+
// [
|
435
|
+
// {"time":1591296000,"open":0.024746,"close":0.024728,"low":0.024728,"high":0.024753,"volume":16.624},
|
436
|
+
// {"time":1591295700,"open":0.024718,"close":0.02475,"low":0.024711,"high":0.02475,"volume":31.645},
|
437
|
+
// {"time":1591295400,"open":0.024721,"close":0.024717,"low":0.024711,"high":0.02473,"volume":65.071}
|
438
|
+
// ]
|
439
|
+
//
|
440
|
+
return this.parseOHLCVs (response, market, timeframe, since, limit);
|
441
|
+
}
|
442
|
+
|
443
|
+
parseBalance (response) {
|
444
|
+
const result = { 'info': response };
|
445
|
+
for (let i = 0; i < response.length; i++) {
|
446
|
+
const balance = response[i];
|
447
|
+
const currencyId = this.safeString (balance, 'currency');
|
448
|
+
const code = this.safeCurrencyCode (currencyId);
|
449
|
+
const account = this.account ();
|
450
|
+
account['used'] = this.safeString (balance, 'reserve');
|
451
|
+
account['total'] = this.safeString (balance, 'balance');
|
452
|
+
result[code] = account;
|
453
|
+
}
|
454
|
+
return this.safeBalance (result);
|
455
|
+
}
|
456
|
+
|
457
|
+
async fetchBalance (params = {}) {
|
458
|
+
await this.loadMarkets ();
|
459
|
+
const response = await this.privateGetWallets (params);
|
460
|
+
return this.parseBalance (response);
|
461
|
+
}
|
462
|
+
|
463
|
+
parseOrderStatus (status) {
|
464
|
+
const statuses = {
|
465
|
+
'1': 'open',
|
466
|
+
'2': 'canceled',
|
467
|
+
'3': 'closed',
|
468
|
+
};
|
469
|
+
return this.safeString (statuses, status, status);
|
470
|
+
}
|
471
|
+
|
472
|
+
parseOrder (order, market = undefined) {
|
473
|
+
//
|
474
|
+
// fetchClosedOrders / fetchOrder
|
475
|
+
// {
|
476
|
+
// "id": "923763073",
|
477
|
+
// "date": "1635451090368",
|
478
|
+
// "type": "sell",
|
479
|
+
// "pair": "XRP_USDT",
|
480
|
+
// "price": "1.00000000",
|
481
|
+
// "amount": "0.00000000",
|
482
|
+
// "status": "3",
|
483
|
+
// "amount_filled": "10.00000000",
|
484
|
+
// "amount_original": "10.0"
|
485
|
+
// "trades": [],
|
486
|
+
// }
|
487
|
+
//
|
488
|
+
// createOrder
|
489
|
+
// {
|
490
|
+
// "success": true,
|
491
|
+
// "date": "1635451754.497541",
|
492
|
+
// "type": "sell",
|
493
|
+
// "oid": "923776755",
|
494
|
+
// "price": "1.0",
|
495
|
+
// "amount": "10.0",
|
496
|
+
// "amount_filled": "0.0",
|
497
|
+
// "amount_original": "10.0",
|
498
|
+
// "trades": []
|
499
|
+
// }
|
500
|
+
//
|
501
|
+
const marketId = this.safeString (order, 'pair');
|
502
|
+
market = this.safeMarket (marketId, market, '_');
|
503
|
+
const symbol = market['symbol'];
|
504
|
+
const success = this.safeValue (order, 'success', false);
|
505
|
+
let timestamp = undefined;
|
506
|
+
if (success) {
|
507
|
+
timestamp = this.safeTimestamp (order, 'date');
|
508
|
+
} else {
|
509
|
+
timestamp = this.safeInteger (order, 'date');
|
510
|
+
}
|
511
|
+
const price = this.safeString (order, 'price');
|
512
|
+
const remaining = this.safeString (order, 'amount');
|
513
|
+
const filled = this.safeString (order, 'amount_filled');
|
514
|
+
const amount = this.safeString (order, 'amount_original');
|
515
|
+
const status = this.parseOrderStatus (this.safeString (order, 'status'));
|
516
|
+
const id = this.safeString2 (order, 'oid', 'id');
|
517
|
+
const trades = this.safeValue (order, 'trades');
|
518
|
+
const side = this.safeString2 (order, 'my_side', 'type');
|
519
|
+
return this.safeOrder ({
|
520
|
+
'id': id,
|
521
|
+
'clientOrderId': undefined,
|
522
|
+
'datetime': this.iso8601 (timestamp),
|
523
|
+
'timestamp': timestamp,
|
524
|
+
'status': status,
|
525
|
+
'symbol': symbol,
|
526
|
+
'type': 'limit',
|
527
|
+
'timeInForce': undefined,
|
528
|
+
'postOnly': undefined,
|
529
|
+
'side': side,
|
530
|
+
'price': price,
|
531
|
+
'stopPrice': undefined,
|
532
|
+
'cost': undefined,
|
533
|
+
'amount': amount,
|
534
|
+
'filled': filled,
|
535
|
+
'remaining': remaining,
|
536
|
+
'trades': trades,
|
537
|
+
'fee': undefined,
|
538
|
+
'info': order,
|
539
|
+
'lastTradeTimestamp': undefined,
|
540
|
+
'average': undefined,
|
541
|
+
}, market);
|
542
|
+
}
|
543
|
+
|
544
|
+
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
|
545
|
+
await this.loadMarkets ();
|
546
|
+
const market = this.market (symbol);
|
547
|
+
const request = {
|
548
|
+
'pair': market['id'],
|
549
|
+
'type': side,
|
550
|
+
'amount': amount,
|
551
|
+
'price': this.priceToPrecision (symbol, price),
|
552
|
+
};
|
553
|
+
const response = await this.privatePostOrder (this.extend (request, params));
|
554
|
+
if (!response['success']) {
|
555
|
+
throw new InvalidOrder (this.id + ' ' + this.json (response));
|
556
|
+
}
|
557
|
+
const order = this.parseOrder (response, market);
|
558
|
+
amount = (order['amount'] > 0) ? order['amount'] : amount;
|
559
|
+
return this.extend (order, {
|
560
|
+
'amount': amount,
|
561
|
+
});
|
562
|
+
}
|
563
|
+
|
564
|
+
async cancelOrder (id, symbol = undefined, params = {}) {
|
565
|
+
const request = {
|
566
|
+
'order': id,
|
567
|
+
};
|
568
|
+
const response = await this.privatePostOrderCancel (this.extend (request, params));
|
569
|
+
return response;
|
570
|
+
}
|
571
|
+
|
572
|
+
async fetchOrder (id, symbol = undefined, params = {}) {
|
573
|
+
await this.loadMarkets ();
|
574
|
+
const request = {
|
575
|
+
'id': id,
|
576
|
+
};
|
577
|
+
const order = await this.privateGetOrderId (this.extend (request, params));
|
578
|
+
return this.parseOrder (order);
|
579
|
+
}
|
580
|
+
|
581
|
+
async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
582
|
+
await this.loadMarkets ();
|
583
|
+
const request = {};
|
584
|
+
let market = undefined;
|
585
|
+
if (symbol !== undefined) {
|
586
|
+
market = this.market (symbol);
|
587
|
+
request['pair'] = market['id'];
|
588
|
+
}
|
589
|
+
if (limit !== undefined) {
|
590
|
+
request['limit'] = limit;
|
591
|
+
}
|
592
|
+
const orders = await this.privateGetOrdersOwn (this.extend (request, params));
|
593
|
+
return this.parseOrders (orders, market, since, limit);
|
594
|
+
}
|
595
|
+
|
596
|
+
async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
597
|
+
const request = {
|
598
|
+
'status': '1',
|
599
|
+
};
|
600
|
+
return await this.fetchOrders (symbol, since, limit, this.extend (request, params));
|
601
|
+
}
|
602
|
+
|
603
|
+
async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
604
|
+
const request = {
|
605
|
+
'status': '3',
|
606
|
+
};
|
607
|
+
return await this.fetchOrders (symbol, since, limit, this.extend (request, params));
|
608
|
+
}
|
609
|
+
|
610
|
+
async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
611
|
+
await this.loadMarkets ();
|
612
|
+
const request = {};
|
613
|
+
if (symbol !== undefined) {
|
614
|
+
const market = this.market (symbol);
|
615
|
+
request['pair'] = market['id'];
|
616
|
+
}
|
617
|
+
if (limit !== undefined) {
|
618
|
+
request['limit'] = limit;
|
619
|
+
}
|
620
|
+
const trades = await this.privateGetExchangesOwn (this.extend (request, params));
|
621
|
+
return this.parseTrades (trades, undefined, since, limit);
|
622
|
+
}
|
623
|
+
|
624
|
+
nonce () {
|
625
|
+
return this.milliseconds ();
|
626
|
+
}
|
627
|
+
|
628
|
+
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
629
|
+
const query = this.urlencode (this.keysort (this.omit (params, this.extractParams (path))));
|
630
|
+
let url = this.urls['api'] + '/';
|
631
|
+
if (path !== 'charts/{pair}/{type}/chart/') {
|
632
|
+
url += 'v1/';
|
633
|
+
}
|
634
|
+
url += this.implodeParams (path, params);
|
635
|
+
headers = { 'Accept': 'application/json' };
|
636
|
+
if (api === 'public') {
|
637
|
+
if (query.length) {
|
638
|
+
url += '?' + query;
|
639
|
+
}
|
640
|
+
} else {
|
641
|
+
this.checkRequiredCredentials ();
|
642
|
+
let payload = this.apiKey;
|
643
|
+
if (method === 'POST') {
|
644
|
+
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
645
|
+
body = query;
|
646
|
+
payload += body;
|
647
|
+
} else if (query.length) {
|
648
|
+
url += '?' + query;
|
649
|
+
}
|
650
|
+
headers['X-KEY'] = this.apiKey;
|
651
|
+
headers['X-SIGN'] = this.hmac (this.encode (payload), this.encode (this.secret));
|
652
|
+
headers['X-NONCE'] = this.nonce ().toString ();
|
653
|
+
}
|
654
|
+
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
655
|
+
}
|
656
|
+
|
657
|
+
handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
658
|
+
if (response === undefined) {
|
659
|
+
return; // fallback to default error handler
|
660
|
+
}
|
661
|
+
//
|
662
|
+
// {"date":1570599531.4814300537,"error":"Out of balance -9.99243661 BTC"}
|
663
|
+
//
|
664
|
+
const error = this.safeString (response, 'error');
|
665
|
+
const feedback = this.id + ' ' + body;
|
666
|
+
if (error !== undefined) {
|
667
|
+
this.throwExactlyMatchedException (this.exceptions['exact'], error, feedback);
|
668
|
+
this.throwBroadlyMatchedException (this.exceptions['broad'], error, feedback);
|
669
|
+
}
|
670
|
+
if (code === 401 || code === 403) {
|
671
|
+
throw new AuthenticationError (feedback);
|
672
|
+
} else if (code === 429) {
|
673
|
+
throw new DDoSProtection (feedback);
|
674
|
+
}
|
675
|
+
if (code < 400) {
|
676
|
+
return;
|
677
|
+
}
|
678
|
+
throw new ExchangeError (feedback);
|
679
|
+
}
|
680
|
+
};
|