ccxt 4.4.85 → 4.4.87
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/README.md +18 -7
- package/dist/ccxt.browser.min.js +3 -3
- package/dist/cjs/ccxt.js +16 -9
- package/dist/cjs/src/abstract/bittrade.js +9 -0
- package/dist/cjs/src/abstract/modetrade.js +9 -0
- package/dist/cjs/src/ascendex.js +189 -155
- package/dist/cjs/src/base/Exchange.js +10 -8
- package/dist/cjs/src/bequant.js +1 -1
- package/dist/cjs/src/binance.js +1 -1
- package/dist/cjs/src/bitget.js +5 -4
- package/dist/cjs/src/bitmart.js +1 -1
- package/dist/cjs/src/bitteam.js +31 -0
- package/dist/cjs/src/bittrade.js +2049 -0
- package/dist/cjs/src/coinbase.js +2 -6
- package/dist/cjs/src/coinmetro.js +5 -1
- package/dist/cjs/src/deribit.js +4 -5
- package/dist/cjs/src/derive.js +4 -5
- package/dist/cjs/src/ellipx.js +2 -3
- package/dist/cjs/src/gate.js +92 -76
- package/dist/cjs/src/hollaex.js +107 -49
- package/dist/cjs/src/htx.js +30 -52
- package/dist/cjs/src/hyperliquid.js +36 -20
- package/dist/cjs/src/kraken.js +5 -8
- package/dist/cjs/src/mexc.js +2 -2
- package/dist/cjs/src/modetrade.js +2839 -0
- package/dist/cjs/src/ndax.js +25 -24
- package/dist/cjs/src/okcoin.js +12 -31
- package/dist/cjs/src/okx.js +104 -2
- package/dist/cjs/src/okxus.js +53 -0
- package/dist/cjs/src/onetrading.js +9 -6
- package/dist/cjs/src/oxfun.js +42 -114
- package/dist/cjs/src/paradex.js +10 -1
- package/dist/cjs/src/phemex.js +4 -6
- package/dist/cjs/src/poloniex.js +181 -170
- package/dist/cjs/src/pro/binance.js +1 -0
- package/dist/cjs/src/pro/bittrade.js +605 -0
- package/dist/cjs/src/pro/luno.js +6 -5
- package/dist/cjs/src/pro/mexc.js +3 -0
- package/dist/cjs/src/pro/modetrade.js +1334 -0
- package/dist/cjs/src/pro/okxus.js +38 -0
- package/dist/cjs/src/probit.js +18 -51
- package/dist/cjs/src/timex.js +5 -10
- package/dist/cjs/src/vertex.js +3 -4
- package/dist/cjs/src/whitebit.js +41 -11
- package/dist/cjs/src/woo.js +101 -77
- package/dist/cjs/src/woofipro.js +24 -21
- package/dist/cjs/src/xt.js +36 -44
- package/js/ccxt.d.ts +20 -11
- package/js/ccxt.js +14 -8
- package/js/src/abstract/modetrade.d.ts +122 -0
- package/js/src/abstract/myokx.d.ts +2 -0
- package/js/src/abstract/okx.d.ts +2 -0
- package/js/src/abstract/okxus.d.ts +352 -0
- package/js/src/abstract/okxus.js +11 -0
- package/js/src/ascendex.d.ts +2 -0
- package/js/src/ascendex.js +189 -155
- package/js/src/base/Exchange.js +10 -8
- package/js/src/bequant.js +1 -1
- package/js/src/binance.js +1 -1
- package/js/src/bitget.js +5 -4
- package/js/src/bitmart.js +1 -1
- package/js/src/bitteam.js +31 -0
- package/js/src/{huobijp.d.ts → bittrade.d.ts} +29 -29
- package/js/src/{huobijp.js → bittrade.js} +35 -35
- package/js/src/coinbase.js +2 -6
- package/js/src/coinmetro.js +5 -1
- package/js/src/deribit.js +4 -5
- package/js/src/derive.js +4 -3
- package/js/src/ellipx.d.ts +1 -1
- package/js/src/ellipx.js +3 -5
- package/js/src/gate.js +92 -76
- package/js/src/hollaex.js +107 -49
- package/js/src/htx.js +30 -52
- package/js/src/hyperliquid.js +36 -20
- package/js/src/kraken.js +5 -8
- package/js/src/mexc.js +2 -2
- package/js/src/modetrade.d.ts +475 -0
- package/js/src/modetrade.js +2840 -0
- package/js/src/ndax.js +25 -24
- package/js/src/okcoin.js +12 -31
- package/js/src/okx.d.ts +24 -1
- package/js/src/okx.js +104 -2
- package/js/src/okxus.d.ts +4 -0
- package/js/src/okxus.js +54 -0
- package/js/src/onetrading.js +9 -6
- package/js/src/oxfun.js +42 -114
- package/js/src/paradex.js +10 -1
- package/js/src/phemex.js +4 -6
- package/js/src/poloniex.d.ts +2 -0
- package/js/src/poloniex.js +181 -170
- package/js/src/pro/binance.js +1 -0
- package/js/src/pro/{huobijp.d.ts → bittrade.d.ts} +6 -6
- package/js/src/pro/{huobijp.js → bittrade.js} +7 -7
- package/js/src/pro/luno.js +6 -5
- package/js/src/pro/mexc.js +3 -0
- package/js/src/pro/modetrade.d.ts +155 -0
- package/js/src/pro/modetrade.js +1335 -0
- package/js/src/pro/okxus.d.ts +4 -0
- package/js/src/pro/okxus.js +39 -0
- package/js/src/probit.js +18 -51
- package/js/src/timex.js +5 -10
- package/js/src/vertex.js +3 -4
- package/js/src/whitebit.js +42 -11
- package/js/src/woo.d.ts +2 -0
- package/js/src/woo.js +101 -77
- package/js/src/woofipro.d.ts +2 -1
- package/js/src/woofipro.js +24 -21
- package/js/src/xt.js +36 -44
- package/package.json +1 -1
- package/js/src/abstract/kuna.d.ts +0 -185
- package/js/src/kuna.d.ts +0 -335
- package/js/src/kuna.js +0 -2006
- /package/js/src/abstract/{huobijp.d.ts → bittrade.d.ts} +0 -0
- /package/js/src/abstract/{huobijp.js → bittrade.js} +0 -0
- /package/js/src/abstract/{kuna.js → modetrade.js} +0 -0
|
@@ -0,0 +1,2049 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var bittrade$1 = require('./abstract/bittrade.js');
|
|
4
|
+
var errors = require('./base/errors.js');
|
|
5
|
+
var Precise = require('./base/Precise.js');
|
|
6
|
+
var number = require('./base/functions/number.js');
|
|
7
|
+
var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
|
|
8
|
+
|
|
9
|
+
// ----------------------------------------------------------------------------
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
/**
|
|
12
|
+
* @class bittrade
|
|
13
|
+
* @augments Exchange
|
|
14
|
+
*/
|
|
15
|
+
class bittrade extends bittrade$1 {
|
|
16
|
+
describe() {
|
|
17
|
+
return this.deepExtend(super.describe(), {
|
|
18
|
+
'id': 'bittrade',
|
|
19
|
+
'name': 'BitTrade',
|
|
20
|
+
'countries': ['JP'],
|
|
21
|
+
'rateLimit': 100,
|
|
22
|
+
'userAgent': this.userAgents['chrome39'],
|
|
23
|
+
'certified': false,
|
|
24
|
+
'version': 'v1',
|
|
25
|
+
'hostname': 'api-cloud.bittrade.co.jp',
|
|
26
|
+
'pro': true,
|
|
27
|
+
'has': {
|
|
28
|
+
'CORS': undefined,
|
|
29
|
+
'spot': true,
|
|
30
|
+
'margin': undefined,
|
|
31
|
+
'swap': false,
|
|
32
|
+
'future': false,
|
|
33
|
+
'option': false,
|
|
34
|
+
'cancelAllOrders': true,
|
|
35
|
+
'cancelOrder': true,
|
|
36
|
+
'cancelOrders': true,
|
|
37
|
+
'createMarketBuyOrderWithCost': true,
|
|
38
|
+
'createMarketOrderWithCost': false,
|
|
39
|
+
'createMarketSellOrderWithCost': false,
|
|
40
|
+
'createOrder': true,
|
|
41
|
+
'createStopLimitOrder': false,
|
|
42
|
+
'createStopMarketOrder': false,
|
|
43
|
+
'createStopOrder': false,
|
|
44
|
+
'fetchAccounts': true,
|
|
45
|
+
'fetchBalance': true,
|
|
46
|
+
'fetchClosedOrders': true,
|
|
47
|
+
'fetchCurrencies': true,
|
|
48
|
+
'fetchDepositAddress': false,
|
|
49
|
+
'fetchDepositAddressesByNetwork': false,
|
|
50
|
+
'fetchDeposits': true,
|
|
51
|
+
'fetchFundingHistory': false,
|
|
52
|
+
'fetchFundingRate': false,
|
|
53
|
+
'fetchFundingRateHistory': false,
|
|
54
|
+
'fetchFundingRates': false,
|
|
55
|
+
'fetchIndexOHLCV': false,
|
|
56
|
+
'fetchMarkets': true,
|
|
57
|
+
'fetchMarkOHLCV': false,
|
|
58
|
+
'fetchMyTrades': true,
|
|
59
|
+
'fetchOHLCV': true,
|
|
60
|
+
'fetchOpenOrders': true,
|
|
61
|
+
'fetchOrder': true,
|
|
62
|
+
'fetchOrderBook': true,
|
|
63
|
+
'fetchOrders': true,
|
|
64
|
+
'fetchOrderTrades': true,
|
|
65
|
+
'fetchPremiumIndexOHLCV': false,
|
|
66
|
+
'fetchTicker': true,
|
|
67
|
+
'fetchTickers': true,
|
|
68
|
+
'fetchTime': true,
|
|
69
|
+
'fetchTrades': true,
|
|
70
|
+
'fetchTradingLimits': true,
|
|
71
|
+
'fetchWithdrawals': true,
|
|
72
|
+
'withdraw': true,
|
|
73
|
+
},
|
|
74
|
+
'timeframes': {
|
|
75
|
+
'1m': '1min',
|
|
76
|
+
'5m': '5min',
|
|
77
|
+
'15m': '15min',
|
|
78
|
+
'30m': '30min',
|
|
79
|
+
'1h': '60min',
|
|
80
|
+
'4h': '4hour',
|
|
81
|
+
'1d': '1day',
|
|
82
|
+
'1w': '1week',
|
|
83
|
+
'1M': '1mon',
|
|
84
|
+
'1y': '1year',
|
|
85
|
+
},
|
|
86
|
+
'urls': {
|
|
87
|
+
'logo': 'https://user-images.githubusercontent.com/1294454/85734211-85755480-b705-11ea-8b35-0b7f1db33a2f.jpg',
|
|
88
|
+
'api': {
|
|
89
|
+
'market': 'https://{hostname}',
|
|
90
|
+
'public': 'https://{hostname}',
|
|
91
|
+
'private': 'https://{hostname}',
|
|
92
|
+
'v2Public': 'https://{hostname}',
|
|
93
|
+
'v2Private': 'https://{hostname}',
|
|
94
|
+
},
|
|
95
|
+
'www': 'https://www.bittrade.co.jp',
|
|
96
|
+
'referral': 'https://www.bittrade.co.jp/register/?invite_code=znnq3',
|
|
97
|
+
'doc': 'https://api-doc.bittrade.co.jp',
|
|
98
|
+
'fees': 'https://www.bittrade.co.jp/ja-jp/support/fee',
|
|
99
|
+
},
|
|
100
|
+
'api': {
|
|
101
|
+
'v2Public': {
|
|
102
|
+
'get': {
|
|
103
|
+
'reference/currencies': 1,
|
|
104
|
+
'market-status': 1, // 获取当前市场状态
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
'v2Private': {
|
|
108
|
+
'get': {
|
|
109
|
+
'account/ledger': 1,
|
|
110
|
+
'account/withdraw/quota': 1,
|
|
111
|
+
'account/withdraw/address': 1,
|
|
112
|
+
'account/deposit/address': 1,
|
|
113
|
+
'account/repayment': 5,
|
|
114
|
+
'reference/transact-fee-rate': 1,
|
|
115
|
+
'account/asset-valuation': 0.2,
|
|
116
|
+
'point/account': 5,
|
|
117
|
+
'sub-user/user-list': 1,
|
|
118
|
+
'sub-user/user-state': 1,
|
|
119
|
+
'sub-user/account-list': 1,
|
|
120
|
+
'sub-user/deposit-address': 1,
|
|
121
|
+
'sub-user/query-deposit': 1,
|
|
122
|
+
'user/api-key': 1,
|
|
123
|
+
'user/uid': 1,
|
|
124
|
+
'algo-orders/opening': 1,
|
|
125
|
+
'algo-orders/history': 1,
|
|
126
|
+
'algo-orders/specific': 1,
|
|
127
|
+
'c2c/offers': 1,
|
|
128
|
+
'c2c/offer': 1,
|
|
129
|
+
'c2c/transactions': 1,
|
|
130
|
+
'c2c/repayment': 1,
|
|
131
|
+
'c2c/account': 1,
|
|
132
|
+
'etp/reference': 1,
|
|
133
|
+
'etp/transactions': 5,
|
|
134
|
+
'etp/transaction': 5,
|
|
135
|
+
'etp/rebalance': 1,
|
|
136
|
+
'etp/limit': 1, // 获取ETP持仓限额
|
|
137
|
+
},
|
|
138
|
+
'post': {
|
|
139
|
+
'account/transfer': 1,
|
|
140
|
+
'account/repayment': 5,
|
|
141
|
+
'point/transfer': 5,
|
|
142
|
+
'sub-user/management': 1,
|
|
143
|
+
'sub-user/creation': 1,
|
|
144
|
+
'sub-user/tradable-market': 1,
|
|
145
|
+
'sub-user/transferability': 1,
|
|
146
|
+
'sub-user/api-key-generation': 1,
|
|
147
|
+
'sub-user/api-key-modification': 1,
|
|
148
|
+
'sub-user/api-key-deletion': 1,
|
|
149
|
+
'sub-user/deduct-mode': 1,
|
|
150
|
+
'algo-orders': 1,
|
|
151
|
+
'algo-orders/cancel-all-after': 1,
|
|
152
|
+
'algo-orders/cancellation': 1,
|
|
153
|
+
'c2c/offer': 1,
|
|
154
|
+
'c2c/cancellation': 1,
|
|
155
|
+
'c2c/cancel-all': 1,
|
|
156
|
+
'c2c/repayment': 1,
|
|
157
|
+
'c2c/transfer': 1,
|
|
158
|
+
'etp/creation': 5,
|
|
159
|
+
'etp/redemption': 5,
|
|
160
|
+
'etp/{transactId}/cancel': 10,
|
|
161
|
+
'etp/batch-cancel': 50, // 杠杆ETP批量撤单
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
'market': {
|
|
165
|
+
'get': {
|
|
166
|
+
'history/kline': 1,
|
|
167
|
+
'detail/merged': 1,
|
|
168
|
+
'depth': 1,
|
|
169
|
+
'trade': 1,
|
|
170
|
+
'history/trade': 1,
|
|
171
|
+
'detail': 1,
|
|
172
|
+
'tickers': 1,
|
|
173
|
+
'etp': 1, // 获取杠杆ETP实时净值
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
'public': {
|
|
177
|
+
'get': {
|
|
178
|
+
'common/symbols': 1,
|
|
179
|
+
'common/currencys': 1,
|
|
180
|
+
'common/timestamp': 1,
|
|
181
|
+
'common/exchange': 1,
|
|
182
|
+
'settings/currencys': 1, // ?language=en-US
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
'private': {
|
|
186
|
+
'get': {
|
|
187
|
+
'account/accounts': 0.2,
|
|
188
|
+
'account/accounts/{id}/balance': 0.2,
|
|
189
|
+
'account/accounts/{sub-uid}': 1,
|
|
190
|
+
'account/history': 4,
|
|
191
|
+
'cross-margin/loan-info': 1,
|
|
192
|
+
'margin/loan-info': 1,
|
|
193
|
+
'fee/fee-rate/get': 1,
|
|
194
|
+
'order/openOrders': 0.4,
|
|
195
|
+
'order/orders': 0.4,
|
|
196
|
+
'order/orders/{id}': 0.4,
|
|
197
|
+
'order/orders/{id}/matchresults': 0.4,
|
|
198
|
+
'order/orders/getClientOrder': 0.4,
|
|
199
|
+
'order/history': 1,
|
|
200
|
+
'order/matchresults': 1,
|
|
201
|
+
// 'dw/withdraw-virtual/addresses', // 查询虚拟币提现地址(Deprecated)
|
|
202
|
+
'query/deposit-withdraw': 1,
|
|
203
|
+
// 'margin/loan-info', // duplicate
|
|
204
|
+
'margin/loan-orders': 0.2,
|
|
205
|
+
'margin/accounts/balance': 0.2,
|
|
206
|
+
'cross-margin/loan-orders': 1,
|
|
207
|
+
'cross-margin/accounts/balance': 1,
|
|
208
|
+
'points/actions': 1,
|
|
209
|
+
'points/orders': 1,
|
|
210
|
+
'subuser/aggregate-balance': 10,
|
|
211
|
+
'stable-coin/exchange_rate': 1,
|
|
212
|
+
'stable-coin/quote': 1,
|
|
213
|
+
},
|
|
214
|
+
'post': {
|
|
215
|
+
'account/transfer': 1,
|
|
216
|
+
'futures/transfer': 1,
|
|
217
|
+
'order/batch-orders': 0.4,
|
|
218
|
+
'order/orders/place': 0.2,
|
|
219
|
+
'order/orders/submitCancelClientOrder': 0.2,
|
|
220
|
+
'order/orders/batchCancelOpenOrders': 0.4,
|
|
221
|
+
// 'order/orders', // 创建一个新的订单请求 (仅创建订单,不执行下单)
|
|
222
|
+
// 'order/orders/{id}/place', // 执行一个订单 (仅执行已创建的订单)
|
|
223
|
+
'order/orders/{id}/submitcancel': 0.2,
|
|
224
|
+
'order/orders/batchcancel': 0.4,
|
|
225
|
+
// 'dw/balance/transfer', // 资产划转
|
|
226
|
+
'dw/withdraw/api/create': 1,
|
|
227
|
+
// 'dw/withdraw-virtual/create', // 申请提现虚拟币
|
|
228
|
+
// 'dw/withdraw-virtual/{id}/place', // 确认申请虚拟币提现(Deprecated)
|
|
229
|
+
'dw/withdraw-virtual/{id}/cancel': 1,
|
|
230
|
+
'dw/transfer-in/margin': 10,
|
|
231
|
+
'dw/transfer-out/margin': 10,
|
|
232
|
+
'margin/orders': 10,
|
|
233
|
+
'margin/orders/{id}/repay': 10,
|
|
234
|
+
'cross-margin/transfer-in': 1,
|
|
235
|
+
'cross-margin/transfer-out': 1,
|
|
236
|
+
'cross-margin/orders': 1,
|
|
237
|
+
'cross-margin/orders/{id}/repay': 1,
|
|
238
|
+
'stable-coin/exchange': 1,
|
|
239
|
+
'subuser/transfer': 10,
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
'fees': {
|
|
244
|
+
'trading': {
|
|
245
|
+
'feeSide': 'get',
|
|
246
|
+
'tierBased': false,
|
|
247
|
+
'percentage': true,
|
|
248
|
+
'maker': this.parseNumber('0.002'),
|
|
249
|
+
'taker': this.parseNumber('0.002'),
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
'features': {
|
|
253
|
+
'spot': {
|
|
254
|
+
'sandbox': false,
|
|
255
|
+
'createOrder': {
|
|
256
|
+
'marginMode': false,
|
|
257
|
+
'triggerPrice': true,
|
|
258
|
+
'triggerPriceType': undefined,
|
|
259
|
+
'triggerDirection': false,
|
|
260
|
+
'stopLossPrice': false,
|
|
261
|
+
'takeProfitPrice': false,
|
|
262
|
+
'attachedStopLossTakeProfit': undefined,
|
|
263
|
+
'timeInForce': {
|
|
264
|
+
'IOC': false,
|
|
265
|
+
'FOK': false,
|
|
266
|
+
'PO': false,
|
|
267
|
+
'GTD': false,
|
|
268
|
+
},
|
|
269
|
+
'hedged': false,
|
|
270
|
+
'selfTradePrevention': false,
|
|
271
|
+
'trailing': false,
|
|
272
|
+
'leverage': false,
|
|
273
|
+
'marketBuyByCost': true,
|
|
274
|
+
'marketBuyRequiresPrice': false,
|
|
275
|
+
'iceberg': false,
|
|
276
|
+
},
|
|
277
|
+
'createOrders': undefined,
|
|
278
|
+
'fetchMyTrades': {
|
|
279
|
+
'marginMode': false,
|
|
280
|
+
'limit': 100,
|
|
281
|
+
'daysBack': 120,
|
|
282
|
+
'untilDays': 2,
|
|
283
|
+
'symbolRequired': false,
|
|
284
|
+
},
|
|
285
|
+
'fetchOrder': {
|
|
286
|
+
'marginMode': false,
|
|
287
|
+
'trigger': false,
|
|
288
|
+
'trailing': false,
|
|
289
|
+
'symbolRequired': false,
|
|
290
|
+
},
|
|
291
|
+
'fetchOpenOrders': {
|
|
292
|
+
'marginMode': false,
|
|
293
|
+
'limit': undefined,
|
|
294
|
+
'trigger': false,
|
|
295
|
+
'trailing': false,
|
|
296
|
+
'symbolRequired': false,
|
|
297
|
+
},
|
|
298
|
+
'fetchOrders': {
|
|
299
|
+
'marginMode': false,
|
|
300
|
+
'limit': undefined,
|
|
301
|
+
'daysBack': undefined,
|
|
302
|
+
'untilDays': undefined,
|
|
303
|
+
'trigger': false,
|
|
304
|
+
'trailing': false,
|
|
305
|
+
'symbolRequired': false,
|
|
306
|
+
},
|
|
307
|
+
'fetchClosedOrders': {
|
|
308
|
+
'marginMode': false,
|
|
309
|
+
'limit': undefined,
|
|
310
|
+
'daysBack': undefined,
|
|
311
|
+
'daysBackCanceled': undefined,
|
|
312
|
+
'untilDays': undefined,
|
|
313
|
+
'trigger': false,
|
|
314
|
+
'trailing': false,
|
|
315
|
+
'symbolRequired': false,
|
|
316
|
+
},
|
|
317
|
+
'fetchOHLCV': {
|
|
318
|
+
'limit': 2000,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
'swap': {
|
|
322
|
+
'linear': undefined,
|
|
323
|
+
'inverse': undefined,
|
|
324
|
+
},
|
|
325
|
+
'future': {
|
|
326
|
+
'linear': undefined,
|
|
327
|
+
'inverse': undefined,
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
'precisionMode': number.TICK_SIZE,
|
|
331
|
+
'exceptions': {
|
|
332
|
+
'broad': {
|
|
333
|
+
'contract is restricted of closing positions on API. Please contact customer service': errors.OnMaintenance,
|
|
334
|
+
'maintain': errors.OnMaintenance,
|
|
335
|
+
},
|
|
336
|
+
'exact': {
|
|
337
|
+
// err-code
|
|
338
|
+
'bad-request': errors.BadRequest,
|
|
339
|
+
'base-date-limit-error': errors.BadRequest,
|
|
340
|
+
'api-not-support-temp-addr': errors.PermissionDenied,
|
|
341
|
+
'timeout': errors.RequestTimeout,
|
|
342
|
+
'gateway-internal-error': errors.ExchangeNotAvailable,
|
|
343
|
+
'account-frozen-balance-insufficient-error': errors.InsufficientFunds,
|
|
344
|
+
'invalid-amount': errors.InvalidOrder,
|
|
345
|
+
'order-limitorder-amount-min-error': errors.InvalidOrder,
|
|
346
|
+
'order-limitorder-amount-max-error': errors.InvalidOrder,
|
|
347
|
+
'order-marketorder-amount-min-error': errors.InvalidOrder,
|
|
348
|
+
'order-limitorder-price-min-error': errors.InvalidOrder,
|
|
349
|
+
'order-limitorder-price-max-error': errors.InvalidOrder,
|
|
350
|
+
'order-holding-limit-failed': errors.InvalidOrder,
|
|
351
|
+
'order-orderprice-precision-error': errors.InvalidOrder,
|
|
352
|
+
'order-etp-nav-price-max-error': errors.InvalidOrder,
|
|
353
|
+
'order-orderstate-error': errors.OrderNotFound,
|
|
354
|
+
'order-queryorder-invalid': errors.OrderNotFound,
|
|
355
|
+
'order-update-error': errors.ExchangeNotAvailable,
|
|
356
|
+
'api-signature-check-failed': errors.AuthenticationError,
|
|
357
|
+
'api-signature-not-valid': errors.AuthenticationError,
|
|
358
|
+
'base-record-invalid': errors.OrderNotFound,
|
|
359
|
+
'base-symbol-trade-disabled': errors.BadSymbol,
|
|
360
|
+
'base-symbol-error': errors.BadSymbol,
|
|
361
|
+
'system-maintenance': errors.OnMaintenance,
|
|
362
|
+
// err-msg
|
|
363
|
+
'invalid symbol': errors.BadSymbol,
|
|
364
|
+
'symbol trade not open now': errors.BadSymbol,
|
|
365
|
+
'invalid-address': errors.BadRequest,
|
|
366
|
+
'base-currency-chain-error': errors.BadRequest,
|
|
367
|
+
'dw-insufficient-balance': errors.InsufficientFunds, // {"status":"error","err-code":"dw-insufficient-balance","err-msg":"Insufficient balance. You can only transfer `12.3456` at most.","data":null}
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
'options': {
|
|
371
|
+
'defaultNetwork': 'ERC20',
|
|
372
|
+
'networks': {
|
|
373
|
+
'ETH': 'erc20',
|
|
374
|
+
'TRX': 'trc20',
|
|
375
|
+
'HRC20': 'hrc20',
|
|
376
|
+
'HECO': 'hrc20',
|
|
377
|
+
'HT': 'hrc20',
|
|
378
|
+
'ALGO': 'algo',
|
|
379
|
+
'OMNI': '',
|
|
380
|
+
},
|
|
381
|
+
// https://github.com/ccxt/ccxt/issues/5376
|
|
382
|
+
'fetchOrdersByStatesMethod': 'private_get_order_orders',
|
|
383
|
+
'fetchOpenOrdersMethod': 'fetch_open_orders_v1',
|
|
384
|
+
'createMarketBuyOrderRequiresPrice': true,
|
|
385
|
+
'fetchMarketsMethod': 'publicGetCommonSymbols',
|
|
386
|
+
'fetchBalanceMethod': 'privateGetAccountAccountsIdBalance',
|
|
387
|
+
'createOrderMethod': 'privatePostOrderOrdersPlace',
|
|
388
|
+
'currencyToPrecisionRoundingMode': number.TRUNCATE,
|
|
389
|
+
'language': 'en-US',
|
|
390
|
+
'broker': {
|
|
391
|
+
'id': 'AA03022abc',
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
'commonCurrencies': {
|
|
395
|
+
// https://github.com/ccxt/ccxt/issues/6081
|
|
396
|
+
// https://github.com/ccxt/ccxt/issues/3365
|
|
397
|
+
// https://github.com/ccxt/ccxt/issues/2873
|
|
398
|
+
'GET': 'Themis',
|
|
399
|
+
'GTC': 'Game.com',
|
|
400
|
+
'HIT': 'HitChain',
|
|
401
|
+
// https://github.com/ccxt/ccxt/issues/7399
|
|
402
|
+
// https://coinmarketcap.com/currencies/pnetwork/
|
|
403
|
+
// https://coinmarketcap.com/currencies/penta/markets/
|
|
404
|
+
// https://en.cryptonomist.ch/blog/eidoo/the-edo-to-pnt-upgrade-what-you-need-to-know-updated/
|
|
405
|
+
'PNT': 'Penta',
|
|
406
|
+
'SBTC': 'Super Bitcoin',
|
|
407
|
+
'BIFI': 'Bitcoin File', // conflict with Beefy.Finance https://github.com/ccxt/ccxt/issues/8706
|
|
408
|
+
},
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* @method
|
|
413
|
+
* @name bittrade#fetchTime
|
|
414
|
+
* @description fetches the current integer timestamp in milliseconds from the exchange server
|
|
415
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
416
|
+
* @returns {int} the current integer timestamp in milliseconds from the exchange server
|
|
417
|
+
*/
|
|
418
|
+
async fetchTime(params = {}) {
|
|
419
|
+
const response = await this.publicGetCommonTimestamp(params);
|
|
420
|
+
return this.safeInteger(response, 'data');
|
|
421
|
+
}
|
|
422
|
+
async fetchTradingLimits(symbols = undefined, params = {}) {
|
|
423
|
+
// this method should not be called directly, use loadTradingLimits () instead
|
|
424
|
+
// by default it will try load withdrawal fees of all currencies (with separate requests)
|
|
425
|
+
// however if you define symbols = [ 'ETH/BTC', 'LTC/BTC' ] in args it will only load those
|
|
426
|
+
await this.loadMarkets();
|
|
427
|
+
if (symbols === undefined) {
|
|
428
|
+
symbols = this.symbols;
|
|
429
|
+
}
|
|
430
|
+
const result = {};
|
|
431
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
432
|
+
const symbol = symbols[i];
|
|
433
|
+
result[symbol] = await this.fetchTradingLimitsById(this.marketId(symbol), params);
|
|
434
|
+
}
|
|
435
|
+
return result;
|
|
436
|
+
}
|
|
437
|
+
async fetchTradingLimitsById(id, params = {}) {
|
|
438
|
+
const request = {
|
|
439
|
+
'symbol': id,
|
|
440
|
+
};
|
|
441
|
+
const response = await this.publicGetCommonExchange(this.extend(request, params));
|
|
442
|
+
//
|
|
443
|
+
// { status: "ok",
|
|
444
|
+
// "data": { symbol: "aidocbtc",
|
|
445
|
+
// "buy-limit-must-less-than": 1.1,
|
|
446
|
+
// "sell-limit-must-greater-than": 0.9,
|
|
447
|
+
// "limit-order-must-greater-than": 1,
|
|
448
|
+
// "limit-order-must-less-than": 5000000,
|
|
449
|
+
// "market-buy-order-must-greater-than": 0.0001,
|
|
450
|
+
// "market-buy-order-must-less-than": 100,
|
|
451
|
+
// "market-sell-order-must-greater-than": 1,
|
|
452
|
+
// "market-sell-order-must-less-than": 500000,
|
|
453
|
+
// "circuit-break-when-greater-than": 10000,
|
|
454
|
+
// "circuit-break-when-less-than": 10,
|
|
455
|
+
// "market-sell-order-rate-must-less-than": 0.1,
|
|
456
|
+
// "market-buy-order-rate-must-less-than": 0.1 } }
|
|
457
|
+
//
|
|
458
|
+
return this.parseTradingLimits(this.safeValue(response, 'data', {}));
|
|
459
|
+
}
|
|
460
|
+
parseTradingLimits(limits, symbol = undefined, params = {}) {
|
|
461
|
+
//
|
|
462
|
+
// { symbol: "aidocbtc",
|
|
463
|
+
// "buy-limit-must-less-than": 1.1,
|
|
464
|
+
// "sell-limit-must-greater-than": 0.9,
|
|
465
|
+
// "limit-order-must-greater-than": 1,
|
|
466
|
+
// "limit-order-must-less-than": 5000000,
|
|
467
|
+
// "market-buy-order-must-greater-than": 0.0001,
|
|
468
|
+
// "market-buy-order-must-less-than": 100,
|
|
469
|
+
// "market-sell-order-must-greater-than": 1,
|
|
470
|
+
// "market-sell-order-must-less-than": 500000,
|
|
471
|
+
// "circuit-break-when-greater-than": 10000,
|
|
472
|
+
// "circuit-break-when-less-than": 10,
|
|
473
|
+
// "market-sell-order-rate-must-less-than": 0.1,
|
|
474
|
+
// "market-buy-order-rate-must-less-than": 0.1 }
|
|
475
|
+
//
|
|
476
|
+
return {
|
|
477
|
+
'info': limits,
|
|
478
|
+
'limits': {
|
|
479
|
+
'amount': {
|
|
480
|
+
'min': this.safeNumber(limits, 'limit-order-must-greater-than'),
|
|
481
|
+
'max': this.safeNumber(limits, 'limit-order-must-less-than'),
|
|
482
|
+
},
|
|
483
|
+
},
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
costToPrecision(symbol, cost) {
|
|
487
|
+
return this.decimalToPrecision(cost, number.TRUNCATE, this.markets[symbol]['precision']['cost'], this.precisionMode);
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* @method
|
|
491
|
+
* @name bittrade#fetchMarkets
|
|
492
|
+
* @description retrieves data on all markets for huobijp
|
|
493
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
494
|
+
* @returns {object[]} an array of objects representing market data
|
|
495
|
+
*/
|
|
496
|
+
async fetchMarkets(params = {}) {
|
|
497
|
+
const method = this.options['fetchMarketsMethod'];
|
|
498
|
+
const response = await this[method](params);
|
|
499
|
+
//
|
|
500
|
+
// {
|
|
501
|
+
// "status": "ok",
|
|
502
|
+
// "data": [
|
|
503
|
+
// {
|
|
504
|
+
// "base-currency": "xrp",
|
|
505
|
+
// "quote-currency": "btc",
|
|
506
|
+
// "price-precision": 9,
|
|
507
|
+
// "amount-precision": 2,
|
|
508
|
+
// "symbol-partition": "default",
|
|
509
|
+
// "symbol": "xrpbtc",
|
|
510
|
+
// "state": "online",
|
|
511
|
+
// "value-precision": 8,
|
|
512
|
+
// "min-order-amt": 1,
|
|
513
|
+
// "max-order-amt": 5000000,
|
|
514
|
+
// "min-order-value": 0.0001,
|
|
515
|
+
// "limit-order-min-order-amt": 1,
|
|
516
|
+
// "limit-order-max-order-amt": 5000000,
|
|
517
|
+
// "limit-order-max-buy-amt": 5000000,
|
|
518
|
+
// "limit-order-max-sell-amt": 5000000,
|
|
519
|
+
// "sell-market-min-order-amt": 1,
|
|
520
|
+
// "sell-market-max-order-amt": 500000,
|
|
521
|
+
// "buy-market-max-order-value": 100,
|
|
522
|
+
// "leverage-ratio": 5,
|
|
523
|
+
// "super-margin-leverage-ratio": 3,
|
|
524
|
+
// "api-trading": "enabled",
|
|
525
|
+
// "tags": ""
|
|
526
|
+
// }
|
|
527
|
+
// ...
|
|
528
|
+
// ]
|
|
529
|
+
// }
|
|
530
|
+
//
|
|
531
|
+
const markets = this.safeValue(response, 'data', []);
|
|
532
|
+
const numMarkets = markets.length;
|
|
533
|
+
if (numMarkets < 1) {
|
|
534
|
+
throw new errors.NetworkError(this.id + ' fetchMarkets() returned empty response: ' + this.json(markets));
|
|
535
|
+
}
|
|
536
|
+
const result = [];
|
|
537
|
+
for (let i = 0; i < markets.length; i++) {
|
|
538
|
+
const market = markets[i];
|
|
539
|
+
const baseId = this.safeString(market, 'base-currency');
|
|
540
|
+
const quoteId = this.safeString(market, 'quote-currency');
|
|
541
|
+
const base = this.safeCurrencyCode(baseId);
|
|
542
|
+
const quote = this.safeCurrencyCode(quoteId);
|
|
543
|
+
const state = this.safeString(market, 'state');
|
|
544
|
+
const leverageRatio = this.safeString(market, 'leverage-ratio', '1');
|
|
545
|
+
const superLeverageRatio = this.safeString(market, 'super-margin-leverage-ratio', '1');
|
|
546
|
+
const margin = Precise["default"].stringGt(leverageRatio, '1') || Precise["default"].stringGt(superLeverageRatio, '1');
|
|
547
|
+
const fee = (base === 'OMG') ? this.parseNumber('0') : this.parseNumber('0.002');
|
|
548
|
+
result.push({
|
|
549
|
+
'id': baseId + quoteId,
|
|
550
|
+
'symbol': base + '/' + quote,
|
|
551
|
+
'base': base,
|
|
552
|
+
'quote': quote,
|
|
553
|
+
'settle': undefined,
|
|
554
|
+
'baseId': baseId,
|
|
555
|
+
'quoteId': quoteId,
|
|
556
|
+
'settleId': undefined,
|
|
557
|
+
'type': 'spot',
|
|
558
|
+
'spot': true,
|
|
559
|
+
'margin': margin,
|
|
560
|
+
'swap': false,
|
|
561
|
+
'future': false,
|
|
562
|
+
'option': false,
|
|
563
|
+
'active': (state === 'online'),
|
|
564
|
+
'contract': false,
|
|
565
|
+
'linear': undefined,
|
|
566
|
+
'inverse': undefined,
|
|
567
|
+
'taker': fee,
|
|
568
|
+
'maker': fee,
|
|
569
|
+
'contractSize': undefined,
|
|
570
|
+
'expiry': undefined,
|
|
571
|
+
'expiryDatetime': undefined,
|
|
572
|
+
'strike': undefined,
|
|
573
|
+
'optionType': undefined,
|
|
574
|
+
'precision': {
|
|
575
|
+
'price': this.parseNumber(this.parsePrecision(this.safeString(market, 'price-precision'))),
|
|
576
|
+
'amount': this.parseNumber(this.parsePrecision(this.safeString(market, 'amount-precision'))),
|
|
577
|
+
'cost': this.parseNumber(this.parsePrecision(this.safeString(market, 'value-precision'))),
|
|
578
|
+
},
|
|
579
|
+
'limits': {
|
|
580
|
+
'leverage': {
|
|
581
|
+
'min': this.parseNumber('1'),
|
|
582
|
+
'max': this.parseNumber(leverageRatio),
|
|
583
|
+
'superMax': this.parseNumber(superLeverageRatio),
|
|
584
|
+
},
|
|
585
|
+
'amount': {
|
|
586
|
+
'min': this.safeNumber(market, 'min-order-amt'),
|
|
587
|
+
'max': this.safeNumber(market, 'max-order-amt'),
|
|
588
|
+
},
|
|
589
|
+
'price': {
|
|
590
|
+
'min': undefined,
|
|
591
|
+
'max': undefined,
|
|
592
|
+
},
|
|
593
|
+
'cost': {
|
|
594
|
+
'min': this.safeNumber(market, 'min-order-value'),
|
|
595
|
+
'max': undefined,
|
|
596
|
+
},
|
|
597
|
+
},
|
|
598
|
+
'created': undefined,
|
|
599
|
+
'info': market,
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
return result;
|
|
603
|
+
}
|
|
604
|
+
parseTicker(ticker, market = undefined) {
|
|
605
|
+
//
|
|
606
|
+
// fetchTicker
|
|
607
|
+
//
|
|
608
|
+
// {
|
|
609
|
+
// "amount": 26228.672978342216,
|
|
610
|
+
// "open": 9078.95,
|
|
611
|
+
// "close": 9146.86,
|
|
612
|
+
// "high": 9155.41,
|
|
613
|
+
// "id": 209988544334,
|
|
614
|
+
// "count": 265846,
|
|
615
|
+
// "low": 8988.0,
|
|
616
|
+
// "version": 209988544334,
|
|
617
|
+
// "ask": [ 9146.87, 0.156134 ],
|
|
618
|
+
// "vol": 2.3822168242201668E8,
|
|
619
|
+
// "bid": [ 9146.86, 0.080758 ],
|
|
620
|
+
// }
|
|
621
|
+
//
|
|
622
|
+
// fetchTickers
|
|
623
|
+
// {
|
|
624
|
+
// "symbol": "bhdht",
|
|
625
|
+
// "open": 2.3938,
|
|
626
|
+
// "high": 2.4151,
|
|
627
|
+
// "low": 2.3323,
|
|
628
|
+
// "close": 2.3909,
|
|
629
|
+
// "amount": 628.992,
|
|
630
|
+
// "vol": 1493.71841095,
|
|
631
|
+
// "count": 2088,
|
|
632
|
+
// "bid": 2.3643,
|
|
633
|
+
// "bidSize": 0.7136,
|
|
634
|
+
// "ask": 2.4061,
|
|
635
|
+
// "askSize": 0.4156
|
|
636
|
+
// }
|
|
637
|
+
//
|
|
638
|
+
const symbol = this.safeSymbol(undefined, market);
|
|
639
|
+
const timestamp = this.safeInteger(ticker, 'ts');
|
|
640
|
+
let bid = undefined;
|
|
641
|
+
let bidVolume = undefined;
|
|
642
|
+
let ask = undefined;
|
|
643
|
+
let askVolume = undefined;
|
|
644
|
+
if ('bid' in ticker) {
|
|
645
|
+
if (Array.isArray(ticker['bid'])) {
|
|
646
|
+
bid = this.safeString(ticker['bid'], 0);
|
|
647
|
+
bidVolume = this.safeString(ticker['bid'], 1);
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
bid = this.safeString(ticker, 'bid');
|
|
651
|
+
bidVolume = this.safeString(ticker, 'bidSize');
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if ('ask' in ticker) {
|
|
655
|
+
if (Array.isArray(ticker['ask'])) {
|
|
656
|
+
ask = this.safeString(ticker['ask'], 0);
|
|
657
|
+
askVolume = this.safeString(ticker['ask'], 1);
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
ask = this.safeString(ticker, 'ask');
|
|
661
|
+
askVolume = this.safeString(ticker, 'askSize');
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
const open = this.safeString(ticker, 'open');
|
|
665
|
+
const close = this.safeString(ticker, 'close');
|
|
666
|
+
const baseVolume = this.safeString(ticker, 'amount');
|
|
667
|
+
const quoteVolume = this.safeString(ticker, 'vol');
|
|
668
|
+
return this.safeTicker({
|
|
669
|
+
'symbol': symbol,
|
|
670
|
+
'timestamp': timestamp,
|
|
671
|
+
'datetime': this.iso8601(timestamp),
|
|
672
|
+
'high': this.safeString(ticker, 'high'),
|
|
673
|
+
'low': this.safeString(ticker, 'low'),
|
|
674
|
+
'bid': bid,
|
|
675
|
+
'bidVolume': bidVolume,
|
|
676
|
+
'ask': ask,
|
|
677
|
+
'askVolume': askVolume,
|
|
678
|
+
'vwap': undefined,
|
|
679
|
+
'open': open,
|
|
680
|
+
'close': close,
|
|
681
|
+
'last': close,
|
|
682
|
+
'previousClose': undefined,
|
|
683
|
+
'change': undefined,
|
|
684
|
+
'percentage': undefined,
|
|
685
|
+
'average': undefined,
|
|
686
|
+
'baseVolume': baseVolume,
|
|
687
|
+
'quoteVolume': quoteVolume,
|
|
688
|
+
'info': ticker,
|
|
689
|
+
}, market);
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* @method
|
|
693
|
+
* @name bittrade#fetchOrderBook
|
|
694
|
+
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
695
|
+
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
696
|
+
* @param {int} [limit] the maximum amount of order book entries to return
|
|
697
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
698
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
699
|
+
*/
|
|
700
|
+
async fetchOrderBook(symbol, limit = undefined, params = {}) {
|
|
701
|
+
await this.loadMarkets();
|
|
702
|
+
const market = this.market(symbol);
|
|
703
|
+
const request = {
|
|
704
|
+
'symbol': market['id'],
|
|
705
|
+
'type': 'step0',
|
|
706
|
+
};
|
|
707
|
+
const response = await this.marketGetDepth(this.extend(request, params));
|
|
708
|
+
//
|
|
709
|
+
// {
|
|
710
|
+
// "status": "ok",
|
|
711
|
+
// "ch": "market.btcusdt.depth.step0",
|
|
712
|
+
// "ts": 1583474832790,
|
|
713
|
+
// "tick": {
|
|
714
|
+
// "bids": [
|
|
715
|
+
// [ 9100.290000000000000000, 0.200000000000000000 ],
|
|
716
|
+
// [ 9099.820000000000000000, 0.200000000000000000 ],
|
|
717
|
+
// [ 9099.610000000000000000, 0.205000000000000000 ],
|
|
718
|
+
// ],
|
|
719
|
+
// "asks": [
|
|
720
|
+
// [ 9100.640000000000000000, 0.005904000000000000 ],
|
|
721
|
+
// [ 9101.010000000000000000, 0.287311000000000000 ],
|
|
722
|
+
// [ 9101.030000000000000000, 0.012121000000000000 ],
|
|
723
|
+
// ],
|
|
724
|
+
// "ts":1583474832008,
|
|
725
|
+
// "version":104999698780
|
|
726
|
+
// }
|
|
727
|
+
// }
|
|
728
|
+
//
|
|
729
|
+
if ('tick' in response) {
|
|
730
|
+
if (!response['tick']) {
|
|
731
|
+
throw new errors.BadSymbol(this.id + ' fetchOrderBook() returned empty response: ' + this.json(response));
|
|
732
|
+
}
|
|
733
|
+
const tick = this.safeValue(response, 'tick');
|
|
734
|
+
const timestamp = this.safeInteger(tick, 'ts', this.safeInteger(response, 'ts'));
|
|
735
|
+
const result = this.parseOrderBook(tick, symbol, timestamp);
|
|
736
|
+
result['nonce'] = this.safeInteger(tick, 'version');
|
|
737
|
+
return result;
|
|
738
|
+
}
|
|
739
|
+
throw new errors.ExchangeError(this.id + ' fetchOrderBook() returned unrecognized response: ' + this.json(response));
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* @method
|
|
743
|
+
* @name bittrade#fetchTicker
|
|
744
|
+
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
|
|
745
|
+
* @param {string} symbol unified symbol of the market to fetch the ticker for
|
|
746
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
747
|
+
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
748
|
+
*/
|
|
749
|
+
async fetchTicker(symbol, params = {}) {
|
|
750
|
+
await this.loadMarkets();
|
|
751
|
+
const market = this.market(symbol);
|
|
752
|
+
const request = {
|
|
753
|
+
'symbol': market['id'],
|
|
754
|
+
};
|
|
755
|
+
const response = await this.marketGetDetailMerged(this.extend(request, params));
|
|
756
|
+
//
|
|
757
|
+
// {
|
|
758
|
+
// "status": "ok",
|
|
759
|
+
// "ch": "market.btcusdt.detail.merged",
|
|
760
|
+
// "ts": 1583494336669,
|
|
761
|
+
// "tick": {
|
|
762
|
+
// "amount": 26228.672978342216,
|
|
763
|
+
// "open": 9078.95,
|
|
764
|
+
// "close": 9146.86,
|
|
765
|
+
// "high": 9155.41,
|
|
766
|
+
// "id": 209988544334,
|
|
767
|
+
// "count": 265846,
|
|
768
|
+
// "low": 8988.0,
|
|
769
|
+
// "version": 209988544334,
|
|
770
|
+
// "ask": [ 9146.87, 0.156134 ],
|
|
771
|
+
// "vol": 2.3822168242201668E8,
|
|
772
|
+
// "bid": [ 9146.86, 0.080758 ],
|
|
773
|
+
// }
|
|
774
|
+
// }
|
|
775
|
+
//
|
|
776
|
+
const ticker = this.parseTicker(response['tick'], market);
|
|
777
|
+
const timestamp = this.safeInteger(response, 'ts');
|
|
778
|
+
ticker['timestamp'] = timestamp;
|
|
779
|
+
ticker['datetime'] = this.iso8601(timestamp);
|
|
780
|
+
return ticker;
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* @method
|
|
784
|
+
* @name bittrade#fetchTickers
|
|
785
|
+
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
|
|
786
|
+
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
|
|
787
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
788
|
+
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
789
|
+
*/
|
|
790
|
+
async fetchTickers(symbols = undefined, params = {}) {
|
|
791
|
+
await this.loadMarkets();
|
|
792
|
+
symbols = this.marketSymbols(symbols);
|
|
793
|
+
const response = await this.marketGetTickers(params);
|
|
794
|
+
const tickers = this.safeValue(response, 'data', []);
|
|
795
|
+
const timestamp = this.safeInteger(response, 'ts');
|
|
796
|
+
const result = {};
|
|
797
|
+
for (let i = 0; i < tickers.length; i++) {
|
|
798
|
+
const marketId = this.safeString(tickers[i], 'symbol');
|
|
799
|
+
const market = this.safeMarket(marketId);
|
|
800
|
+
const symbol = market['symbol'];
|
|
801
|
+
const ticker = this.parseTicker(tickers[i], market);
|
|
802
|
+
ticker['timestamp'] = timestamp;
|
|
803
|
+
ticker['datetime'] = this.iso8601(timestamp);
|
|
804
|
+
result[symbol] = ticker;
|
|
805
|
+
}
|
|
806
|
+
return this.filterByArrayTickers(result, 'symbol', symbols);
|
|
807
|
+
}
|
|
808
|
+
parseTrade(trade, market = undefined) {
|
|
809
|
+
//
|
|
810
|
+
// fetchTrades (public)
|
|
811
|
+
//
|
|
812
|
+
// {
|
|
813
|
+
// "amount": 0.010411000000000000,
|
|
814
|
+
// "trade-id": 102090736910,
|
|
815
|
+
// "ts": 1583497692182,
|
|
816
|
+
// "id": 10500517034273194594947,
|
|
817
|
+
// "price": 9096.050000000000000000,
|
|
818
|
+
// "direction": "sell"
|
|
819
|
+
// }
|
|
820
|
+
//
|
|
821
|
+
// fetchMyTrades (private)
|
|
822
|
+
//
|
|
823
|
+
// {
|
|
824
|
+
// "symbol": "swftcbtc",
|
|
825
|
+
// "fee-currency": "swftc",
|
|
826
|
+
// "filled-fees": "0",
|
|
827
|
+
// "source": "spot-api",
|
|
828
|
+
// "id": 83789509854000,
|
|
829
|
+
// "type": "buy-limit",
|
|
830
|
+
// "order-id": 83711103204909,
|
|
831
|
+
// 'filled-points': "0.005826843283532154",
|
|
832
|
+
// "fee-deduct-currency": "ht",
|
|
833
|
+
// 'filled-amount': "45941.53",
|
|
834
|
+
// "price": "0.0000001401",
|
|
835
|
+
// "created-at": 1597933260729,
|
|
836
|
+
// "match-id": 100087455560,
|
|
837
|
+
// "role": "maker",
|
|
838
|
+
// "trade-id": 100050305348
|
|
839
|
+
// },
|
|
840
|
+
//
|
|
841
|
+
const marketId = this.safeString(trade, 'symbol');
|
|
842
|
+
const symbol = this.safeSymbol(marketId, market);
|
|
843
|
+
const timestamp = this.safeInteger2(trade, 'ts', 'created-at');
|
|
844
|
+
const order = this.safeString(trade, 'order-id');
|
|
845
|
+
let side = this.safeString(trade, 'direction');
|
|
846
|
+
let type = this.safeString(trade, 'type');
|
|
847
|
+
if (type !== undefined) {
|
|
848
|
+
const typeParts = type.split('-');
|
|
849
|
+
side = typeParts[0];
|
|
850
|
+
type = typeParts[1];
|
|
851
|
+
}
|
|
852
|
+
const takerOrMaker = this.safeString(trade, 'role');
|
|
853
|
+
const price = this.safeString(trade, 'price');
|
|
854
|
+
const amount = this.safeString2(trade, 'filled-amount', 'amount');
|
|
855
|
+
const cost = Precise["default"].stringMul(price, amount);
|
|
856
|
+
let fee = undefined;
|
|
857
|
+
let feeCost = this.safeString(trade, 'filled-fees');
|
|
858
|
+
let feeCurrency = this.safeCurrencyCode(this.safeString(trade, 'fee-currency'));
|
|
859
|
+
const filledPoints = this.safeString(trade, 'filled-points');
|
|
860
|
+
if (filledPoints !== undefined) {
|
|
861
|
+
if ((feeCost === undefined) || (Precise["default"].stringEq(feeCost, '0.0'))) {
|
|
862
|
+
feeCost = filledPoints;
|
|
863
|
+
feeCurrency = this.safeCurrencyCode(this.safeString(trade, 'fee-deduct-currency'));
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
if (feeCost !== undefined) {
|
|
867
|
+
fee = {
|
|
868
|
+
'cost': feeCost,
|
|
869
|
+
'currency': feeCurrency,
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
const tradeId = this.safeString2(trade, 'trade-id', 'tradeId');
|
|
873
|
+
const id = this.safeString(trade, 'id', tradeId);
|
|
874
|
+
return this.safeTrade({
|
|
875
|
+
'info': trade,
|
|
876
|
+
'id': id,
|
|
877
|
+
'symbol': symbol,
|
|
878
|
+
'order': order,
|
|
879
|
+
'timestamp': timestamp,
|
|
880
|
+
'datetime': this.iso8601(timestamp),
|
|
881
|
+
'type': type,
|
|
882
|
+
'side': side,
|
|
883
|
+
'takerOrMaker': takerOrMaker,
|
|
884
|
+
'price': price,
|
|
885
|
+
'amount': amount,
|
|
886
|
+
'cost': cost,
|
|
887
|
+
'fee': fee,
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* @method
|
|
892
|
+
* @name bittrade#fetchOrderTrades
|
|
893
|
+
* @description fetch all the trades made from a single order
|
|
894
|
+
* @param {string} id order id
|
|
895
|
+
* @param {string} symbol unified market symbol
|
|
896
|
+
* @param {int} [since] the earliest time in ms to fetch trades for
|
|
897
|
+
* @param {int} [limit] the maximum number of trades to retrieve
|
|
898
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
899
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
|
|
900
|
+
*/
|
|
901
|
+
async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
902
|
+
await this.loadMarkets();
|
|
903
|
+
const request = {
|
|
904
|
+
'id': id,
|
|
905
|
+
};
|
|
906
|
+
const response = await this.privateGetOrderOrdersIdMatchresults(this.extend(request, params));
|
|
907
|
+
return this.parseTrades(response['data'], undefined, since, limit);
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* @method
|
|
911
|
+
* @name bittrade#fetchMyTrades
|
|
912
|
+
* @description fetch all trades made by the user
|
|
913
|
+
* @param {string} symbol unified market symbol
|
|
914
|
+
* @param {int} [since] the earliest time in ms to fetch trades for
|
|
915
|
+
* @param {int} [limit] the maximum number of trades structures to retrieve
|
|
916
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
917
|
+
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
|
|
918
|
+
*/
|
|
919
|
+
async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
920
|
+
await this.loadMarkets();
|
|
921
|
+
let market = undefined;
|
|
922
|
+
const request = {};
|
|
923
|
+
if (symbol !== undefined) {
|
|
924
|
+
market = this.market(symbol);
|
|
925
|
+
request['symbol'] = market['id'];
|
|
926
|
+
}
|
|
927
|
+
if (limit !== undefined) {
|
|
928
|
+
request['size'] = limit; // 1-100 orders, default is 100
|
|
929
|
+
}
|
|
930
|
+
if (since !== undefined) {
|
|
931
|
+
request['start-time'] = since; // a date within 120 days from today
|
|
932
|
+
// request['end-time'] = this.sum (since, 172800000); // 48 hours window
|
|
933
|
+
}
|
|
934
|
+
const response = await this.privateGetOrderMatchresults(this.extend(request, params));
|
|
935
|
+
return this.parseTrades(response['data'], market, since, limit);
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* @method
|
|
939
|
+
* @name bittrade#fetchTrades
|
|
940
|
+
* @description get the list of most recent trades for a particular symbol
|
|
941
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
942
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
943
|
+
* @param {int} [limit] the maximum amount of trades to fetch
|
|
944
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
945
|
+
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
946
|
+
*/
|
|
947
|
+
async fetchTrades(symbol, since = undefined, limit = 1000, params = {}) {
|
|
948
|
+
await this.loadMarkets();
|
|
949
|
+
const market = this.market(symbol);
|
|
950
|
+
const request = {
|
|
951
|
+
'symbol': market['id'],
|
|
952
|
+
};
|
|
953
|
+
if (limit !== undefined) {
|
|
954
|
+
request['size'] = Math.min(limit, 2000);
|
|
955
|
+
}
|
|
956
|
+
const response = await this.marketGetHistoryTrade(this.extend(request, params));
|
|
957
|
+
//
|
|
958
|
+
// {
|
|
959
|
+
// "status": "ok",
|
|
960
|
+
// "ch": "market.btcusdt.trade.detail",
|
|
961
|
+
// "ts": 1583497692365,
|
|
962
|
+
// "data": [
|
|
963
|
+
// {
|
|
964
|
+
// "id": 105005170342,
|
|
965
|
+
// "ts": 1583497692182,
|
|
966
|
+
// "data": [
|
|
967
|
+
// {
|
|
968
|
+
// "amount": 0.010411000000000000,
|
|
969
|
+
// "trade-id": 102090736910,
|
|
970
|
+
// "ts": 1583497692182,
|
|
971
|
+
// "id": 10500517034273194594947,
|
|
972
|
+
// "price": 9096.050000000000000000,
|
|
973
|
+
// "direction": "sell"
|
|
974
|
+
// }
|
|
975
|
+
// ]
|
|
976
|
+
// },
|
|
977
|
+
// // ...
|
|
978
|
+
// ]
|
|
979
|
+
// }
|
|
980
|
+
//
|
|
981
|
+
const data = this.safeValue(response, 'data', []);
|
|
982
|
+
let result = [];
|
|
983
|
+
for (let i = 0; i < data.length; i++) {
|
|
984
|
+
const trades = this.safeValue(data[i], 'data', []);
|
|
985
|
+
for (let j = 0; j < trades.length; j++) {
|
|
986
|
+
const trade = this.parseTrade(trades[j], market);
|
|
987
|
+
result.push(trade);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
result = this.sortBy(result, 'timestamp');
|
|
991
|
+
return this.filterBySymbolSinceLimit(result, market['symbol'], since, limit);
|
|
992
|
+
}
|
|
993
|
+
parseOHLCV(ohlcv, market = undefined) {
|
|
994
|
+
//
|
|
995
|
+
// {
|
|
996
|
+
// "amount":1.2082,
|
|
997
|
+
// "open":0.025096,
|
|
998
|
+
// "close":0.025095,
|
|
999
|
+
// "high":0.025096,
|
|
1000
|
+
// "id":1591515300,
|
|
1001
|
+
// "count":6,
|
|
1002
|
+
// "low":0.025095,
|
|
1003
|
+
// "vol":0.0303205097
|
|
1004
|
+
// }
|
|
1005
|
+
//
|
|
1006
|
+
return [
|
|
1007
|
+
this.safeTimestamp(ohlcv, 'id'),
|
|
1008
|
+
this.safeNumber(ohlcv, 'open'),
|
|
1009
|
+
this.safeNumber(ohlcv, 'high'),
|
|
1010
|
+
this.safeNumber(ohlcv, 'low'),
|
|
1011
|
+
this.safeNumber(ohlcv, 'close'),
|
|
1012
|
+
this.safeNumber(ohlcv, 'amount'),
|
|
1013
|
+
];
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* @method
|
|
1017
|
+
* @name bittrade#fetchOHLCV
|
|
1018
|
+
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
|
1019
|
+
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
|
|
1020
|
+
* @param {string} timeframe the length of time each candle represents
|
|
1021
|
+
* @param {int} [since] timestamp in ms of the earliest candle to fetch
|
|
1022
|
+
* @param {int} [limit] the maximum amount of candles to fetch
|
|
1023
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1024
|
+
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
|
|
1025
|
+
*/
|
|
1026
|
+
async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = 1000, params = {}) {
|
|
1027
|
+
await this.loadMarkets();
|
|
1028
|
+
const market = this.market(symbol);
|
|
1029
|
+
const request = {
|
|
1030
|
+
'symbol': market['id'],
|
|
1031
|
+
'period': this.safeString(this.timeframes, timeframe, timeframe),
|
|
1032
|
+
};
|
|
1033
|
+
if (limit !== undefined) {
|
|
1034
|
+
request['size'] = Math.min(limit, 2000);
|
|
1035
|
+
}
|
|
1036
|
+
const response = await this.marketGetHistoryKline(this.extend(request, params));
|
|
1037
|
+
//
|
|
1038
|
+
// {
|
|
1039
|
+
// "status":"ok",
|
|
1040
|
+
// "ch":"market.ethbtc.kline.1min",
|
|
1041
|
+
// "ts":1591515374371,
|
|
1042
|
+
// "data":[
|
|
1043
|
+
// {"amount":0.0,"open":0.025095,"close":0.025095,"high":0.025095,"id":1591515360,"count":0,"low":0.025095,"vol":0.0},
|
|
1044
|
+
// {"amount":1.2082,"open":0.025096,"close":0.025095,"high":0.025096,"id":1591515300,"count":6,"low":0.025095,"vol":0.0303205097},
|
|
1045
|
+
// {"amount":0.0648,"open":0.025096,"close":0.025096,"high":0.025096,"id":1591515240,"count":2,"low":0.025096,"vol":0.0016262208},
|
|
1046
|
+
// ]
|
|
1047
|
+
// }
|
|
1048
|
+
//
|
|
1049
|
+
const data = this.safeList(response, 'data', []);
|
|
1050
|
+
return this.parseOHLCVs(data, market, timeframe, since, limit);
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* @method
|
|
1054
|
+
* @name bittrade#fetchAccounts
|
|
1055
|
+
* @description fetch all the accounts associated with a profile
|
|
1056
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1057
|
+
* @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/#/?id=account-structure} indexed by the account type
|
|
1058
|
+
*/
|
|
1059
|
+
async fetchAccounts(params = {}) {
|
|
1060
|
+
await this.loadMarkets();
|
|
1061
|
+
const response = await this.privateGetAccountAccounts(params);
|
|
1062
|
+
return response['data'];
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* @method
|
|
1066
|
+
* @name bittrade#fetchCurrencies
|
|
1067
|
+
* @description fetches all available currencies on an exchange
|
|
1068
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1069
|
+
* @returns {object} an associative dictionary of currencies
|
|
1070
|
+
*/
|
|
1071
|
+
async fetchCurrencies(params = {}) {
|
|
1072
|
+
const request = {
|
|
1073
|
+
'language': this.options['language'],
|
|
1074
|
+
};
|
|
1075
|
+
const response = await this.publicGetSettingsCurrencys(this.extend(request, params));
|
|
1076
|
+
//
|
|
1077
|
+
// {
|
|
1078
|
+
// "status":"ok",
|
|
1079
|
+
// "data":[
|
|
1080
|
+
// {
|
|
1081
|
+
// "currency-addr-with-tag":false,
|
|
1082
|
+
// "fast-confirms":12,
|
|
1083
|
+
// "safe-confirms":12,
|
|
1084
|
+
// "currency-type":"eth",
|
|
1085
|
+
// "quote-currency":true,
|
|
1086
|
+
// "withdraw-enable-timestamp":1609430400000,
|
|
1087
|
+
// "deposit-enable-timestamp":1609430400000,
|
|
1088
|
+
// "currency-partition":"all",
|
|
1089
|
+
// "support-sites":["OTC","INSTITUTION","MINEPOOL"],
|
|
1090
|
+
// "withdraw-precision":6,
|
|
1091
|
+
// "visible-assets-timestamp":1508839200000,
|
|
1092
|
+
// "deposit-min-amount":"1",
|
|
1093
|
+
// "withdraw-min-amount":"10",
|
|
1094
|
+
// "show-precision":"8",
|
|
1095
|
+
// "tags":"",
|
|
1096
|
+
// "weight":23,
|
|
1097
|
+
// "full-name":"Tether USDT",
|
|
1098
|
+
// "otc-enable":1,
|
|
1099
|
+
// "visible":true,
|
|
1100
|
+
// "white-enabled":false,
|
|
1101
|
+
// "country-disabled":false,
|
|
1102
|
+
// "deposit-enabled":true,
|
|
1103
|
+
// "withdraw-enabled":true,
|
|
1104
|
+
// "name":"usdt",
|
|
1105
|
+
// "state":"online",
|
|
1106
|
+
// "display-name":"USDT",
|
|
1107
|
+
// "suspend-withdraw-desc":null,
|
|
1108
|
+
// "withdraw-desc":"Minimum withdrawal amount: 10 USDT (ERC20). !>_<!To ensure the safety of your funds, your withdrawal request will be manually reviewed if your security strategy or password is changed. Please wait for phone calls or emails from our staff.!>_<!Please make sure that your computer and browser are secure and your information is protected from being tampered or leaked.",
|
|
1109
|
+
// "suspend-deposit-desc":null,
|
|
1110
|
+
// "deposit-desc":"Please don’t deposit any other digital assets except USDT to the above address. Otherwise, you may lose your assets permanently. !>_<!Depositing to the above address requires confirmations of the entire network. It will arrive after 12 confirmations, and it will be available to withdraw after 12 confirmations. !>_<!Minimum deposit amount: 1 USDT. Any deposits less than the minimum will not be credited or refunded.!>_<!Your deposit address won’t change often. If there are any changes, we will notify you via announcement or email.!>_<!Please make sure that your computer and browser are secure and your information is protected from being tampered or leaked.",
|
|
1111
|
+
// "suspend-visible-desc":null
|
|
1112
|
+
// }
|
|
1113
|
+
// ]
|
|
1114
|
+
// }
|
|
1115
|
+
//
|
|
1116
|
+
const currencies = this.safeValue(response, 'data', []);
|
|
1117
|
+
const result = {};
|
|
1118
|
+
for (let i = 0; i < currencies.length; i++) {
|
|
1119
|
+
const currency = currencies[i];
|
|
1120
|
+
const id = this.safeValue(currency, 'name');
|
|
1121
|
+
const code = this.safeCurrencyCode(id);
|
|
1122
|
+
const depositEnabled = this.safeValue(currency, 'deposit-enabled');
|
|
1123
|
+
const withdrawEnabled = this.safeValue(currency, 'withdraw-enabled');
|
|
1124
|
+
const countryDisabled = this.safeValue(currency, 'country-disabled');
|
|
1125
|
+
const visible = this.safeBool(currency, 'visible', false);
|
|
1126
|
+
const state = this.safeString(currency, 'state');
|
|
1127
|
+
const active = visible && depositEnabled && withdrawEnabled && (state === 'online') && !countryDisabled;
|
|
1128
|
+
const name = this.safeString(currency, 'display-name');
|
|
1129
|
+
const precision = this.parseNumber(this.parsePrecision(this.safeString(currency, 'withdraw-precision')));
|
|
1130
|
+
result[code] = {
|
|
1131
|
+
'id': id,
|
|
1132
|
+
'code': code,
|
|
1133
|
+
'type': 'crypto',
|
|
1134
|
+
// 'payin': currency['deposit-enabled'],
|
|
1135
|
+
// 'payout': currency['withdraw-enabled'],
|
|
1136
|
+
// 'transfer': undefined,
|
|
1137
|
+
'name': name,
|
|
1138
|
+
'active': active,
|
|
1139
|
+
'deposit': depositEnabled,
|
|
1140
|
+
'withdraw': withdrawEnabled,
|
|
1141
|
+
'fee': undefined,
|
|
1142
|
+
'precision': precision,
|
|
1143
|
+
'networks': undefined,
|
|
1144
|
+
'limits': {
|
|
1145
|
+
'amount': {
|
|
1146
|
+
'min': precision,
|
|
1147
|
+
'max': undefined,
|
|
1148
|
+
},
|
|
1149
|
+
'deposit': {
|
|
1150
|
+
'min': this.safeNumber(currency, 'deposit-min-amount'),
|
|
1151
|
+
'max': undefined,
|
|
1152
|
+
},
|
|
1153
|
+
'withdraw': {
|
|
1154
|
+
'min': this.safeNumber(currency, 'withdraw-min-amount'),
|
|
1155
|
+
'max': undefined,
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1158
|
+
'info': currency,
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
return result;
|
|
1162
|
+
}
|
|
1163
|
+
parseBalance(response) {
|
|
1164
|
+
const balances = this.safeValue(response['data'], 'list', []);
|
|
1165
|
+
const result = { 'info': response };
|
|
1166
|
+
for (let i = 0; i < balances.length; i++) {
|
|
1167
|
+
const balance = balances[i];
|
|
1168
|
+
const currencyId = this.safeString(balance, 'currency');
|
|
1169
|
+
const code = this.safeCurrencyCode(currencyId);
|
|
1170
|
+
let account = undefined;
|
|
1171
|
+
if (code in result) {
|
|
1172
|
+
account = result[code];
|
|
1173
|
+
}
|
|
1174
|
+
else {
|
|
1175
|
+
account = this.account();
|
|
1176
|
+
}
|
|
1177
|
+
if (balance['type'] === 'trade') {
|
|
1178
|
+
account['free'] = this.safeString(balance, 'balance');
|
|
1179
|
+
}
|
|
1180
|
+
if (balance['type'] === 'frozen') {
|
|
1181
|
+
account['used'] = this.safeString(balance, 'balance');
|
|
1182
|
+
}
|
|
1183
|
+
result[code] = account;
|
|
1184
|
+
}
|
|
1185
|
+
return this.safeBalance(result);
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* @method
|
|
1189
|
+
* @name bittrade#fetchBalance
|
|
1190
|
+
* @description query for balance and get the amount of funds available for trading or funds locked in orders
|
|
1191
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1192
|
+
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
|
|
1193
|
+
*/
|
|
1194
|
+
async fetchBalance(params = {}) {
|
|
1195
|
+
await this.loadMarkets();
|
|
1196
|
+
await this.loadAccounts();
|
|
1197
|
+
const method = this.options['fetchBalanceMethod'];
|
|
1198
|
+
const request = {
|
|
1199
|
+
'id': this.accounts[0]['id'],
|
|
1200
|
+
};
|
|
1201
|
+
const response = await this[method](this.extend(request, params));
|
|
1202
|
+
return this.parseBalance(response);
|
|
1203
|
+
}
|
|
1204
|
+
async fetchOrdersByStates(states, symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1205
|
+
await this.loadMarkets();
|
|
1206
|
+
const request = {
|
|
1207
|
+
'states': states,
|
|
1208
|
+
};
|
|
1209
|
+
let market = undefined;
|
|
1210
|
+
if (symbol !== undefined) {
|
|
1211
|
+
market = this.market(symbol);
|
|
1212
|
+
request['symbol'] = market['id'];
|
|
1213
|
+
}
|
|
1214
|
+
const method = this.safeString(this.options, 'fetchOrdersByStatesMethod', 'private_get_order_orders');
|
|
1215
|
+
const response = await this[method](this.extend(request, params));
|
|
1216
|
+
//
|
|
1217
|
+
// { "status": "ok",
|
|
1218
|
+
// "data": [ { id: 13997833014,
|
|
1219
|
+
// "symbol": "ethbtc",
|
|
1220
|
+
// "account-id": 3398321,
|
|
1221
|
+
// "amount": "0.045000000000000000",
|
|
1222
|
+
// "price": "0.034014000000000000",
|
|
1223
|
+
// "created-at": 1545836976871,
|
|
1224
|
+
// "type": "sell-limit",
|
|
1225
|
+
// "field-amount": "0.045000000000000000",
|
|
1226
|
+
// "field-cash-amount": "0.001530630000000000",
|
|
1227
|
+
// "field-fees": "0.000003061260000000",
|
|
1228
|
+
// "finished-at": 1545837948214,
|
|
1229
|
+
// "source": "spot-api",
|
|
1230
|
+
// "state": "filled",
|
|
1231
|
+
// "canceled-at": 0 } ] }
|
|
1232
|
+
//
|
|
1233
|
+
return this.parseOrders(response['data'], market, since, limit);
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* @method
|
|
1237
|
+
* @name bittrade#fetchOrder
|
|
1238
|
+
* @description fetches information on an order made by the user
|
|
1239
|
+
* @param {string} id order id
|
|
1240
|
+
* @param {string} symbol unified symbol of the market the order was made in
|
|
1241
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1242
|
+
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1243
|
+
*/
|
|
1244
|
+
async fetchOrder(id, symbol = undefined, params = {}) {
|
|
1245
|
+
await this.loadMarkets();
|
|
1246
|
+
const request = {
|
|
1247
|
+
'id': id,
|
|
1248
|
+
};
|
|
1249
|
+
const response = await this.privateGetOrderOrdersId(this.extend(request, params));
|
|
1250
|
+
const order = this.safeDict(response, 'data');
|
|
1251
|
+
return this.parseOrder(order);
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* @method
|
|
1255
|
+
* @name bittrade#fetchOrders
|
|
1256
|
+
* @description fetches information on multiple orders made by the user
|
|
1257
|
+
* @param {string} symbol unified market symbol of the market orders were made in
|
|
1258
|
+
* @param {int} [since] the earliest time in ms to fetch orders for
|
|
1259
|
+
* @param {int} [limit] the maximum number of order structures to retrieve
|
|
1260
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1261
|
+
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1262
|
+
*/
|
|
1263
|
+
async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1264
|
+
return await this.fetchOrdersByStates('pre-submitted,submitted,partial-filled,filled,partial-canceled,canceled', symbol, since, limit, params);
|
|
1265
|
+
}
|
|
1266
|
+
/**
|
|
1267
|
+
* @method
|
|
1268
|
+
* @name bittrade#fetchOpenOrders
|
|
1269
|
+
* @description fetch all unfilled currently open orders
|
|
1270
|
+
* @param {string} symbol unified market symbol
|
|
1271
|
+
* @param {int} [since] the earliest time in ms to fetch open orders for
|
|
1272
|
+
* @param {int} [limit] the maximum number of open orders structures to retrieve
|
|
1273
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1274
|
+
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1275
|
+
*/
|
|
1276
|
+
async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1277
|
+
const method = this.safeString(this.options, 'fetchOpenOrdersMethod', 'fetch_open_orders_v1');
|
|
1278
|
+
return await this[method](symbol, since, limit, params);
|
|
1279
|
+
}
|
|
1280
|
+
async fetchOpenOrdersV1(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1281
|
+
if (symbol === undefined) {
|
|
1282
|
+
throw new errors.ArgumentsRequired(this.id + ' fetchOpenOrdersV1() requires a symbol argument');
|
|
1283
|
+
}
|
|
1284
|
+
return await this.fetchOrdersByStates('pre-submitted,submitted,partial-filled', symbol, since, limit, params);
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* @method
|
|
1288
|
+
* @name bittrade#fetchClosedOrders
|
|
1289
|
+
* @description fetches information on multiple closed orders made by the user
|
|
1290
|
+
* @param {string} symbol unified market symbol of the market orders were made in
|
|
1291
|
+
* @param {int} [since] the earliest time in ms to fetch orders for
|
|
1292
|
+
* @param {int} [limit] the maximum number of order structures to retrieve
|
|
1293
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1294
|
+
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1295
|
+
*/
|
|
1296
|
+
async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1297
|
+
return await this.fetchOrdersByStates('filled,partial-canceled,canceled', symbol, since, limit, params);
|
|
1298
|
+
}
|
|
1299
|
+
async fetchOpenOrdersV2(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1300
|
+
await this.loadMarkets();
|
|
1301
|
+
const request = {};
|
|
1302
|
+
let market = undefined;
|
|
1303
|
+
if (symbol !== undefined) {
|
|
1304
|
+
market = this.market(symbol);
|
|
1305
|
+
request['symbol'] = market['id'];
|
|
1306
|
+
}
|
|
1307
|
+
let accountId = this.safeString(params, 'account-id');
|
|
1308
|
+
if (accountId === undefined) {
|
|
1309
|
+
// pick the first account
|
|
1310
|
+
await this.loadAccounts();
|
|
1311
|
+
for (let i = 0; i < this.accounts.length; i++) {
|
|
1312
|
+
const account = this.accounts[i];
|
|
1313
|
+
if (account['type'] === 'spot') {
|
|
1314
|
+
accountId = this.safeString(account, 'id');
|
|
1315
|
+
if (accountId !== undefined) {
|
|
1316
|
+
break;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
request['account-id'] = accountId;
|
|
1322
|
+
if (limit !== undefined) {
|
|
1323
|
+
request['size'] = limit;
|
|
1324
|
+
}
|
|
1325
|
+
const omitted = this.omit(params, 'account-id');
|
|
1326
|
+
const response = await this.privateGetOrderOpenOrders(this.extend(request, omitted));
|
|
1327
|
+
//
|
|
1328
|
+
// {
|
|
1329
|
+
// "status":"ok",
|
|
1330
|
+
// "data":[
|
|
1331
|
+
// {
|
|
1332
|
+
// "symbol":"ethusdt",
|
|
1333
|
+
// "source":"api",
|
|
1334
|
+
// "amount":"0.010000000000000000",
|
|
1335
|
+
// "account-id":1528640,
|
|
1336
|
+
// "created-at":1561597491963,
|
|
1337
|
+
// "price":"400.000000000000000000",
|
|
1338
|
+
// "filled-amount":"0.0",
|
|
1339
|
+
// "filled-cash-amount":"0.0",
|
|
1340
|
+
// "filled-fees":"0.0",
|
|
1341
|
+
// "id":38477101630,
|
|
1342
|
+
// "state":"submitted",
|
|
1343
|
+
// "type":"sell-limit"
|
|
1344
|
+
// }
|
|
1345
|
+
// ]
|
|
1346
|
+
// }
|
|
1347
|
+
//
|
|
1348
|
+
const data = this.safeList(response, 'data', []);
|
|
1349
|
+
return this.parseOrders(data, market, since, limit);
|
|
1350
|
+
}
|
|
1351
|
+
parseOrderStatus(status) {
|
|
1352
|
+
const statuses = {
|
|
1353
|
+
'partial-filled': 'open',
|
|
1354
|
+
'partial-canceled': 'canceled',
|
|
1355
|
+
'filled': 'closed',
|
|
1356
|
+
'canceled': 'canceled',
|
|
1357
|
+
'submitted': 'open',
|
|
1358
|
+
};
|
|
1359
|
+
return this.safeString(statuses, status, status);
|
|
1360
|
+
}
|
|
1361
|
+
parseOrder(order, market = undefined) {
|
|
1362
|
+
//
|
|
1363
|
+
// { id: 13997833014,
|
|
1364
|
+
// "symbol": "ethbtc",
|
|
1365
|
+
// "account-id": 3398321,
|
|
1366
|
+
// "amount": "0.045000000000000000",
|
|
1367
|
+
// "price": "0.034014000000000000",
|
|
1368
|
+
// "created-at": 1545836976871,
|
|
1369
|
+
// "type": "sell-limit",
|
|
1370
|
+
// "field-amount": "0.045000000000000000", // they have fixed it for filled-amount
|
|
1371
|
+
// "field-cash-amount": "0.001530630000000000", // they have fixed it for filled-cash-amount
|
|
1372
|
+
// "field-fees": "0.000003061260000000", // they have fixed it for filled-fees
|
|
1373
|
+
// "finished-at": 1545837948214,
|
|
1374
|
+
// "source": "spot-api",
|
|
1375
|
+
// "state": "filled",
|
|
1376
|
+
// "canceled-at": 0 }
|
|
1377
|
+
//
|
|
1378
|
+
// { id: 20395337822,
|
|
1379
|
+
// "symbol": "ethbtc",
|
|
1380
|
+
// "account-id": 5685075,
|
|
1381
|
+
// "amount": "0.001000000000000000",
|
|
1382
|
+
// "price": "0.0",
|
|
1383
|
+
// "created-at": 1545831584023,
|
|
1384
|
+
// "type": "buy-market",
|
|
1385
|
+
// "field-amount": "0.029100000000000000", // they have fixed it for filled-amount
|
|
1386
|
+
// "field-cash-amount": "0.000999788700000000", // they have fixed it for filled-cash-amount
|
|
1387
|
+
// "field-fees": "0.000058200000000000", // they have fixed it for filled-fees
|
|
1388
|
+
// "finished-at": 1545831584181,
|
|
1389
|
+
// "source": "spot-api",
|
|
1390
|
+
// "state": "filled",
|
|
1391
|
+
// "canceled-at": 0 }
|
|
1392
|
+
//
|
|
1393
|
+
const id = this.safeString(order, 'id');
|
|
1394
|
+
let side = undefined;
|
|
1395
|
+
let type = undefined;
|
|
1396
|
+
let status = undefined;
|
|
1397
|
+
if ('type' in order) {
|
|
1398
|
+
const orderType = order['type'].split('-');
|
|
1399
|
+
side = orderType[0];
|
|
1400
|
+
type = orderType[1];
|
|
1401
|
+
status = this.parseOrderStatus(this.safeString(order, 'state'));
|
|
1402
|
+
}
|
|
1403
|
+
const marketId = this.safeString(order, 'symbol');
|
|
1404
|
+
market = this.safeMarket(marketId, market);
|
|
1405
|
+
const timestamp = this.safeInteger(order, 'created-at');
|
|
1406
|
+
const clientOrderId = this.safeString(order, 'client-order-id');
|
|
1407
|
+
const amount = this.safeString(order, 'amount');
|
|
1408
|
+
const filled = this.safeString2(order, 'filled-amount', 'field-amount'); // typo in their API, filled amount
|
|
1409
|
+
const price = this.safeString(order, 'price');
|
|
1410
|
+
const cost = this.safeString2(order, 'filled-cash-amount', 'field-cash-amount'); // same typo
|
|
1411
|
+
const feeCost = this.safeString2(order, 'filled-fees', 'field-fees'); // typo in their API, filled fees
|
|
1412
|
+
let fee = undefined;
|
|
1413
|
+
if (feeCost !== undefined) {
|
|
1414
|
+
const feeCurrency = (side === 'sell') ? market['quote'] : market['base'];
|
|
1415
|
+
fee = {
|
|
1416
|
+
'cost': feeCost,
|
|
1417
|
+
'currency': feeCurrency,
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
return this.safeOrder({
|
|
1421
|
+
'info': order,
|
|
1422
|
+
'id': id,
|
|
1423
|
+
'clientOrderId': clientOrderId,
|
|
1424
|
+
'timestamp': timestamp,
|
|
1425
|
+
'datetime': this.iso8601(timestamp),
|
|
1426
|
+
'lastTradeTimestamp': undefined,
|
|
1427
|
+
'symbol': market['symbol'],
|
|
1428
|
+
'type': type,
|
|
1429
|
+
'timeInForce': undefined,
|
|
1430
|
+
'postOnly': undefined,
|
|
1431
|
+
'side': side,
|
|
1432
|
+
'price': price,
|
|
1433
|
+
'triggerPrice': undefined,
|
|
1434
|
+
'average': undefined,
|
|
1435
|
+
'cost': cost,
|
|
1436
|
+
'amount': amount,
|
|
1437
|
+
'filled': filled,
|
|
1438
|
+
'remaining': undefined,
|
|
1439
|
+
'status': status,
|
|
1440
|
+
'fee': fee,
|
|
1441
|
+
'trades': undefined,
|
|
1442
|
+
}, market);
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* @method
|
|
1446
|
+
* @name bittrade#createMarketBuyOrderWithCost
|
|
1447
|
+
* @description create a market buy order by providing the symbol and cost
|
|
1448
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
1449
|
+
* @param {float} cost how much you want to trade in units of the quote currency
|
|
1450
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1451
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1452
|
+
*/
|
|
1453
|
+
async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
|
|
1454
|
+
await this.loadMarkets();
|
|
1455
|
+
const market = this.market(symbol);
|
|
1456
|
+
if (!market['spot']) {
|
|
1457
|
+
throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
|
|
1458
|
+
}
|
|
1459
|
+
params['createMarketBuyOrderRequiresPrice'] = false;
|
|
1460
|
+
return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* @method
|
|
1464
|
+
* @name bittrade#createOrder
|
|
1465
|
+
* @description create a trade order
|
|
1466
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
1467
|
+
* @param {string} type 'market' or 'limit'
|
|
1468
|
+
* @param {string} side 'buy' or 'sell'
|
|
1469
|
+
* @param {float} amount how much of currency you want to trade in units of base currency
|
|
1470
|
+
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
|
1471
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1472
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1473
|
+
*/
|
|
1474
|
+
async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
|
|
1475
|
+
await this.loadMarkets();
|
|
1476
|
+
await this.loadAccounts();
|
|
1477
|
+
const market = this.market(symbol);
|
|
1478
|
+
const request = {
|
|
1479
|
+
'account-id': this.accounts[0]['id'],
|
|
1480
|
+
'symbol': market['id'],
|
|
1481
|
+
'type': side + '-' + type,
|
|
1482
|
+
};
|
|
1483
|
+
const clientOrderId = this.safeString2(params, 'clientOrderId', 'client-order-id'); // must be 64 chars max and unique within 24 hours
|
|
1484
|
+
if (clientOrderId === undefined) {
|
|
1485
|
+
const broker = this.safeValue(this.options, 'broker', {});
|
|
1486
|
+
const brokerId = this.safeString(broker, 'id');
|
|
1487
|
+
request['client-order-id'] = brokerId + this.uuid();
|
|
1488
|
+
}
|
|
1489
|
+
else {
|
|
1490
|
+
request['client-order-id'] = clientOrderId;
|
|
1491
|
+
}
|
|
1492
|
+
params = this.omit(params, ['clientOrderId', 'client-order-id']);
|
|
1493
|
+
if ((type === 'market') && (side === 'buy')) {
|
|
1494
|
+
let quoteAmount = undefined;
|
|
1495
|
+
let createMarketBuyOrderRequiresPrice = true;
|
|
1496
|
+
[createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
|
|
1497
|
+
const cost = this.safeNumber(params, 'cost');
|
|
1498
|
+
params = this.omit(params, 'cost');
|
|
1499
|
+
if (cost !== undefined) {
|
|
1500
|
+
quoteAmount = this.amountToPrecision(symbol, cost);
|
|
1501
|
+
}
|
|
1502
|
+
else if (createMarketBuyOrderRequiresPrice) {
|
|
1503
|
+
if (price === undefined) {
|
|
1504
|
+
throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument');
|
|
1505
|
+
}
|
|
1506
|
+
else {
|
|
1507
|
+
// despite that cost = amount * price is in quote currency and should have quote precision
|
|
1508
|
+
// the exchange API requires the cost supplied in 'amount' to be of base precision
|
|
1509
|
+
// more about it here:
|
|
1510
|
+
// https://github.com/ccxt/ccxt/pull/4395
|
|
1511
|
+
// https://github.com/ccxt/ccxt/issues/7611
|
|
1512
|
+
// we use amountToPrecision here because the exchange requires cost in base precision
|
|
1513
|
+
const amountString = this.numberToString(amount);
|
|
1514
|
+
const priceString = this.numberToString(price);
|
|
1515
|
+
quoteAmount = this.amountToPrecision(symbol, Precise["default"].stringMul(amountString, priceString));
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
else {
|
|
1519
|
+
quoteAmount = this.amountToPrecision(symbol, amount);
|
|
1520
|
+
}
|
|
1521
|
+
request['amount'] = quoteAmount;
|
|
1522
|
+
}
|
|
1523
|
+
else {
|
|
1524
|
+
request['amount'] = this.amountToPrecision(symbol, amount);
|
|
1525
|
+
}
|
|
1526
|
+
if (type === 'limit' || type === 'ioc' || type === 'limit-maker' || type === 'stop-limit' || type === 'stop-limit-fok') {
|
|
1527
|
+
request['price'] = this.priceToPrecision(symbol, price);
|
|
1528
|
+
}
|
|
1529
|
+
const method = this.options['createOrderMethod'];
|
|
1530
|
+
const response = await this[method](this.extend(request, params));
|
|
1531
|
+
const id = this.safeString(response, 'data');
|
|
1532
|
+
return this.safeOrder({
|
|
1533
|
+
'info': response,
|
|
1534
|
+
'id': id,
|
|
1535
|
+
'timestamp': undefined,
|
|
1536
|
+
'datetime': undefined,
|
|
1537
|
+
'lastTradeTimestamp': undefined,
|
|
1538
|
+
'status': undefined,
|
|
1539
|
+
'symbol': symbol,
|
|
1540
|
+
'type': type,
|
|
1541
|
+
'side': side,
|
|
1542
|
+
'price': price,
|
|
1543
|
+
'amount': amount,
|
|
1544
|
+
'filled': undefined,
|
|
1545
|
+
'remaining': undefined,
|
|
1546
|
+
'cost': undefined,
|
|
1547
|
+
'trades': undefined,
|
|
1548
|
+
'fee': undefined,
|
|
1549
|
+
'clientOrderId': undefined,
|
|
1550
|
+
'average': undefined,
|
|
1551
|
+
}, market);
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* @method
|
|
1555
|
+
* @name bittrade#cancelOrder
|
|
1556
|
+
* @description cancels an open order
|
|
1557
|
+
* @param {string} id order id
|
|
1558
|
+
* @param {string} symbol not used by bittrade cancelOrder ()
|
|
1559
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1560
|
+
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1561
|
+
*/
|
|
1562
|
+
async cancelOrder(id, symbol = undefined, params = {}) {
|
|
1563
|
+
const response = await this.privatePostOrderOrdersIdSubmitcancel({ 'id': id });
|
|
1564
|
+
//
|
|
1565
|
+
// {
|
|
1566
|
+
// "status": "ok",
|
|
1567
|
+
// "data": "10138899000",
|
|
1568
|
+
// }
|
|
1569
|
+
//
|
|
1570
|
+
return this.extend(this.parseOrder(response), {
|
|
1571
|
+
'id': id,
|
|
1572
|
+
'status': 'canceled',
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
/**
|
|
1576
|
+
* @method
|
|
1577
|
+
* @name bittrade#cancelOrders
|
|
1578
|
+
* @description cancel multiple orders
|
|
1579
|
+
* @param {string[]} ids order ids
|
|
1580
|
+
* @param {string} symbol not used by bittrade cancelOrders ()
|
|
1581
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1582
|
+
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1583
|
+
*/
|
|
1584
|
+
async cancelOrders(ids, symbol = undefined, params = {}) {
|
|
1585
|
+
await this.loadMarkets();
|
|
1586
|
+
const clientOrderIds = this.safeValue2(params, 'clientOrderIds', 'client-order-ids');
|
|
1587
|
+
params = this.omit(params, ['clientOrderIds', 'client-order-ids']);
|
|
1588
|
+
const request = {};
|
|
1589
|
+
if (clientOrderIds === undefined) {
|
|
1590
|
+
request['order-ids'] = ids;
|
|
1591
|
+
}
|
|
1592
|
+
else {
|
|
1593
|
+
request['client-order-ids'] = clientOrderIds;
|
|
1594
|
+
}
|
|
1595
|
+
const response = await this.privatePostOrderOrdersBatchcancel(this.extend(request, params));
|
|
1596
|
+
//
|
|
1597
|
+
// {
|
|
1598
|
+
// "status": "ok",
|
|
1599
|
+
// "data": {
|
|
1600
|
+
// "success": [
|
|
1601
|
+
// "5983466"
|
|
1602
|
+
// ],
|
|
1603
|
+
// "failed": [
|
|
1604
|
+
// {
|
|
1605
|
+
// "err-msg": "Incorrect order state",
|
|
1606
|
+
// "order-state": 7,
|
|
1607
|
+
// "order-id": "",
|
|
1608
|
+
// "err-code": "order-orderstate-error",
|
|
1609
|
+
// "client-order-id": "first"
|
|
1610
|
+
// },
|
|
1611
|
+
// {
|
|
1612
|
+
// "err-msg": "Incorrect order state",
|
|
1613
|
+
// "order-state": 7,
|
|
1614
|
+
// "order-id": "",
|
|
1615
|
+
// "err-code": "order-orderstate-error",
|
|
1616
|
+
// "client-order-id": "second"
|
|
1617
|
+
// },
|
|
1618
|
+
// {
|
|
1619
|
+
// "err-msg": "The record is not found.",
|
|
1620
|
+
// "order-id": "",
|
|
1621
|
+
// "err-code": "base-not-found",
|
|
1622
|
+
// "client-order-id": "third"
|
|
1623
|
+
// }
|
|
1624
|
+
// ]
|
|
1625
|
+
// }
|
|
1626
|
+
// }
|
|
1627
|
+
//
|
|
1628
|
+
return this.parseCancelOrders(response);
|
|
1629
|
+
}
|
|
1630
|
+
parseCancelOrders(orders) {
|
|
1631
|
+
//
|
|
1632
|
+
// {
|
|
1633
|
+
// "success": [
|
|
1634
|
+
// "5983466"
|
|
1635
|
+
// ],
|
|
1636
|
+
// "failed": [
|
|
1637
|
+
// {
|
|
1638
|
+
// "err-msg": "Incorrect order state",
|
|
1639
|
+
// "order-state": 7,
|
|
1640
|
+
// "order-id": "",
|
|
1641
|
+
// "err-code": "order-orderstate-error",
|
|
1642
|
+
// "client-order-id": "first"
|
|
1643
|
+
// },
|
|
1644
|
+
// ...
|
|
1645
|
+
// ]
|
|
1646
|
+
// }
|
|
1647
|
+
//
|
|
1648
|
+
// {
|
|
1649
|
+
// "errors": [
|
|
1650
|
+
// {
|
|
1651
|
+
// "order_id": "769206471845261312",
|
|
1652
|
+
// "err_code": 1061,
|
|
1653
|
+
// "err_msg": "This order doesnt exist."
|
|
1654
|
+
// }
|
|
1655
|
+
// ],
|
|
1656
|
+
// "successes": "1258075374411399168,1258075393254871040"
|
|
1657
|
+
// }
|
|
1658
|
+
//
|
|
1659
|
+
const successes = this.safeString(orders, 'successes');
|
|
1660
|
+
let success = undefined;
|
|
1661
|
+
if (successes !== undefined) {
|
|
1662
|
+
success = successes.split(',');
|
|
1663
|
+
}
|
|
1664
|
+
else {
|
|
1665
|
+
success = this.safeList(orders, 'success', []);
|
|
1666
|
+
}
|
|
1667
|
+
const failed = this.safeList2(orders, 'errors', 'failed', []);
|
|
1668
|
+
const result = [];
|
|
1669
|
+
for (let i = 0; i < success.length; i++) {
|
|
1670
|
+
const order = success[i];
|
|
1671
|
+
result.push(this.safeOrder({
|
|
1672
|
+
'info': order,
|
|
1673
|
+
'id': order,
|
|
1674
|
+
'status': 'canceled',
|
|
1675
|
+
}));
|
|
1676
|
+
}
|
|
1677
|
+
for (let i = 0; i < failed.length; i++) {
|
|
1678
|
+
const order = failed[i];
|
|
1679
|
+
result.push(this.safeOrder({
|
|
1680
|
+
'info': order,
|
|
1681
|
+
'id': this.safeString2(order, 'order-id', 'order_id'),
|
|
1682
|
+
'status': 'failed',
|
|
1683
|
+
'clientOrderId': this.safeString(order, 'client-order-id'),
|
|
1684
|
+
}));
|
|
1685
|
+
}
|
|
1686
|
+
return result;
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* @method
|
|
1690
|
+
* @name bittrade#cancelAllOrders
|
|
1691
|
+
* @description cancel all open orders
|
|
1692
|
+
* @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
|
|
1693
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1694
|
+
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1695
|
+
*/
|
|
1696
|
+
async cancelAllOrders(symbol = undefined, params = {}) {
|
|
1697
|
+
await this.loadMarkets();
|
|
1698
|
+
const request = {
|
|
1699
|
+
// 'account-id' string false NA The account id used for this cancel Refer to GET /v1/account/accounts
|
|
1700
|
+
// 'symbol': market['id'], // a list of comma-separated symbols, all symbols by default
|
|
1701
|
+
// 'types' 'string', buy-market, sell-market, buy-limit, sell-limit, buy-ioc, sell-ioc, buy-stop-limit, sell-stop-limit, buy-limit-fok, sell-limit-fok, buy-stop-limit-fok, sell-stop-limit-fok
|
|
1702
|
+
// 'side': 'buy', // or 'sell'
|
|
1703
|
+
// 'size': 100, // the number of orders to cancel 1-100
|
|
1704
|
+
};
|
|
1705
|
+
let market = undefined;
|
|
1706
|
+
if (symbol !== undefined) {
|
|
1707
|
+
market = this.market(symbol);
|
|
1708
|
+
request['symbol'] = market['id'];
|
|
1709
|
+
}
|
|
1710
|
+
const response = await this.privatePostOrderOrdersBatchCancelOpenOrders(this.extend(request, params));
|
|
1711
|
+
//
|
|
1712
|
+
// {
|
|
1713
|
+
// "code": 200,
|
|
1714
|
+
// "data": {
|
|
1715
|
+
// "success-count": 2,
|
|
1716
|
+
// "failed-count": 0,
|
|
1717
|
+
// "next-id": 5454600
|
|
1718
|
+
// }
|
|
1719
|
+
// }
|
|
1720
|
+
//
|
|
1721
|
+
const data = this.safeDict(response, 'data', {});
|
|
1722
|
+
return [
|
|
1723
|
+
this.safeOrder({
|
|
1724
|
+
'info': data,
|
|
1725
|
+
}),
|
|
1726
|
+
];
|
|
1727
|
+
}
|
|
1728
|
+
parseDepositAddress(depositAddress, currency = undefined) {
|
|
1729
|
+
//
|
|
1730
|
+
// {
|
|
1731
|
+
// "currency": "usdt",
|
|
1732
|
+
// "address": "0xf7292eb9ba7bc50358e27f0e025a4d225a64127b",
|
|
1733
|
+
// "addressTag": "",
|
|
1734
|
+
// "chain": "usdterc20", // trc20usdt, hrc20usdt, usdt, algousdt
|
|
1735
|
+
// }
|
|
1736
|
+
//
|
|
1737
|
+
const address = this.safeString(depositAddress, 'address');
|
|
1738
|
+
const tag = this.safeString(depositAddress, 'addressTag');
|
|
1739
|
+
const currencyId = this.safeString(depositAddress, 'currency');
|
|
1740
|
+
currency = this.safeCurrency(currencyId, currency);
|
|
1741
|
+
const code = this.safeCurrencyCode(currencyId, currency);
|
|
1742
|
+
const networkId = this.safeString(depositAddress, 'chain');
|
|
1743
|
+
const networks = this.safeValue(currency, 'networks', {});
|
|
1744
|
+
const networksById = this.indexBy(networks, 'id');
|
|
1745
|
+
const networkValue = this.safeValue(networksById, networkId, networkId);
|
|
1746
|
+
const network = this.safeString(networkValue, 'network');
|
|
1747
|
+
this.checkAddress(address);
|
|
1748
|
+
return {
|
|
1749
|
+
'currency': code,
|
|
1750
|
+
'address': address,
|
|
1751
|
+
'tag': tag,
|
|
1752
|
+
'network': network,
|
|
1753
|
+
'info': depositAddress,
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
/**
|
|
1757
|
+
* @method
|
|
1758
|
+
* @name bittrade#fetchDeposits
|
|
1759
|
+
* @description fetch all deposits made to an account
|
|
1760
|
+
* @param {string} code unified currency code
|
|
1761
|
+
* @param {int} [since] the earliest time in ms to fetch deposits for
|
|
1762
|
+
* @param {int} [limit] the maximum number of deposits structures to retrieve
|
|
1763
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1764
|
+
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
1765
|
+
*/
|
|
1766
|
+
async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1767
|
+
if (limit === undefined || limit > 100) {
|
|
1768
|
+
limit = 100;
|
|
1769
|
+
}
|
|
1770
|
+
await this.loadMarkets();
|
|
1771
|
+
let currency = undefined;
|
|
1772
|
+
if (code !== undefined) {
|
|
1773
|
+
currency = this.currency(code);
|
|
1774
|
+
}
|
|
1775
|
+
const request = {
|
|
1776
|
+
'type': 'deposit',
|
|
1777
|
+
'from': 0, // From 'id' ... if you want to get results after a particular transaction id, pass the id in params.from
|
|
1778
|
+
};
|
|
1779
|
+
if (currency !== undefined) {
|
|
1780
|
+
request['currency'] = currency['id'];
|
|
1781
|
+
}
|
|
1782
|
+
if (limit !== undefined) {
|
|
1783
|
+
request['size'] = limit; // max 100
|
|
1784
|
+
}
|
|
1785
|
+
const response = await this.privateGetQueryDepositWithdraw(this.extend(request, params));
|
|
1786
|
+
// return response
|
|
1787
|
+
return this.parseTransactions(response['data'], currency, since, limit);
|
|
1788
|
+
}
|
|
1789
|
+
/**
|
|
1790
|
+
* @method
|
|
1791
|
+
* @name bittrade#fetchWithdrawals
|
|
1792
|
+
* @description fetch all withdrawals made from an account
|
|
1793
|
+
* @param {string} code unified currency code
|
|
1794
|
+
* @param {int} [since] the earliest time in ms to fetch withdrawals for
|
|
1795
|
+
* @param {int} [limit] the maximum number of withdrawals structures to retrieve
|
|
1796
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1797
|
+
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
1798
|
+
*/
|
|
1799
|
+
async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1800
|
+
if (limit === undefined || limit > 100) {
|
|
1801
|
+
limit = 100;
|
|
1802
|
+
}
|
|
1803
|
+
await this.loadMarkets();
|
|
1804
|
+
let currency = undefined;
|
|
1805
|
+
if (code !== undefined) {
|
|
1806
|
+
currency = this.currency(code);
|
|
1807
|
+
}
|
|
1808
|
+
const request = {
|
|
1809
|
+
'type': 'withdraw',
|
|
1810
|
+
'from': 0, // From 'id' ... if you want to get results after a particular transaction id, pass the id in params.from
|
|
1811
|
+
};
|
|
1812
|
+
if (currency !== undefined) {
|
|
1813
|
+
request['currency'] = currency['id'];
|
|
1814
|
+
}
|
|
1815
|
+
if (limit !== undefined) {
|
|
1816
|
+
request['size'] = limit; // max 100
|
|
1817
|
+
}
|
|
1818
|
+
const response = await this.privateGetQueryDepositWithdraw(this.extend(request, params));
|
|
1819
|
+
// return response
|
|
1820
|
+
return this.parseTransactions(response['data'], currency, since, limit);
|
|
1821
|
+
}
|
|
1822
|
+
parseTransaction(transaction, currency = undefined) {
|
|
1823
|
+
//
|
|
1824
|
+
// fetchDeposits
|
|
1825
|
+
//
|
|
1826
|
+
// {
|
|
1827
|
+
// "id": 8211029,
|
|
1828
|
+
// "type": "deposit",
|
|
1829
|
+
// "currency": "eth",
|
|
1830
|
+
// "chain": "eth",
|
|
1831
|
+
// 'tx-hash': "bd315....",
|
|
1832
|
+
// "amount": 0.81162421,
|
|
1833
|
+
// "address": "4b8b....",
|
|
1834
|
+
// 'address-tag": '",
|
|
1835
|
+
// "fee": 0,
|
|
1836
|
+
// "state": "safe",
|
|
1837
|
+
// "created-at": 1542180380965,
|
|
1838
|
+
// "updated-at": 1542180788077
|
|
1839
|
+
// }
|
|
1840
|
+
//
|
|
1841
|
+
// fetchWithdrawals
|
|
1842
|
+
//
|
|
1843
|
+
// {
|
|
1844
|
+
// "id": 6908275,
|
|
1845
|
+
// "type": "withdraw",
|
|
1846
|
+
// "currency": "btc",
|
|
1847
|
+
// "chain": "btc",
|
|
1848
|
+
// 'tx-hash': "c1a1a....",
|
|
1849
|
+
// "amount": 0.80257005,
|
|
1850
|
+
// "address": "1QR....",
|
|
1851
|
+
// 'address-tag": '",
|
|
1852
|
+
// "fee": 0.0005,
|
|
1853
|
+
// "state": "confirmed",
|
|
1854
|
+
// "created-at": 1552107295685,
|
|
1855
|
+
// "updated-at": 1552108032859
|
|
1856
|
+
// }
|
|
1857
|
+
//
|
|
1858
|
+
// withdraw
|
|
1859
|
+
//
|
|
1860
|
+
// {
|
|
1861
|
+
// "status": "ok",
|
|
1862
|
+
// "data": "99562054"
|
|
1863
|
+
// }
|
|
1864
|
+
//
|
|
1865
|
+
const timestamp = this.safeInteger(transaction, 'created-at');
|
|
1866
|
+
const code = this.safeCurrencyCode(this.safeString(transaction, 'currency'));
|
|
1867
|
+
let type = this.safeString(transaction, 'type');
|
|
1868
|
+
if (type === 'withdraw') {
|
|
1869
|
+
type = 'withdrawal';
|
|
1870
|
+
}
|
|
1871
|
+
let feeCost = this.safeString(transaction, 'fee');
|
|
1872
|
+
if (feeCost !== undefined) {
|
|
1873
|
+
feeCost = Precise["default"].stringAbs(feeCost);
|
|
1874
|
+
}
|
|
1875
|
+
return {
|
|
1876
|
+
'info': transaction,
|
|
1877
|
+
'id': this.safeString2(transaction, 'id', 'data'),
|
|
1878
|
+
'txid': this.safeString(transaction, 'tx-hash'),
|
|
1879
|
+
'timestamp': timestamp,
|
|
1880
|
+
'datetime': this.iso8601(timestamp),
|
|
1881
|
+
'network': this.safeStringUpper(transaction, 'chain'),
|
|
1882
|
+
'address': this.safeString(transaction, 'address'),
|
|
1883
|
+
'addressTo': undefined,
|
|
1884
|
+
'addressFrom': undefined,
|
|
1885
|
+
'tag': this.safeString(transaction, 'address-tag'),
|
|
1886
|
+
'tagTo': undefined,
|
|
1887
|
+
'tagFrom': undefined,
|
|
1888
|
+
'type': type,
|
|
1889
|
+
'amount': this.safeNumber(transaction, 'amount'),
|
|
1890
|
+
'currency': code,
|
|
1891
|
+
'status': this.parseTransactionStatus(this.safeString(transaction, 'state')),
|
|
1892
|
+
'updated': this.safeInteger(transaction, 'updated-at'),
|
|
1893
|
+
'comment': undefined,
|
|
1894
|
+
'internal': undefined,
|
|
1895
|
+
'fee': {
|
|
1896
|
+
'currency': code,
|
|
1897
|
+
'cost': this.parseNumber(feeCost),
|
|
1898
|
+
'rate': undefined,
|
|
1899
|
+
},
|
|
1900
|
+
};
|
|
1901
|
+
}
|
|
1902
|
+
parseTransactionStatus(status) {
|
|
1903
|
+
const statuses = {
|
|
1904
|
+
// deposit statuses
|
|
1905
|
+
'unknown': 'failed',
|
|
1906
|
+
'confirming': 'pending',
|
|
1907
|
+
'confirmed': 'ok',
|
|
1908
|
+
'safe': 'ok',
|
|
1909
|
+
'orphan': 'failed',
|
|
1910
|
+
// withdrawal statuses
|
|
1911
|
+
'submitted': 'pending',
|
|
1912
|
+
'canceled': 'canceled',
|
|
1913
|
+
'reexamine': 'pending',
|
|
1914
|
+
'reject': 'failed',
|
|
1915
|
+
'pass': 'pending',
|
|
1916
|
+
'wallet-reject': 'failed',
|
|
1917
|
+
// 'confirmed': 'ok', // present in deposit statuses
|
|
1918
|
+
'confirm-error': 'failed',
|
|
1919
|
+
'repealed': 'failed',
|
|
1920
|
+
'wallet-transfer': 'pending',
|
|
1921
|
+
'pre-transfer': 'pending',
|
|
1922
|
+
};
|
|
1923
|
+
return this.safeString(statuses, status, status);
|
|
1924
|
+
}
|
|
1925
|
+
/**
|
|
1926
|
+
* @method
|
|
1927
|
+
* @name bittrade#withdraw
|
|
1928
|
+
* @description make a withdrawal
|
|
1929
|
+
* @param {string} code unified currency code
|
|
1930
|
+
* @param {float} amount the amount to withdraw
|
|
1931
|
+
* @param {string} address the address to withdraw to
|
|
1932
|
+
* @param {string} tag
|
|
1933
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1934
|
+
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
1935
|
+
*/
|
|
1936
|
+
async withdraw(code, amount, address, tag = undefined, params = {}) {
|
|
1937
|
+
[tag, params] = this.handleWithdrawTagAndParams(tag, params);
|
|
1938
|
+
await this.loadMarkets();
|
|
1939
|
+
this.checkAddress(address);
|
|
1940
|
+
const currency = this.currency(code);
|
|
1941
|
+
const request = {
|
|
1942
|
+
'address': address,
|
|
1943
|
+
'amount': amount,
|
|
1944
|
+
'currency': currency['id'].toLowerCase(),
|
|
1945
|
+
};
|
|
1946
|
+
if (tag !== undefined) {
|
|
1947
|
+
request['addr-tag'] = tag; // only for XRP?
|
|
1948
|
+
}
|
|
1949
|
+
const networks = this.safeValue(this.options, 'networks', {});
|
|
1950
|
+
let network = this.safeStringUpper(params, 'network'); // this line allows the user to specify either ERC20 or ETH
|
|
1951
|
+
network = this.safeStringLower(networks, network, network); // handle ETH>ERC20 alias
|
|
1952
|
+
if (network !== undefined) {
|
|
1953
|
+
// possible chains - usdterc20, trc20usdt, hrc20usdt, usdt, algousdt
|
|
1954
|
+
if (network === 'erc20') {
|
|
1955
|
+
request['chain'] = currency['id'] + network;
|
|
1956
|
+
}
|
|
1957
|
+
else {
|
|
1958
|
+
request['chain'] = network + currency['id'];
|
|
1959
|
+
}
|
|
1960
|
+
params = this.omit(params, 'network');
|
|
1961
|
+
}
|
|
1962
|
+
const response = await this.privatePostDwWithdrawApiCreate(this.extend(request, params));
|
|
1963
|
+
//
|
|
1964
|
+
// {
|
|
1965
|
+
// "status": "ok",
|
|
1966
|
+
// "data": "99562054"
|
|
1967
|
+
// }
|
|
1968
|
+
//
|
|
1969
|
+
return this.parseTransaction(response, currency);
|
|
1970
|
+
}
|
|
1971
|
+
sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
|
1972
|
+
let url = '/';
|
|
1973
|
+
if (api === 'market') {
|
|
1974
|
+
url += api;
|
|
1975
|
+
}
|
|
1976
|
+
else if ((api === 'public') || (api === 'private')) {
|
|
1977
|
+
url += this.version;
|
|
1978
|
+
}
|
|
1979
|
+
else if ((api === 'v2Public') || (api === 'v2Private')) {
|
|
1980
|
+
url += 'v2';
|
|
1981
|
+
}
|
|
1982
|
+
url += '/' + this.implodeParams(path, params);
|
|
1983
|
+
const query = this.omit(params, this.extractParams(path));
|
|
1984
|
+
if (api === 'private' || api === 'v2Private') {
|
|
1985
|
+
this.checkRequiredCredentials();
|
|
1986
|
+
const timestamp = this.ymdhms(this.milliseconds(), 'T');
|
|
1987
|
+
let request = {
|
|
1988
|
+
'SignatureMethod': 'HmacSHA256',
|
|
1989
|
+
'SignatureVersion': '2',
|
|
1990
|
+
'AccessKeyId': this.apiKey,
|
|
1991
|
+
'Timestamp': timestamp,
|
|
1992
|
+
};
|
|
1993
|
+
if (method !== 'POST') {
|
|
1994
|
+
request = this.extend(request, query);
|
|
1995
|
+
}
|
|
1996
|
+
const requestSorted = this.keysort(request);
|
|
1997
|
+
let auth = this.urlencode(requestSorted);
|
|
1998
|
+
// unfortunately, PHP demands double quotes for the escaped newline symbol
|
|
1999
|
+
// eslint-disable-next-line quotes
|
|
2000
|
+
const payload = [method, this.hostname, url, auth].join("\n");
|
|
2001
|
+
const signature = this.hmac(this.encode(payload), this.encode(this.secret), sha256.sha256, 'base64');
|
|
2002
|
+
auth += '&' + this.urlencode({ 'Signature': signature });
|
|
2003
|
+
url += '?' + auth;
|
|
2004
|
+
if (method === 'POST') {
|
|
2005
|
+
body = this.json(query);
|
|
2006
|
+
headers = {
|
|
2007
|
+
'Content-Type': 'application/json',
|
|
2008
|
+
};
|
|
2009
|
+
}
|
|
2010
|
+
else {
|
|
2011
|
+
headers = {
|
|
2012
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
else {
|
|
2017
|
+
if (Object.keys(params).length) {
|
|
2018
|
+
url += '?' + this.urlencode(params);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
url = this.implodeParams(this.urls['api'][api], {
|
|
2022
|
+
'hostname': this.hostname,
|
|
2023
|
+
}) + url;
|
|
2024
|
+
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
|
2025
|
+
}
|
|
2026
|
+
handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
|
2027
|
+
if (response === undefined) {
|
|
2028
|
+
return undefined; // fallback to default error handler
|
|
2029
|
+
}
|
|
2030
|
+
if ('status' in response) {
|
|
2031
|
+
//
|
|
2032
|
+
// {"status":"error","err-code":"order-limitorder-amount-min-error","err-msg":"limit order amount error, min: `0.001`","data":null}
|
|
2033
|
+
//
|
|
2034
|
+
const status = this.safeString(response, 'status');
|
|
2035
|
+
if (status === 'error') {
|
|
2036
|
+
const code = this.safeString(response, 'err-code');
|
|
2037
|
+
const feedback = this.id + ' ' + body;
|
|
2038
|
+
this.throwBroadlyMatchedException(this.exceptions['broad'], body, feedback);
|
|
2039
|
+
this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
|
|
2040
|
+
const message = this.safeString(response, 'err-msg');
|
|
2041
|
+
this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
|
|
2042
|
+
throw new errors.ExchangeError(feedback);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
return undefined;
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
module.exports = bittrade;
|