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/btcmarkets.js
ADDED
@@ -0,0 +1,1022 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
// ---------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const Exchange = require ('./base/Exchange');
|
6
|
+
const { ArgumentsRequired, ExchangeError, OrderNotFound, InvalidOrder, InsufficientFunds, DDoSProtection, BadRequest } = require ('./base/errors');
|
7
|
+
|
8
|
+
// ---------------------------------------------------------------------------
|
9
|
+
|
10
|
+
module.exports = class btcmarkets extends Exchange {
|
11
|
+
describe () {
|
12
|
+
return this.deepExtend (super.describe (), {
|
13
|
+
'id': 'btcmarkets',
|
14
|
+
'name': 'BTC Markets',
|
15
|
+
'countries': [ 'AU' ], // Australia
|
16
|
+
'rateLimit': 1000, // market data cached for 1 second (trades cached for 2 seconds)
|
17
|
+
'version': 'v3',
|
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
|
+
'cancelOrders': true,
|
28
|
+
'createOrder': true,
|
29
|
+
'createReduceOnlyOrder': false,
|
30
|
+
'fetchBalance': true,
|
31
|
+
'fetchBorrowRate': false,
|
32
|
+
'fetchBorrowRateHistories': false,
|
33
|
+
'fetchBorrowRateHistory': false,
|
34
|
+
'fetchBorrowRates': false,
|
35
|
+
'fetchBorrowRatesPerSymbol': false,
|
36
|
+
'fetchClosedOrders': 'emulated',
|
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': true,
|
57
|
+
'fetchTime': true,
|
58
|
+
'fetchTrades': true,
|
59
|
+
'fetchTransactions': true,
|
60
|
+
'fetchWithdrawals': true,
|
61
|
+
'reduceMargin': false,
|
62
|
+
'setLeverage': false,
|
63
|
+
'setMarginMode': false,
|
64
|
+
'setPositionMode': false,
|
65
|
+
},
|
66
|
+
'urls': {
|
67
|
+
'logo': 'https://user-images.githubusercontent.com/51840849/89731817-b3fb8480-da52-11ea-817f-783b08aaf32b.jpg',
|
68
|
+
'api': {
|
69
|
+
'public': 'https://api.btcmarkets.net',
|
70
|
+
'private': 'https://api.btcmarkets.net',
|
71
|
+
},
|
72
|
+
'www': 'https://btcmarkets.net',
|
73
|
+
'doc': [
|
74
|
+
'https://api.btcmarkets.net/doc/v3',
|
75
|
+
'https://github.com/BTCMarkets/API',
|
76
|
+
],
|
77
|
+
},
|
78
|
+
'api': {
|
79
|
+
'public': {
|
80
|
+
'get': [
|
81
|
+
'markets',
|
82
|
+
'markets/{marketId}/ticker',
|
83
|
+
'markets/{marketId}/trades',
|
84
|
+
'markets/{marketId}/orderbook',
|
85
|
+
'markets/{marketId}/candles',
|
86
|
+
'markets/tickers',
|
87
|
+
'markets/orderbooks',
|
88
|
+
'time',
|
89
|
+
],
|
90
|
+
},
|
91
|
+
'private': {
|
92
|
+
'get': [
|
93
|
+
'orders',
|
94
|
+
'orders/{id}',
|
95
|
+
'batchorders/{ids}',
|
96
|
+
'trades',
|
97
|
+
'trades/{id}',
|
98
|
+
'withdrawals',
|
99
|
+
'withdrawals/{id}',
|
100
|
+
'deposits',
|
101
|
+
'deposits/{id}',
|
102
|
+
'transfers',
|
103
|
+
'transfers/{id}',
|
104
|
+
'addresses',
|
105
|
+
'withdrawal-fees',
|
106
|
+
'assets',
|
107
|
+
'accounts/me/trading-fees',
|
108
|
+
'accounts/me/withdrawal-limits',
|
109
|
+
'accounts/me/balances',
|
110
|
+
'accounts/me/transactions',
|
111
|
+
'reports/{id}',
|
112
|
+
],
|
113
|
+
'post': [
|
114
|
+
'orders',
|
115
|
+
'batchorders',
|
116
|
+
'withdrawals',
|
117
|
+
'reports',
|
118
|
+
],
|
119
|
+
'delete': [
|
120
|
+
'orders',
|
121
|
+
'orders/{id}',
|
122
|
+
'batchorders/{ids}',
|
123
|
+
],
|
124
|
+
'put': [
|
125
|
+
'orders/{id}',
|
126
|
+
],
|
127
|
+
},
|
128
|
+
},
|
129
|
+
'timeframes': {
|
130
|
+
'1m': '1m',
|
131
|
+
'1h': '1h',
|
132
|
+
'1d': '1d',
|
133
|
+
},
|
134
|
+
'exceptions': {
|
135
|
+
'3': InvalidOrder,
|
136
|
+
'6': DDoSProtection,
|
137
|
+
'InsufficientFund': InsufficientFunds,
|
138
|
+
'InvalidPrice': InvalidOrder,
|
139
|
+
'InvalidAmount': InvalidOrder,
|
140
|
+
'MissingArgument': InvalidOrder,
|
141
|
+
'OrderAlreadyCancelled': InvalidOrder,
|
142
|
+
'OrderNotFound': OrderNotFound,
|
143
|
+
'OrderStatusIsFinal': InvalidOrder,
|
144
|
+
'InvalidPaginationParameter': BadRequest,
|
145
|
+
},
|
146
|
+
'fees': {
|
147
|
+
'percentage': true,
|
148
|
+
'tierBased': true,
|
149
|
+
'maker': this.parseNumber ('-0.0005'),
|
150
|
+
'taker': this.parseNumber ('0.0020'),
|
151
|
+
},
|
152
|
+
'options': {
|
153
|
+
'fees': {
|
154
|
+
'AUD': {
|
155
|
+
'maker': 0.85 / 100,
|
156
|
+
'taker': 0.85 / 100,
|
157
|
+
},
|
158
|
+
},
|
159
|
+
},
|
160
|
+
});
|
161
|
+
}
|
162
|
+
|
163
|
+
async fetchTransactionsWithMethod (method, code = undefined, since = undefined, limit = undefined, params = {}) {
|
164
|
+
await this.loadMarkets ();
|
165
|
+
const request = {};
|
166
|
+
if (limit !== undefined) {
|
167
|
+
request['limit'] = limit;
|
168
|
+
}
|
169
|
+
if (since !== undefined) {
|
170
|
+
request['after'] = since;
|
171
|
+
}
|
172
|
+
let currency = undefined;
|
173
|
+
if (code !== undefined) {
|
174
|
+
currency = this.currency (code);
|
175
|
+
}
|
176
|
+
const response = await this[method] (this.extend (request, params));
|
177
|
+
return this.parseTransactions (response, currency, since, limit);
|
178
|
+
}
|
179
|
+
|
180
|
+
async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) {
|
181
|
+
return await this.fetchTransactionsWithMethod ('privateGetTransfers', code, since, limit, params);
|
182
|
+
}
|
183
|
+
|
184
|
+
async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
|
185
|
+
return await this.fetchTransactionsWithMethod ('privateGetDeposits', code, since, limit, params);
|
186
|
+
}
|
187
|
+
|
188
|
+
async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
|
189
|
+
return await this.fetchTransactionsWithMethod ('privateGetWithdrawals', code, since, limit, params);
|
190
|
+
}
|
191
|
+
|
192
|
+
parseTransactionStatus (status) {
|
193
|
+
// todo: find more statuses
|
194
|
+
const statuses = {
|
195
|
+
'Complete': 'ok',
|
196
|
+
};
|
197
|
+
return this.safeString (statuses, status, status);
|
198
|
+
}
|
199
|
+
|
200
|
+
parseTransactionType (type) {
|
201
|
+
const statuses = {
|
202
|
+
'Withdraw': 'withdrawal',
|
203
|
+
'Deposit': 'deposit',
|
204
|
+
};
|
205
|
+
return this.safeString (statuses, type, type);
|
206
|
+
}
|
207
|
+
|
208
|
+
parseTransaction (transaction, currency = undefined) {
|
209
|
+
//
|
210
|
+
// {
|
211
|
+
// "id": "6500230339",
|
212
|
+
// "assetName": "XRP",
|
213
|
+
// "amount": "500",
|
214
|
+
// "type": "Deposit",
|
215
|
+
// "creationTime": "2020-07-27T07:52:08.640000Z",
|
216
|
+
// "status": "Complete",
|
217
|
+
// "description": "RIPPLE Deposit, XRP 500",
|
218
|
+
// "fee": "0",
|
219
|
+
// "lastUpdate": "2020-07-27T07:52:08.665000Z",
|
220
|
+
// "paymentDetail": {
|
221
|
+
// "txId": "lsjflsjdfljsd",
|
222
|
+
// "address": "kjasfkjsdf?dt=873874545"
|
223
|
+
// }
|
224
|
+
// }
|
225
|
+
//
|
226
|
+
// {
|
227
|
+
// "id": "500985282",
|
228
|
+
// "assetName": "BTC",
|
229
|
+
// "amount": "0.42570126",
|
230
|
+
// "type": "Withdraw",
|
231
|
+
// "creationTime": "2017-07-29T12:49:03.931000Z",
|
232
|
+
// "status": "Complete",
|
233
|
+
// "description": "BTC withdraw from [nick-btcmarkets@snowmonkey.co.uk] to Address: 1B9DsnSYQ54VMqFHVJYdGoLMCYzFwrQzsj amount: 0.42570126 fee: 0.00000000",
|
234
|
+
// "fee": "0.0005",
|
235
|
+
// "lastUpdate": "2017-07-29T12:52:20.676000Z",
|
236
|
+
// "paymentDetail": {
|
237
|
+
// "txId": "fkjdsfjsfljsdfl",
|
238
|
+
// "address": "a;daddjas;djas"
|
239
|
+
// }
|
240
|
+
// }
|
241
|
+
//
|
242
|
+
// {
|
243
|
+
// "id": "505102262",
|
244
|
+
// "assetName": "XRP",
|
245
|
+
// "amount": "979.836",
|
246
|
+
// "type": "Deposit",
|
247
|
+
// "creationTime": "2017-07-31T08:50:01.053000Z",
|
248
|
+
// "status": "Complete",
|
249
|
+
// "description": "Ripple Deposit, X 979.8360",
|
250
|
+
// "fee": "0",
|
251
|
+
// "lastUpdate": "2017-07-31T08:50:01.290000Z"
|
252
|
+
// }
|
253
|
+
//
|
254
|
+
const timestamp = this.parse8601 (this.safeString (transaction, 'creationTime'));
|
255
|
+
const lastUpdate = this.parse8601 (this.safeString (transaction, 'lastUpdate'));
|
256
|
+
let type = this.parseTransactionType (this.safeStringLower (transaction, 'type'));
|
257
|
+
if (type === 'withdraw') {
|
258
|
+
type = 'withdrawal';
|
259
|
+
}
|
260
|
+
const cryptoPaymentDetail = this.safeValue (transaction, 'paymentDetail', {});
|
261
|
+
const txid = this.safeString (cryptoPaymentDetail, 'txId');
|
262
|
+
let address = this.safeString (cryptoPaymentDetail, 'address');
|
263
|
+
let tag = undefined;
|
264
|
+
if (address !== undefined) {
|
265
|
+
const addressParts = address.split ('?dt=');
|
266
|
+
const numParts = addressParts.length;
|
267
|
+
if (numParts > 1) {
|
268
|
+
address = addressParts[0];
|
269
|
+
tag = addressParts[1];
|
270
|
+
}
|
271
|
+
}
|
272
|
+
const addressTo = address;
|
273
|
+
const tagTo = tag;
|
274
|
+
const addressFrom = undefined;
|
275
|
+
const tagFrom = undefined;
|
276
|
+
const fee = this.safeNumber (transaction, 'fee');
|
277
|
+
const status = this.parseTransactionStatus (this.safeString (transaction, 'status'));
|
278
|
+
const currencyId = this.safeString (transaction, 'assetName');
|
279
|
+
const code = this.safeCurrencyCode (currencyId);
|
280
|
+
let amount = this.safeNumber (transaction, 'amount');
|
281
|
+
if (fee) {
|
282
|
+
amount -= fee;
|
283
|
+
}
|
284
|
+
return {
|
285
|
+
'id': this.safeString (transaction, 'id'),
|
286
|
+
'txid': txid,
|
287
|
+
'timestamp': timestamp,
|
288
|
+
'datetime': this.iso8601 (timestamp),
|
289
|
+
'network': undefined,
|
290
|
+
'address': address,
|
291
|
+
'addressTo': addressTo,
|
292
|
+
'addressFrom': addressFrom,
|
293
|
+
'tag': tag,
|
294
|
+
'tagTo': tagTo,
|
295
|
+
'tagFrom': tagFrom,
|
296
|
+
'type': type,
|
297
|
+
'amount': amount,
|
298
|
+
'currency': code,
|
299
|
+
'status': status,
|
300
|
+
'updated': lastUpdate,
|
301
|
+
'fee': {
|
302
|
+
'currency': code,
|
303
|
+
'cost': fee,
|
304
|
+
},
|
305
|
+
'info': transaction,
|
306
|
+
};
|
307
|
+
}
|
308
|
+
|
309
|
+
async fetchMarkets (params = {}) {
|
310
|
+
const response = await this.publicGetMarkets (params);
|
311
|
+
//
|
312
|
+
// [
|
313
|
+
// {
|
314
|
+
// "marketId":"COMP-AUD",
|
315
|
+
// "baseAssetName":"COMP",
|
316
|
+
// "quoteAssetName":"AUD",
|
317
|
+
// "minOrderAmount":"0.00007",
|
318
|
+
// "maxOrderAmount":"1000000",
|
319
|
+
// "amountDecimals":"8",
|
320
|
+
// "priceDecimals":"2"
|
321
|
+
// }
|
322
|
+
// ]
|
323
|
+
//
|
324
|
+
const result = [];
|
325
|
+
for (let i = 0; i < response.length; i++) {
|
326
|
+
const market = response[i];
|
327
|
+
const baseId = this.safeString (market, 'baseAssetName');
|
328
|
+
const quoteId = this.safeString (market, 'quoteAssetName');
|
329
|
+
const id = this.safeString (market, 'marketId');
|
330
|
+
const base = this.safeCurrencyCode (baseId);
|
331
|
+
const quote = this.safeCurrencyCode (quoteId);
|
332
|
+
const symbol = base + '/' + quote;
|
333
|
+
const fees = this.safeValue (this.safeValue (this.options, 'fees', {}), quote, this.fees);
|
334
|
+
const pricePrecision = this.safeInteger (market, 'priceDecimals');
|
335
|
+
const amountPrecision = this.safeInteger (market, 'amountDecimals');
|
336
|
+
const minAmount = this.safeNumber (market, 'minOrderAmount');
|
337
|
+
const maxAmount = this.safeNumber (market, 'maxOrderAmount');
|
338
|
+
let minPrice = undefined;
|
339
|
+
if (quote === 'AUD') {
|
340
|
+
minPrice = Math.pow (10, -pricePrecision);
|
341
|
+
}
|
342
|
+
result.push ({
|
343
|
+
'id': id,
|
344
|
+
'symbol': symbol,
|
345
|
+
'base': base,
|
346
|
+
'quote': quote,
|
347
|
+
'settle': undefined,
|
348
|
+
'baseId': baseId,
|
349
|
+
'quoteId': quoteId,
|
350
|
+
'settleId': undefined,
|
351
|
+
'type': 'spot',
|
352
|
+
'spot': true,
|
353
|
+
'margin': false,
|
354
|
+
'swap': false,
|
355
|
+
'future': false,
|
356
|
+
'option': false,
|
357
|
+
'active': undefined,
|
358
|
+
'contract': false,
|
359
|
+
'linear': undefined,
|
360
|
+
'inverse': undefined,
|
361
|
+
'taker': fees['taker'],
|
362
|
+
'maker': fees['maker'],
|
363
|
+
'contractSize': undefined,
|
364
|
+
'expiry': undefined,
|
365
|
+
'expiryDatetime': undefined,
|
366
|
+
'strike': undefined,
|
367
|
+
'optionType': undefined,
|
368
|
+
'precision': {
|
369
|
+
'amount': amountPrecision,
|
370
|
+
'price': pricePrecision,
|
371
|
+
},
|
372
|
+
'limits': {
|
373
|
+
'leverage': {
|
374
|
+
'min': undefined,
|
375
|
+
'max': undefined,
|
376
|
+
},
|
377
|
+
'amount': {
|
378
|
+
'min': minAmount,
|
379
|
+
'max': maxAmount,
|
380
|
+
},
|
381
|
+
'price': {
|
382
|
+
'min': minPrice,
|
383
|
+
'max': undefined,
|
384
|
+
},
|
385
|
+
'cost': {
|
386
|
+
'min': undefined,
|
387
|
+
'max': undefined,
|
388
|
+
},
|
389
|
+
},
|
390
|
+
'info': market,
|
391
|
+
});
|
392
|
+
}
|
393
|
+
return result;
|
394
|
+
}
|
395
|
+
|
396
|
+
async fetchTime (params = {}) {
|
397
|
+
const response = await this.publicGetTime (params);
|
398
|
+
//
|
399
|
+
// {
|
400
|
+
// "timestamp": "2019-09-01T18:34:27.045000Z"
|
401
|
+
// }
|
402
|
+
//
|
403
|
+
return this.parse8601 (this.safeString (response, 'timestamp'));
|
404
|
+
}
|
405
|
+
|
406
|
+
parseBalance (response) {
|
407
|
+
const result = { 'info': response };
|
408
|
+
for (let i = 0; i < response.length; i++) {
|
409
|
+
const balance = response[i];
|
410
|
+
const currencyId = this.safeString (balance, 'assetName');
|
411
|
+
const code = this.safeCurrencyCode (currencyId);
|
412
|
+
const account = this.account ();
|
413
|
+
account['used'] = this.safeString (balance, 'locked');
|
414
|
+
account['total'] = this.safeString (balance, 'balance');
|
415
|
+
result[code] = account;
|
416
|
+
}
|
417
|
+
return this.safeBalance (result);
|
418
|
+
}
|
419
|
+
|
420
|
+
async fetchBalance (params = {}) {
|
421
|
+
await this.loadMarkets ();
|
422
|
+
const response = await this.privateGetAccountsMeBalances (params);
|
423
|
+
return this.parseBalance (response);
|
424
|
+
}
|
425
|
+
|
426
|
+
parseOHLCV (ohlcv, market = undefined) {
|
427
|
+
//
|
428
|
+
// [
|
429
|
+
// "2020-09-12T18:30:00.000000Z",
|
430
|
+
// "14409.45", // open
|
431
|
+
// "14409.45", // high
|
432
|
+
// "14403.91", // low
|
433
|
+
// "14403.91", // close
|
434
|
+
// "0.01571701" // volume
|
435
|
+
// ]
|
436
|
+
//
|
437
|
+
return [
|
438
|
+
this.parse8601 (this.safeString (ohlcv, 0)),
|
439
|
+
this.safeNumber (ohlcv, 1), // open
|
440
|
+
this.safeNumber (ohlcv, 2), // high
|
441
|
+
this.safeNumber (ohlcv, 3), // low
|
442
|
+
this.safeNumber (ohlcv, 4), // close
|
443
|
+
this.safeNumber (ohlcv, 5), // volume
|
444
|
+
];
|
445
|
+
}
|
446
|
+
|
447
|
+
async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
448
|
+
await this.loadMarkets ();
|
449
|
+
const market = this.market (symbol);
|
450
|
+
const request = {
|
451
|
+
'marketId': market['id'],
|
452
|
+
'timeWindow': this.timeframes[timeframe],
|
453
|
+
// 'from': this.iso8601 (since),
|
454
|
+
// 'to': this.iso8601 (this.milliseconds ()),
|
455
|
+
// 'before': 1234567890123,
|
456
|
+
// 'after': 1234567890123,
|
457
|
+
// 'limit': limit, // default 10, max 200
|
458
|
+
};
|
459
|
+
if (since !== undefined) {
|
460
|
+
request['from'] = this.iso8601 (since);
|
461
|
+
}
|
462
|
+
if (limit !== undefined) {
|
463
|
+
request['limit'] = limit; // default is 10, max 200
|
464
|
+
}
|
465
|
+
const response = await this.publicGetMarketsMarketIdCandles (this.extend (request, params));
|
466
|
+
//
|
467
|
+
// [
|
468
|
+
// ["2020-09-12T18:30:00.000000Z","14409.45","14409.45","14403.91","14403.91","0.01571701"],
|
469
|
+
// ["2020-09-12T18:21:00.000000Z","14409.45","14409.45","14409.45","14409.45","0.0035"],
|
470
|
+
// ["2020-09-12T18:03:00.000000Z","14361.37","14361.37","14361.37","14361.37","0.00345221"],
|
471
|
+
// ]
|
472
|
+
//
|
473
|
+
return this.parseOHLCVs (response, market, timeframe, since, limit);
|
474
|
+
}
|
475
|
+
|
476
|
+
async fetchOrderBook (symbol, limit = undefined, params = {}) {
|
477
|
+
await this.loadMarkets ();
|
478
|
+
const market = this.market (symbol);
|
479
|
+
const request = {
|
480
|
+
'marketId': market['id'],
|
481
|
+
};
|
482
|
+
const response = await this.publicGetMarketsMarketIdOrderbook (this.extend (request, params));
|
483
|
+
//
|
484
|
+
// {
|
485
|
+
// "marketId":"BTC-AUD",
|
486
|
+
// "snapshotId":1599936148941000,
|
487
|
+
// "asks":[
|
488
|
+
// ["14459.45","0.00456475"],
|
489
|
+
// ["14463.56","2"],
|
490
|
+
// ["14470.91","0.98"],
|
491
|
+
// ],
|
492
|
+
// "bids":[
|
493
|
+
// ["14421.01","0.52"],
|
494
|
+
// ["14421","0.75"],
|
495
|
+
// ["14418","0.3521"],
|
496
|
+
// ]
|
497
|
+
// }
|
498
|
+
//
|
499
|
+
const timestamp = this.safeIntegerProduct (response, 'snapshotId', 0.001);
|
500
|
+
const orderbook = this.parseOrderBook (response, symbol, timestamp);
|
501
|
+
orderbook['nonce'] = this.safeInteger (response, 'snapshotId');
|
502
|
+
return orderbook;
|
503
|
+
}
|
504
|
+
|
505
|
+
parseTicker (ticker, market = undefined) {
|
506
|
+
//
|
507
|
+
// fetchTicker
|
508
|
+
//
|
509
|
+
// {
|
510
|
+
// "marketId":"BAT-AUD",
|
511
|
+
// "bestBid":"0.3751",
|
512
|
+
// "bestAsk":"0.377",
|
513
|
+
// "lastPrice":"0.3769",
|
514
|
+
// "volume24h":"56192.97613335",
|
515
|
+
// "volumeQte24h":"21179.13270465",
|
516
|
+
// "price24h":"0.0119",
|
517
|
+
// "pricePct24h":"3.26",
|
518
|
+
// "low24h":"0.3611",
|
519
|
+
// "high24h":"0.3799",
|
520
|
+
// "timestamp":"2020-08-09T18:28:23.280000Z"
|
521
|
+
// }
|
522
|
+
//
|
523
|
+
const marketId = this.safeString (ticker, 'marketId');
|
524
|
+
market = this.safeMarket (marketId, market, '-');
|
525
|
+
const symbol = market['symbol'];
|
526
|
+
const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp'));
|
527
|
+
const last = this.safeString (ticker, 'lastPrice');
|
528
|
+
const baseVolume = this.safeString (ticker, 'volume24h');
|
529
|
+
const quoteVolume = this.safeString (ticker, 'volumeQte24h');
|
530
|
+
const change = this.safeString (ticker, 'price24h');
|
531
|
+
const percentage = this.safeString (ticker, 'pricePct24h');
|
532
|
+
return this.safeTicker ({
|
533
|
+
'symbol': symbol,
|
534
|
+
'timestamp': timestamp,
|
535
|
+
'datetime': this.iso8601 (timestamp),
|
536
|
+
'high': this.safeString (ticker, 'high24h'),
|
537
|
+
'low': this.safeString (ticker, 'low'),
|
538
|
+
'bid': this.safeString (ticker, 'bestBid'),
|
539
|
+
'bidVolume': undefined,
|
540
|
+
'ask': this.safeString (ticker, 'bestAsk'),
|
541
|
+
'askVolume': undefined,
|
542
|
+
'vwap': undefined,
|
543
|
+
'open': undefined,
|
544
|
+
'close': last,
|
545
|
+
'last': last,
|
546
|
+
'previousClose': undefined,
|
547
|
+
'change': change,
|
548
|
+
'percentage': percentage,
|
549
|
+
'average': undefined,
|
550
|
+
'baseVolume': baseVolume,
|
551
|
+
'quoteVolume': quoteVolume,
|
552
|
+
'info': ticker,
|
553
|
+
}, market, false);
|
554
|
+
}
|
555
|
+
|
556
|
+
async fetchTicker (symbol, params = {}) {
|
557
|
+
await this.loadMarkets ();
|
558
|
+
const market = this.market (symbol);
|
559
|
+
const request = {
|
560
|
+
'marketId': market['id'],
|
561
|
+
};
|
562
|
+
const response = await this.publicGetMarketsMarketIdTicker (this.extend (request, params));
|
563
|
+
//
|
564
|
+
// {
|
565
|
+
// "marketId":"BAT-AUD",
|
566
|
+
// "bestBid":"0.3751",
|
567
|
+
// "bestAsk":"0.377",
|
568
|
+
// "lastPrice":"0.3769",
|
569
|
+
// "volume24h":"56192.97613335",
|
570
|
+
// "volumeQte24h":"21179.13270465",
|
571
|
+
// "price24h":"0.0119",
|
572
|
+
// "pricePct24h":"3.26",
|
573
|
+
// "low24h":"0.3611",
|
574
|
+
// "high24h":"0.3799",
|
575
|
+
// "timestamp":"2020-08-09T18:28:23.280000Z"
|
576
|
+
// }
|
577
|
+
//
|
578
|
+
return this.parseTicker (response, market);
|
579
|
+
}
|
580
|
+
|
581
|
+
async fetchTicker2 (symbol, params = {}) {
|
582
|
+
await this.loadMarkets ();
|
583
|
+
const market = this.market (symbol);
|
584
|
+
const request = {
|
585
|
+
'id': market['id'],
|
586
|
+
};
|
587
|
+
const response = await this.publicGetMarketIdTick (this.extend (request, params));
|
588
|
+
return this.parseTicker (response, market);
|
589
|
+
}
|
590
|
+
|
591
|
+
parseTrade (trade, market = undefined) {
|
592
|
+
//
|
593
|
+
// public fetchTrades
|
594
|
+
//
|
595
|
+
// {
|
596
|
+
// "id":"6191646611",
|
597
|
+
// "price":"539.98",
|
598
|
+
// "amount":"0.5",
|
599
|
+
// "timestamp":"2020-08-09T15:21:05.016000Z",
|
600
|
+
// "side":"Ask"
|
601
|
+
// }
|
602
|
+
//
|
603
|
+
// private fetchMyTrades
|
604
|
+
//
|
605
|
+
// {
|
606
|
+
// "id": "36014819",
|
607
|
+
// "marketId": "XRP-AUD",
|
608
|
+
// "timestamp": "2019-06-25T16:01:02.977000Z",
|
609
|
+
// "price": "0.67",
|
610
|
+
// "amount": "1.50533262",
|
611
|
+
// "side": "Ask",
|
612
|
+
// "fee": "0.00857285",
|
613
|
+
// "orderId": "3648306",
|
614
|
+
// "liquidityType": "Taker",
|
615
|
+
// "clientOrderId": "48"
|
616
|
+
// }
|
617
|
+
//
|
618
|
+
const timestamp = this.parse8601 (this.safeString (trade, 'timestamp'));
|
619
|
+
const marketId = this.safeString (trade, 'marketId');
|
620
|
+
market = this.safeMarket (marketId, market, '-');
|
621
|
+
const feeCurrencyCode = (market['quote'] === 'AUD') ? market['quote'] : market['base'];
|
622
|
+
let side = this.safeString (trade, 'side');
|
623
|
+
if (side === 'Bid') {
|
624
|
+
side = 'buy';
|
625
|
+
} else if (side === 'Ask') {
|
626
|
+
side = 'sell';
|
627
|
+
}
|
628
|
+
const id = this.safeString (trade, 'id');
|
629
|
+
const priceString = this.safeString (trade, 'price');
|
630
|
+
const amountString = this.safeString (trade, 'amount');
|
631
|
+
const orderId = this.safeString (trade, 'orderId');
|
632
|
+
let fee = undefined;
|
633
|
+
const feeCostString = this.safeString (trade, 'fee');
|
634
|
+
if (feeCostString !== undefined) {
|
635
|
+
fee = {
|
636
|
+
'cost': feeCostString,
|
637
|
+
'currency': feeCurrencyCode,
|
638
|
+
};
|
639
|
+
}
|
640
|
+
const takerOrMaker = this.safeStringLower (trade, 'liquidityType');
|
641
|
+
return this.safeTrade ({
|
642
|
+
'info': trade,
|
643
|
+
'id': id,
|
644
|
+
'timestamp': timestamp,
|
645
|
+
'datetime': this.iso8601 (timestamp),
|
646
|
+
'order': orderId,
|
647
|
+
'symbol': market['symbol'],
|
648
|
+
'type': undefined,
|
649
|
+
'side': side,
|
650
|
+
'price': priceString,
|
651
|
+
'amount': amountString,
|
652
|
+
'cost': undefined,
|
653
|
+
'takerOrMaker': takerOrMaker,
|
654
|
+
'fee': fee,
|
655
|
+
}, market);
|
656
|
+
}
|
657
|
+
|
658
|
+
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
|
659
|
+
await this.loadMarkets ();
|
660
|
+
const market = this.market (symbol);
|
661
|
+
const request = {
|
662
|
+
// 'since': 59868345231,
|
663
|
+
'marketId': market['id'],
|
664
|
+
};
|
665
|
+
const response = await this.publicGetMarketsMarketIdTrades (this.extend (request, params));
|
666
|
+
//
|
667
|
+
// [
|
668
|
+
// {"id":"6191646611","price":"539.98","amount":"0.5","timestamp":"2020-08-09T15:21:05.016000Z","side":"Ask"},
|
669
|
+
// {"id":"6191646610","price":"539.99","amount":"0.5","timestamp":"2020-08-09T15:21:05.015000Z","side":"Ask"},
|
670
|
+
// {"id":"6191646590","price":"540","amount":"0.00233785","timestamp":"2020-08-09T15:21:04.171000Z","side":"Bid"},
|
671
|
+
// ]
|
672
|
+
//
|
673
|
+
return this.parseTrades (response, market, since, limit);
|
674
|
+
}
|
675
|
+
|
676
|
+
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
|
677
|
+
await this.loadMarkets ();
|
678
|
+
const market = this.market (symbol);
|
679
|
+
const request = {
|
680
|
+
'marketId': market['id'],
|
681
|
+
// 'price': this.priceToPrecision (symbol, price),
|
682
|
+
'amount': this.amountToPrecision (symbol, amount),
|
683
|
+
// 'type': 'Limit', // "Limit", "Market", "Stop Limit", "Stop", "Take Profit"
|
684
|
+
'side': (side === 'buy') ? 'Bid' : 'Ask',
|
685
|
+
// 'triggerPrice': this.priceToPrecision (symbol, triggerPrice), // required for Stop, Stop Limit, Take Profit orders
|
686
|
+
// 'targetAmount': this.amountToPrecision (symbol, targetAmount), // target amount when a desired target outcome is required for order execution
|
687
|
+
// 'timeInForce': 'GTC', // GTC, FOK, IOC
|
688
|
+
// 'postOnly': false, // boolean if this is a post-only order
|
689
|
+
// 'selfTrade': 'A', // A = allow, P = prevent
|
690
|
+
// 'clientOrderId': this.uuid (),
|
691
|
+
};
|
692
|
+
const lowercaseType = type.toLowerCase ();
|
693
|
+
const orderTypes = this.safeValue (this.options, 'orderTypes', {
|
694
|
+
'limit': 'Limit',
|
695
|
+
'market': 'Market',
|
696
|
+
'stop': 'Stop',
|
697
|
+
'stop limit': 'Stop Limit',
|
698
|
+
'take profit': 'Take Profit',
|
699
|
+
});
|
700
|
+
request['type'] = this.safeString (orderTypes, lowercaseType, type);
|
701
|
+
let priceIsRequired = false;
|
702
|
+
let triggerPriceIsRequired = false;
|
703
|
+
if (lowercaseType === 'limit') {
|
704
|
+
priceIsRequired = true;
|
705
|
+
// } else if (lowercaseType === 'market') {
|
706
|
+
// ...
|
707
|
+
// }
|
708
|
+
} else if (lowercaseType === 'stop limit') {
|
709
|
+
triggerPriceIsRequired = true;
|
710
|
+
priceIsRequired = true;
|
711
|
+
} else if (lowercaseType === 'take profit') {
|
712
|
+
triggerPriceIsRequired = true;
|
713
|
+
} else if (lowercaseType === 'stop') {
|
714
|
+
triggerPriceIsRequired = true;
|
715
|
+
}
|
716
|
+
if (priceIsRequired) {
|
717
|
+
if (price === undefined) {
|
718
|
+
throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument for a ' + type + 'order');
|
719
|
+
} else {
|
720
|
+
request['price'] = this.priceToPrecision (symbol, price);
|
721
|
+
}
|
722
|
+
}
|
723
|
+
if (triggerPriceIsRequired) {
|
724
|
+
const triggerPrice = this.safeNumber (params, 'triggerPrice');
|
725
|
+
params = this.omit (params, 'triggerPrice');
|
726
|
+
if (triggerPrice === undefined) {
|
727
|
+
throw new ArgumentsRequired (this.id + ' createOrder() requires a triggerPrice parameter for a ' + type + 'order');
|
728
|
+
} else {
|
729
|
+
request['triggerPrice'] = this.priceToPrecision (symbol, triggerPrice);
|
730
|
+
}
|
731
|
+
}
|
732
|
+
const clientOrderId = this.safeString (params, 'clientOrderId');
|
733
|
+
if (clientOrderId !== undefined) {
|
734
|
+
request['clientOrderId'] = clientOrderId;
|
735
|
+
}
|
736
|
+
params = this.omit (params, 'clientOrderId');
|
737
|
+
const response = await this.privatePostOrders (this.extend (request, params));
|
738
|
+
//
|
739
|
+
// {
|
740
|
+
// "orderId": "7524",
|
741
|
+
// "marketId": "BTC-AUD",
|
742
|
+
// "side": "Bid",
|
743
|
+
// "type": "Limit",
|
744
|
+
// "creationTime": "2019-08-30T11:08:21.956000Z",
|
745
|
+
// "price": "100.12",
|
746
|
+
// "amount": "1.034",
|
747
|
+
// "openAmount": "1.034",
|
748
|
+
// "status": "Accepted",
|
749
|
+
// "clientOrderId": "1234-5678",
|
750
|
+
// "timeInForce": "IOC",
|
751
|
+
// "postOnly": false,
|
752
|
+
// "selfTrade": "P",
|
753
|
+
// "triggerAmount": "105",
|
754
|
+
// "targetAmount": "1000"
|
755
|
+
// }
|
756
|
+
//
|
757
|
+
return this.parseOrder (response, market);
|
758
|
+
}
|
759
|
+
|
760
|
+
async cancelOrders (ids, symbol = undefined, params = {}) {
|
761
|
+
await this.loadMarkets ();
|
762
|
+
for (let i = 0; i < ids.length; i++) {
|
763
|
+
ids[i] = parseInt (ids[i]);
|
764
|
+
}
|
765
|
+
const request = {
|
766
|
+
'ids': ids,
|
767
|
+
};
|
768
|
+
return await this.privateDeleteBatchordersIds (this.extend (request, params));
|
769
|
+
}
|
770
|
+
|
771
|
+
async cancelOrder (id, symbol = undefined, params = {}) {
|
772
|
+
await this.loadMarkets ();
|
773
|
+
const request = {
|
774
|
+
'id': id,
|
775
|
+
};
|
776
|
+
return await this.privateDeleteOrdersId (this.extend (request, params));
|
777
|
+
}
|
778
|
+
|
779
|
+
calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) {
|
780
|
+
const market = this.markets[symbol];
|
781
|
+
const rate = market[takerOrMaker];
|
782
|
+
let currency = undefined;
|
783
|
+
let cost = undefined;
|
784
|
+
if (market['quote'] === 'AUD') {
|
785
|
+
currency = market['quote'];
|
786
|
+
cost = parseFloat (this.costToPrecision (symbol, amount * price));
|
787
|
+
} else {
|
788
|
+
currency = market['base'];
|
789
|
+
cost = parseFloat (this.amountToPrecision (symbol, amount));
|
790
|
+
}
|
791
|
+
return {
|
792
|
+
'type': takerOrMaker,
|
793
|
+
'currency': currency,
|
794
|
+
'rate': rate,
|
795
|
+
'cost': parseFloat (this.feeToPrecision (symbol, rate * cost)),
|
796
|
+
};
|
797
|
+
}
|
798
|
+
|
799
|
+
parseOrderStatus (status) {
|
800
|
+
const statuses = {
|
801
|
+
'Accepted': 'open',
|
802
|
+
'Placed': 'open',
|
803
|
+
'Partially Matched': 'open',
|
804
|
+
'Fully Matched': 'closed',
|
805
|
+
'Cancelled': 'canceled',
|
806
|
+
'Partially Cancelled': 'canceled',
|
807
|
+
'Failed': 'rejected',
|
808
|
+
};
|
809
|
+
return this.safeString (statuses, status, status);
|
810
|
+
}
|
811
|
+
|
812
|
+
parseOrder (order, market = undefined) {
|
813
|
+
//
|
814
|
+
// createOrder
|
815
|
+
//
|
816
|
+
// {
|
817
|
+
// "orderId": "7524",
|
818
|
+
// "marketId": "BTC-AUD",
|
819
|
+
// "side": "Bid",
|
820
|
+
// "type": "Limit",
|
821
|
+
// "creationTime": "2019-08-30T11:08:21.956000Z",
|
822
|
+
// "price": "100.12",
|
823
|
+
// "amount": "1.034",
|
824
|
+
// "openAmount": "1.034",
|
825
|
+
// "status": "Accepted",
|
826
|
+
// "clientOrderId": "1234-5678",
|
827
|
+
// "timeInForce": "IOC",
|
828
|
+
// "postOnly": false,
|
829
|
+
// "selfTrade": "P",
|
830
|
+
// "triggerAmount": "105",
|
831
|
+
// "targetAmount": "1000"
|
832
|
+
// }
|
833
|
+
//
|
834
|
+
const timestamp = this.parse8601 (this.safeString (order, 'creationTime'));
|
835
|
+
const marketId = this.safeString (order, 'marketId');
|
836
|
+
market = this.safeMarket (marketId, market, '-');
|
837
|
+
let side = this.safeString (order, 'side');
|
838
|
+
if (side === 'Bid') {
|
839
|
+
side = 'buy';
|
840
|
+
} else if (side === 'Ask') {
|
841
|
+
side = 'sell';
|
842
|
+
}
|
843
|
+
const type = this.safeStringLower (order, 'type');
|
844
|
+
const price = this.safeString (order, 'price');
|
845
|
+
const amount = this.safeString (order, 'amount');
|
846
|
+
const remaining = this.safeString (order, 'openAmount');
|
847
|
+
const status = this.parseOrderStatus (this.safeString (order, 'status'));
|
848
|
+
const id = this.safeString (order, 'orderId');
|
849
|
+
const clientOrderId = this.safeString (order, 'clientOrderId');
|
850
|
+
const timeInForce = this.safeString (order, 'timeInForce');
|
851
|
+
const stopPrice = this.safeNumber (order, 'triggerPrice');
|
852
|
+
const postOnly = this.safeValue (order, 'postOnly');
|
853
|
+
return this.safeOrder ({
|
854
|
+
'info': order,
|
855
|
+
'id': id,
|
856
|
+
'clientOrderId': clientOrderId,
|
857
|
+
'timestamp': timestamp,
|
858
|
+
'datetime': this.iso8601 (timestamp),
|
859
|
+
'lastTradeTimestamp': undefined,
|
860
|
+
'symbol': market['symbol'],
|
861
|
+
'type': type,
|
862
|
+
'timeInForce': timeInForce,
|
863
|
+
'postOnly': postOnly,
|
864
|
+
'side': side,
|
865
|
+
'price': price,
|
866
|
+
'stopPrice': stopPrice,
|
867
|
+
'cost': undefined,
|
868
|
+
'amount': amount,
|
869
|
+
'filled': undefined,
|
870
|
+
'remaining': remaining,
|
871
|
+
'average': undefined,
|
872
|
+
'status': status,
|
873
|
+
'trades': undefined,
|
874
|
+
'fee': undefined,
|
875
|
+
}, market);
|
876
|
+
}
|
877
|
+
|
878
|
+
async fetchOrder (id, symbol = undefined, params = {}) {
|
879
|
+
await this.loadMarkets ();
|
880
|
+
const request = {
|
881
|
+
'id': id,
|
882
|
+
};
|
883
|
+
const response = await this.privateGetOrdersId (this.extend (request, params));
|
884
|
+
return this.parseOrder (response);
|
885
|
+
}
|
886
|
+
|
887
|
+
async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
888
|
+
await this.loadMarkets ();
|
889
|
+
const request = {
|
890
|
+
'status': 'all',
|
891
|
+
};
|
892
|
+
let market = undefined;
|
893
|
+
if (symbol !== undefined) {
|
894
|
+
market = this.market (symbol);
|
895
|
+
request['marketId'] = market['id'];
|
896
|
+
}
|
897
|
+
if (since !== undefined) {
|
898
|
+
request['after'] = since;
|
899
|
+
}
|
900
|
+
if (limit !== undefined) {
|
901
|
+
request['limit'] = limit;
|
902
|
+
}
|
903
|
+
const response = await this.privateGetOrders (this.extend (request, params));
|
904
|
+
return this.parseOrders (response, market, since, limit);
|
905
|
+
}
|
906
|
+
|
907
|
+
async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
908
|
+
const request = { 'status': 'open' };
|
909
|
+
return await this.fetchOrders (symbol, since, limit, this.extend (request, params));
|
910
|
+
}
|
911
|
+
|
912
|
+
async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
913
|
+
const orders = await this.fetchOrders (symbol, since, limit, params);
|
914
|
+
return this.filterBy (orders, 'status', 'closed');
|
915
|
+
}
|
916
|
+
|
917
|
+
async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
918
|
+
await this.loadMarkets ();
|
919
|
+
const request = {};
|
920
|
+
let market = undefined;
|
921
|
+
if (symbol !== undefined) {
|
922
|
+
market = this.market (symbol);
|
923
|
+
request['marketId'] = market['id'];
|
924
|
+
}
|
925
|
+
if (since !== undefined) {
|
926
|
+
request['after'] = since;
|
927
|
+
}
|
928
|
+
if (limit !== undefined) {
|
929
|
+
request['limit'] = limit;
|
930
|
+
}
|
931
|
+
const response = await this.privateGetTrades (this.extend (request, params));
|
932
|
+
//
|
933
|
+
// [
|
934
|
+
// {
|
935
|
+
// "id": "36014819",
|
936
|
+
// "marketId": "XRP-AUD",
|
937
|
+
// "timestamp": "2019-06-25T16:01:02.977000Z",
|
938
|
+
// "price": "0.67",
|
939
|
+
// "amount": "1.50533262",
|
940
|
+
// "side": "Ask",
|
941
|
+
// "fee": "0.00857285",
|
942
|
+
// "orderId": "3648306",
|
943
|
+
// "liquidityType": "Taker",
|
944
|
+
// "clientOrderId": "48"
|
945
|
+
// },
|
946
|
+
// {
|
947
|
+
// "id": "3568960",
|
948
|
+
// "marketId": "GNT-AUD",
|
949
|
+
// "timestamp": "2019-06-20T08:44:04.488000Z",
|
950
|
+
// "price": "0.1362",
|
951
|
+
// "amount": "0.85",
|
952
|
+
// "side": "Bid",
|
953
|
+
// "fee": "0.00098404",
|
954
|
+
// "orderId": "3543015",
|
955
|
+
// "liquidityType": "Maker"
|
956
|
+
// }
|
957
|
+
// ]
|
958
|
+
//
|
959
|
+
return this.parseTrades (response, market, since, limit);
|
960
|
+
}
|
961
|
+
|
962
|
+
nonce () {
|
963
|
+
return this.milliseconds ();
|
964
|
+
}
|
965
|
+
|
966
|
+
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
967
|
+
let request = '/' + this.version + '/' + this.implodeParams (path, params);
|
968
|
+
const query = this.keysort (this.omit (params, this.extractParams (path)));
|
969
|
+
if (api === 'private') {
|
970
|
+
this.checkRequiredCredentials ();
|
971
|
+
const nonce = this.nonce ().toString ();
|
972
|
+
const secret = this.base64ToBinary (this.encode (this.secret));
|
973
|
+
let auth = method + request + nonce;
|
974
|
+
if ((method === 'GET') || (method === 'DELETE')) {
|
975
|
+
if (Object.keys (query).length) {
|
976
|
+
request += '?' + this.urlencode (query);
|
977
|
+
}
|
978
|
+
} else {
|
979
|
+
body = this.json (query);
|
980
|
+
auth += body;
|
981
|
+
}
|
982
|
+
const signature = this.hmac (this.encode (auth), secret, 'sha512', 'base64');
|
983
|
+
headers = {
|
984
|
+
'Accept': 'application/json',
|
985
|
+
'Accept-Charset': 'UTF-8',
|
986
|
+
'Content-Type': 'application/json',
|
987
|
+
'BM-AUTH-APIKEY': this.apiKey,
|
988
|
+
'BM-AUTH-TIMESTAMP': nonce,
|
989
|
+
'BM-AUTH-SIGNATURE': signature,
|
990
|
+
};
|
991
|
+
} else if (api === 'public') {
|
992
|
+
if (Object.keys (query).length) {
|
993
|
+
request += '?' + this.urlencode (query);
|
994
|
+
}
|
995
|
+
}
|
996
|
+
const url = this.urls['api'][api] + request;
|
997
|
+
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
998
|
+
}
|
999
|
+
|
1000
|
+
handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
1001
|
+
if (response === undefined) {
|
1002
|
+
return; // fallback to default error handler
|
1003
|
+
}
|
1004
|
+
if ('success' in response) {
|
1005
|
+
if (!response['success']) {
|
1006
|
+
const error = this.safeString (response, 'errorCode');
|
1007
|
+
const feedback = this.id + ' ' + body;
|
1008
|
+
this.throwExactlyMatchedException (this.exceptions, error, feedback);
|
1009
|
+
throw new ExchangeError (feedback);
|
1010
|
+
}
|
1011
|
+
}
|
1012
|
+
// v3 api errors
|
1013
|
+
if (code >= 400) {
|
1014
|
+
const errorCode = this.safeString (response, 'code');
|
1015
|
+
const message = this.safeString (response, 'message');
|
1016
|
+
const feedback = this.id + ' ' + body;
|
1017
|
+
this.throwExactlyMatchedException (this.exceptions, errorCode, feedback);
|
1018
|
+
this.throwExactlyMatchedException (this.exceptions, message, feedback);
|
1019
|
+
throw new ExchangeError (feedback);
|
1020
|
+
}
|
1021
|
+
}
|
1022
|
+
};
|