ccxt 4.4.94 → 4.4.96

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.
Files changed (125) hide show
  1. package/README.md +7 -7
  2. package/dist/ccxt.browser.min.js +7 -7
  3. package/dist/cjs/ccxt.js +4 -1
  4. package/dist/cjs/src/abstract/foxbit.js +9 -0
  5. package/dist/cjs/src/apex.js +2 -2
  6. package/dist/cjs/src/ascendex.js +3 -3
  7. package/dist/cjs/src/base/Exchange.js +8 -4
  8. package/dist/cjs/src/base/ws/Future.js +2 -2
  9. package/dist/cjs/src/bingx.js +148 -94
  10. package/dist/cjs/src/bitget.js +32 -144
  11. package/dist/cjs/src/bitmart.js +2 -2
  12. package/dist/cjs/src/bitrue.js +15 -8
  13. package/dist/cjs/src/bitstamp.js +1 -0
  14. package/dist/cjs/src/blofin.js +7 -1
  15. package/dist/cjs/src/bybit.js +17 -6
  16. package/dist/cjs/src/coinbase.js +36 -0
  17. package/dist/cjs/src/coinbaseexchange.js +4 -2
  18. package/dist/cjs/src/coinmate.js +34 -0
  19. package/dist/cjs/src/coinone.js +34 -0
  20. package/dist/cjs/src/coinsph.js +29 -0
  21. package/dist/cjs/src/coinspot.js +36 -1
  22. package/dist/cjs/src/cryptocom.js +2 -1
  23. package/dist/cjs/src/cryptomus.js +41 -1
  24. package/dist/cjs/src/defx.js +1 -1
  25. package/dist/cjs/src/derive.js +1 -1
  26. package/dist/cjs/src/ellipx.js +40 -0
  27. package/dist/cjs/src/foxbit.js +2016 -0
  28. package/dist/cjs/src/gate.js +1 -1
  29. package/dist/cjs/src/hyperliquid.js +3 -2
  30. package/dist/cjs/src/kucoin.js +1 -1
  31. package/dist/cjs/src/kucoinfutures.js +3 -2
  32. package/dist/cjs/src/mexc.js +28 -13
  33. package/dist/cjs/src/modetrade.js +3 -3
  34. package/dist/cjs/src/okcoin.js +1 -1
  35. package/dist/cjs/src/okx.js +12 -3
  36. package/dist/cjs/src/onetrading.js +1 -1
  37. package/dist/cjs/src/oxfun.js +2 -1
  38. package/dist/cjs/src/paradex.js +2 -2
  39. package/dist/cjs/src/pro/hyperliquid.js +6 -6
  40. package/dist/cjs/src/pro/kraken.js +18 -18
  41. package/dist/cjs/src/pro/mexc.js +10 -10
  42. package/dist/cjs/src/vertex.js +3 -2
  43. package/dist/cjs/src/woo.js +1281 -894
  44. package/dist/cjs/src/woofipro.js +2 -2
  45. package/js/ccxt.d.ts +5 -2
  46. package/js/ccxt.js +4 -2
  47. package/js/src/abstract/bingx.d.ts +3 -0
  48. package/js/src/abstract/foxbit.d.ts +29 -0
  49. package/js/src/abstract/foxbit.js +11 -0
  50. package/js/src/abstract/woo.d.ts +58 -3
  51. package/js/src/apex.d.ts +2 -2
  52. package/js/src/apex.js +2 -2
  53. package/js/src/ascendex.d.ts +1 -1
  54. package/js/src/ascendex.js +3 -3
  55. package/js/src/base/Exchange.d.ts +7 -6
  56. package/js/src/base/Exchange.js +8 -4
  57. package/js/src/base/ws/Future.js +2 -2
  58. package/js/src/bingx.d.ts +6 -6
  59. package/js/src/bingx.js +148 -94
  60. package/js/src/bitget.js +32 -144
  61. package/js/src/bitmart.d.ts +2 -2
  62. package/js/src/bitmart.js +2 -2
  63. package/js/src/bitrue.js +15 -8
  64. package/js/src/bitstamp.js +2 -1
  65. package/js/src/bittrade.d.ts +1 -1
  66. package/js/src/blofin.d.ts +2 -1
  67. package/js/src/blofin.js +7 -1
  68. package/js/src/bybit.d.ts +1 -1
  69. package/js/src/bybit.js +17 -6
  70. package/js/src/coinbase.js +36 -0
  71. package/js/src/coinbaseexchange.d.ts +2 -2
  72. package/js/src/coinbaseexchange.js +4 -2
  73. package/js/src/coinbaseinternational.d.ts +2 -2
  74. package/js/src/coinmate.js +34 -0
  75. package/js/src/coinone.js +34 -0
  76. package/js/src/coinsph.js +29 -0
  77. package/js/src/coinspot.d.ts +1 -1
  78. package/js/src/coinspot.js +36 -1
  79. package/js/src/cryptocom.d.ts +1 -1
  80. package/js/src/cryptocom.js +2 -1
  81. package/js/src/cryptomus.d.ts +1 -1
  82. package/js/src/cryptomus.js +41 -1
  83. package/js/src/defx.d.ts +2 -2
  84. package/js/src/defx.js +1 -1
  85. package/js/src/derive.d.ts +2 -2
  86. package/js/src/derive.js +1 -1
  87. package/js/src/digifinex.d.ts +1 -1
  88. package/js/src/ellipx.js +40 -0
  89. package/js/src/foxbit.d.ts +352 -0
  90. package/js/src/foxbit.js +2016 -0
  91. package/js/src/gate.js +1 -1
  92. package/js/src/htx.d.ts +2 -2
  93. package/js/src/hyperliquid.d.ts +2 -2
  94. package/js/src/hyperliquid.js +3 -2
  95. package/js/src/krakenfutures.d.ts +1 -1
  96. package/js/src/kucoin.d.ts +1 -1
  97. package/js/src/kucoin.js +1 -1
  98. package/js/src/kucoinfutures.d.ts +3 -3
  99. package/js/src/kucoinfutures.js +3 -2
  100. package/js/src/mexc.d.ts +1 -1
  101. package/js/src/mexc.js +28 -13
  102. package/js/src/modetrade.d.ts +2 -4
  103. package/js/src/modetrade.js +3 -3
  104. package/js/src/ndax.d.ts +1 -1
  105. package/js/src/okcoin.d.ts +1 -1
  106. package/js/src/okcoin.js +1 -1
  107. package/js/src/okx.d.ts +1 -1
  108. package/js/src/okx.js +12 -3
  109. package/js/src/onetrading.d.ts +1 -1
  110. package/js/src/onetrading.js +1 -1
  111. package/js/src/oxfun.d.ts +1 -1
  112. package/js/src/oxfun.js +2 -1
  113. package/js/src/paradex.d.ts +1 -1
  114. package/js/src/paradex.js +2 -2
  115. package/js/src/pro/hyperliquid.js +6 -6
  116. package/js/src/pro/kraken.js +18 -18
  117. package/js/src/pro/mexc.js +10 -10
  118. package/js/src/timex.d.ts +1 -1
  119. package/js/src/vertex.d.ts +2 -2
  120. package/js/src/vertex.js +3 -2
  121. package/js/src/woo.d.ts +80 -50
  122. package/js/src/woo.js +1281 -894
  123. package/js/src/woofipro.d.ts +2 -4
  124. package/js/src/woofipro.js +2 -2
  125. package/package.json +7 -7
@@ -0,0 +1,2016 @@
1
+ 'use strict';
2
+
3
+ require('../ccxt.js');
4
+ var foxbit$1 = require('./abstract/foxbit.js');
5
+ var errors = require('./base/errors.js');
6
+ var number = require('./base/functions/number.js');
7
+ var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
8
+ var Precise = require('./base/Precise.js');
9
+
10
+ // ----------------------------------------------------------------------------
11
+ // ---------------------------------------------------------------------------
12
+ /**
13
+ * @class foxbit
14
+ * @augments Exchange
15
+ */
16
+ class foxbit extends foxbit$1 {
17
+ describe() {
18
+ return this.deepExtend(super.describe(), {
19
+ 'id': 'foxbit',
20
+ 'name': 'Foxbit',
21
+ 'countries': ['pt-BR'],
22
+ // 300 requests per 10 seconds = 30 requests per second
23
+ // rateLimit = 1000 ms / 30 requests ~= 33.334
24
+ 'rateLimit': 33.334,
25
+ 'version': '1',
26
+ 'comment': 'Foxbit Exchange',
27
+ 'certified': false,
28
+ 'pro': false,
29
+ 'has': {
30
+ 'CORS': true,
31
+ 'spot': true,
32
+ 'margin': undefined,
33
+ 'swap': undefined,
34
+ 'future': undefined,
35
+ 'option': undefined,
36
+ 'cancelAllOrders': true,
37
+ 'cancelOrder': true,
38
+ 'createLimitBuyOrder': true,
39
+ 'createLimitSellOrder': true,
40
+ 'createMarketBuyOrder': true,
41
+ 'createMarketSellOrder': true,
42
+ 'createOrder': true,
43
+ 'fecthOrderBook': true,
44
+ 'fetchBalance': true,
45
+ 'fetchCanceledOrders': true,
46
+ 'fetchClosedOrders': true,
47
+ 'fetchCurrencies': true,
48
+ 'fetchDepositAddress': true,
49
+ 'fetchDeposits': true,
50
+ 'fetchL2OrderBook': true,
51
+ 'fetchLedger': true,
52
+ 'fetchMarkets': true,
53
+ 'fetchMyTrades': true,
54
+ 'fetchOHLCV': true,
55
+ 'fetchOpenOrders': true,
56
+ 'fetchOrder': true,
57
+ 'fetchOrders': true,
58
+ 'fetchTicker': true,
59
+ 'fetchTickers': true,
60
+ 'fetchTrades': true,
61
+ 'fetchTradingFee': true,
62
+ 'fetchTradingFees': true,
63
+ 'fetchTransactions': true,
64
+ 'fetchWithdrawals': true,
65
+ 'loadMarkets': true,
66
+ 'sandbox': false,
67
+ 'withdraw': true,
68
+ 'ws': false,
69
+ },
70
+ 'timeframes': {
71
+ '1m': '1m',
72
+ '5m': '5m',
73
+ '15m': '15m',
74
+ '30m': '30m',
75
+ '1h': '1h',
76
+ '2h': '2h',
77
+ '4h': '4h',
78
+ '6h': '6h',
79
+ '12h': '12h',
80
+ '1d': '1d',
81
+ '1w': '1w',
82
+ '2w': '2w',
83
+ '1M': '1M',
84
+ },
85
+ 'urls': {
86
+ 'logo': 'https://github.com/user-attachments/assets/63be1a3a-775d-459b-8c03-493c71c0253c',
87
+ 'api': {
88
+ 'public': 'https://api.foxbit.com.br',
89
+ 'private': 'https://api.foxbit.com.br',
90
+ 'status': 'https://metadata-v2.foxbit.com.br/api',
91
+ },
92
+ 'www': 'https://app.foxbit.com.br',
93
+ 'doc': [
94
+ 'https://docs.foxbit.com.br',
95
+ ],
96
+ },
97
+ 'precisionMode': number.DECIMAL_PLACES,
98
+ 'exceptions': {
99
+ 'exact': {
100
+ // https://docs.foxbit.com.br/rest/v3/#tag/API-Codes/Errors
101
+ '400': errors.BadRequest,
102
+ '429': errors.RateLimitExceeded,
103
+ '404': errors.BadRequest,
104
+ '500': errors.ExchangeError,
105
+ '2001': errors.AuthenticationError,
106
+ '2002': errors.AuthenticationError,
107
+ '2003': errors.AuthenticationError,
108
+ '2004': errors.BadRequest,
109
+ '2005': errors.PermissionDenied,
110
+ '3001': errors.PermissionDenied,
111
+ '3002': errors.PermissionDenied,
112
+ '3003': errors.AccountSuspended,
113
+ '4001': errors.BadRequest,
114
+ '4002': errors.InsufficientFunds,
115
+ '4003': errors.InvalidOrder,
116
+ '4004': errors.BadSymbol,
117
+ '4005': errors.BadRequest,
118
+ '4007': errors.ExchangeError,
119
+ '4008': errors.InvalidOrder,
120
+ '4009': errors.PermissionDenied,
121
+ '4011': errors.RateLimitExceeded,
122
+ '4012': errors.ExchangeError,
123
+ '5001': errors.ExchangeNotAvailable,
124
+ '5002': errors.OnMaintenance,
125
+ '5003': errors.OnMaintenance,
126
+ '5004': errors.InvalidOrder,
127
+ '5005': errors.InvalidOrder,
128
+ '5006': errors.InvalidOrder, // Significant price deviation detected, exceeding acceptable limits. The order price is exceeding acceptable limits from market to complete your request.
129
+ },
130
+ 'broad': {
131
+ // todo: add details messages that can be usefull here, like when market is not found
132
+ },
133
+ },
134
+ 'requiredCredentials': {
135
+ 'apiKey': true,
136
+ 'secret': true,
137
+ },
138
+ 'api': {
139
+ 'v3': {
140
+ 'public': {
141
+ 'get': {
142
+ 'currencies': 5,
143
+ 'markets': 5,
144
+ 'markets/ticker/24hr': 60,
145
+ 'markets/{market}/orderbook': 6,
146
+ 'markets/{market}/candlesticks': 12,
147
+ 'markets/{market}/trades/history': 12,
148
+ 'markets/{market}/ticker/24hr': 15, // 4 requests per 2 seconds
149
+ },
150
+ },
151
+ 'private': {
152
+ 'get': {
153
+ 'accounts': 2,
154
+ 'accounts/{symbol}/transactions': 60,
155
+ 'orders': 2,
156
+ 'orders/by-order-id/{id}': 2,
157
+ 'trades': 6,
158
+ 'deposits/address': 10,
159
+ 'deposits': 10,
160
+ 'withdrawals': 10,
161
+ 'me/fees/trading': 60, // 1 requests per 2 seconds
162
+ },
163
+ 'post': {
164
+ 'orders': 2,
165
+ 'orders/batch': 7.5,
166
+ 'orders/cancel-replace': 3,
167
+ 'withdrawals': 10, // 3 requests per second
168
+ },
169
+ 'put': {
170
+ 'orders/cancel': 2, // 30 requests per 2 seconds
171
+ },
172
+ },
173
+ },
174
+ 'status': {
175
+ 'public': {
176
+ 'get': {
177
+ 'status': 30, // 1 request per second
178
+ },
179
+ },
180
+ },
181
+ },
182
+ 'fees': {
183
+ 'trading': {
184
+ 'feeSide': 'get',
185
+ 'tierBased': false,
186
+ 'percentage': true,
187
+ 'taker': this.parseNumber('0.005'),
188
+ 'maker': this.parseNumber('0.0025'),
189
+ },
190
+ },
191
+ 'options': {
192
+ 'sandboxMode': false,
193
+ 'networksById': {
194
+ 'algorand': 'ALGO',
195
+ 'arbitrum': 'ARBITRUM',
196
+ 'avalanchecchain': 'AVAX',
197
+ 'bitcoin': 'BTC',
198
+ 'bitcoincash': 'BCH',
199
+ 'bsc': 'BEP20',
200
+ 'cardano': 'ADA',
201
+ 'cosmos': 'ATOM',
202
+ 'dogecoin': 'DOGE',
203
+ 'erc20': 'ETH',
204
+ 'hedera': 'HBAR',
205
+ 'litecoin': 'LTC',
206
+ 'near': 'NEAR',
207
+ 'optimism': 'OPTIMISM',
208
+ 'polkadot': 'DOT',
209
+ 'polygon': 'MATIC',
210
+ 'ripple': 'XRP',
211
+ 'solana': 'SOL',
212
+ 'stacks': 'STX',
213
+ 'stellar': 'XLM',
214
+ 'tezos': 'XTZ',
215
+ 'trc20': 'TRC20',
216
+ },
217
+ 'networks': {
218
+ 'ALGO': 'algorand',
219
+ 'ARBITRUM': 'arbitrum',
220
+ 'AVAX': 'avalanchecchain',
221
+ 'BTC': 'bitcoin',
222
+ 'BCH': 'bitcoincash',
223
+ 'BEP20': 'bsc',
224
+ 'ADA': 'cardano',
225
+ 'ATOM': 'cosmos',
226
+ 'DOGE': 'dogecoin',
227
+ 'ETH': 'erc20',
228
+ 'HBAR': 'hedera',
229
+ 'LTC': 'litecoin',
230
+ 'NEAR': 'near',
231
+ 'OPTIMISM': 'optimism',
232
+ 'DOT': 'polkadot',
233
+ 'MATIC': 'polygon',
234
+ 'XRP': 'ripple',
235
+ 'SOL': 'solana',
236
+ 'STX': 'stacks',
237
+ 'XLM': 'stellar',
238
+ 'XTZ': 'tezos',
239
+ 'TRC20': 'trc20',
240
+ },
241
+ },
242
+ 'features': {
243
+ 'spot': {
244
+ 'sandbox': false,
245
+ 'createOrder': {
246
+ 'marginMode': false,
247
+ 'triggerPrice': true,
248
+ 'triggerPriceType': {
249
+ 'last': true,
250
+ 'mark': false,
251
+ 'index': false,
252
+ },
253
+ 'triggerDirection': false,
254
+ 'stopLossPrice': false,
255
+ 'takeProfitPrice': false,
256
+ 'attachedStopLossTakeProfit': undefined,
257
+ 'timeInForce': {
258
+ 'GTC': true,
259
+ 'FOK': true,
260
+ 'IOC': true,
261
+ 'PO': true,
262
+ 'GTD': false,
263
+ },
264
+ 'hedged': false,
265
+ 'leverage': false,
266
+ 'marketBuyByCost': false,
267
+ 'marketBuyRequiresPrice': false,
268
+ 'selfTradePrevention': {
269
+ 'expire_maker': true,
270
+ 'expire_taker': true,
271
+ 'expire_both': true,
272
+ 'none': true, // foxbit prevents self trading by default, no params can change this
273
+ },
274
+ 'trailing': false,
275
+ 'icebergAmount': false,
276
+ },
277
+ 'createOrders': {
278
+ 'max': 5,
279
+ },
280
+ 'fetchMyTrades': {
281
+ 'marginMode': false,
282
+ 'limit': 100,
283
+ 'daysBack': 90,
284
+ 'untilDays': 10000,
285
+ 'symbolRequired': true,
286
+ },
287
+ 'fetchOrder': {
288
+ 'marginMode': false,
289
+ 'limit': 1,
290
+ 'daysBack': 90,
291
+ 'trigger': false,
292
+ 'trailing': false,
293
+ 'symbolRequired': false,
294
+ },
295
+ 'fetchOpenOrders': {
296
+ 'marginMode': false,
297
+ 'limit': 100,
298
+ 'daysBack': 90,
299
+ 'trigger': false,
300
+ 'trailing': false,
301
+ 'symbolRequired': false,
302
+ },
303
+ 'fetchOrders': {
304
+ 'marginMode': true,
305
+ 'limit': 100,
306
+ 'daysBack': 90,
307
+ 'untilDays': 10000,
308
+ 'trigger': false,
309
+ 'trailing': false,
310
+ 'symbolRequired': false,
311
+ },
312
+ 'fetchClosedOrders': {
313
+ 'marginMode': true,
314
+ 'limit': 100,
315
+ 'daysBack': 90,
316
+ 'daysBackCanceled': 90,
317
+ 'untilDays': 10000,
318
+ 'trigger': false,
319
+ 'trailing': false,
320
+ 'symbolRequired': false,
321
+ },
322
+ 'fetchOHLCV': {
323
+ 'limit': 500,
324
+ },
325
+ },
326
+ },
327
+ });
328
+ }
329
+ async fetchCurrencies(params = {}) {
330
+ const response = await this.v3PublicGetCurrencies(params);
331
+ // {
332
+ // "data": [
333
+ // {
334
+ // "symbol": "btc",
335
+ // "name": "Bitcoin",
336
+ // "type": "CRYPTO",
337
+ // "precision": 8,
338
+ // "deposit_info": {
339
+ // "min_to_confirm": "1",
340
+ // "min_amount": "0.0001"
341
+ // },
342
+ // "withdraw_info": {
343
+ // "enabled": true,
344
+ // "min_amount": "0.0001",
345
+ // "fee": "0.0001"
346
+ // },
347
+ // "category": {
348
+ // "code": "cripto",
349
+ // "name": "Cripto"
350
+ // },
351
+ // "networks": [
352
+ // {
353
+ // "name": "Bitcoin",
354
+ // "code": "btc",
355
+ // "deposit_info": {
356
+ // status: "ENABLED",
357
+ // },
358
+ // "withdraw_info": {
359
+ // "status": "ENABLED",
360
+ // "fee": "0.0001",
361
+ // },
362
+ // "has_destination_tag": false
363
+ // }
364
+ // ]
365
+ // }
366
+ // ]
367
+ // }
368
+ const data = this.safeList(response, 'data', []);
369
+ const result = {};
370
+ for (let i = 0; i < data.length; i++) {
371
+ const currency = data[i];
372
+ const precision = this.safeInteger(currency, 'precision');
373
+ const currencyId = this.safeString(currency, 'symbol');
374
+ const name = this.safeString(currency, 'name');
375
+ const code = this.safeCurrencyCode(currencyId);
376
+ const depositInfo = this.safeDict(currency, 'deposit_info');
377
+ const withdrawInfo = this.safeDict(currency, 'withdraw_info');
378
+ const networks = this.safeList(currency, 'networks', []);
379
+ const type = this.safeStringLower(currency, 'type');
380
+ const parsedNetworks = {};
381
+ for (let j = 0; j < networks.length; j++) {
382
+ const network = networks[j];
383
+ const networkId = this.safeString(network, 'code');
384
+ const networkCode = this.networkIdToCode(networkId, code);
385
+ const networkWithdrawInfo = this.safeDict(network, 'withdraw_info');
386
+ const networkDepositInfo = this.safeDict(network, 'deposit_info');
387
+ const isWithdrawEnabled = this.safeString(networkWithdrawInfo, 'status') === 'ENABLED';
388
+ const isDepositEnabled = this.safeString(networkDepositInfo, 'status') === 'ENABLED';
389
+ parsedNetworks[networkCode] = {
390
+ 'info': currency,
391
+ 'id': networkId,
392
+ 'network': networkCode,
393
+ 'name': this.safeString(network, 'name'),
394
+ 'deposit': isDepositEnabled,
395
+ 'withdraw': isWithdrawEnabled,
396
+ 'active': true,
397
+ 'precision': precision,
398
+ 'fee': this.safeNumber(networkWithdrawInfo, 'fee'),
399
+ 'limits': {
400
+ 'amount': {
401
+ 'min': undefined,
402
+ 'max': undefined,
403
+ },
404
+ 'deposit': {
405
+ 'min': this.safeNumber(depositInfo, 'min_amount'),
406
+ 'max': undefined,
407
+ },
408
+ 'withdraw': {
409
+ 'min': this.safeNumber(withdrawInfo, 'min_amount'),
410
+ 'max': undefined,
411
+ },
412
+ },
413
+ };
414
+ }
415
+ if (this.safeDict(result, code) === undefined) {
416
+ result[code] = this.safeCurrencyStructure({
417
+ 'id': currencyId,
418
+ 'code': code,
419
+ 'info': currency,
420
+ 'name': name,
421
+ 'active': true,
422
+ 'type': type,
423
+ 'deposit': this.safeBool(depositInfo, 'enabled', false),
424
+ 'withdraw': this.safeBool(withdrawInfo, 'enabled', false),
425
+ 'fee': this.safeNumber(withdrawInfo, 'fee'),
426
+ 'precision': precision,
427
+ 'limits': {
428
+ 'amount': {
429
+ 'min': undefined,
430
+ 'max': undefined,
431
+ },
432
+ 'deposit': {
433
+ 'min': this.safeNumber(depositInfo, 'min_amount'),
434
+ 'max': undefined,
435
+ },
436
+ 'withdraw': {
437
+ 'min': this.safeNumber(withdrawInfo, 'min_amount'),
438
+ 'max': undefined,
439
+ },
440
+ },
441
+ 'networks': parsedNetworks,
442
+ });
443
+ }
444
+ }
445
+ return result;
446
+ }
447
+ /**
448
+ * @method
449
+ * @name foxbit#fetchMarkets
450
+ * @description Retrieves data on all markets for foxbit.
451
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Market-Data/operation/MarketsController_index
452
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
453
+ * @returns {object[]} an array of objects representing market data
454
+ */
455
+ async fetchMarkets(params = {}) {
456
+ const response = await this.v3PublicGetMarkets(params);
457
+ // {
458
+ // "data": [
459
+ // {
460
+ // "symbol": "btcbrl",
461
+ // "quantity_min": "0.00000236",
462
+ // "quantity_increment": "0.00000001",
463
+ // "quantity_precision": 8,
464
+ // "price_min": "0.0001",
465
+ // "price_increment": "0.0001",
466
+ // "price_precision": 4,
467
+ // "default_fees": {
468
+ // "maker": "0.001",
469
+ // "taker": "0.001"
470
+ // },
471
+ // "base": {
472
+ // "symbol": "btc",
473
+ // "name": "Bitcoin",
474
+ // "type": "CRYPTO",
475
+ // "precision": 8,
476
+ // "category": {
477
+ // "code": "cripto",
478
+ // "name": "Cripto"
479
+ // },
480
+ // "deposit_info": {
481
+ // "min_to_confirm": "1",
482
+ // "min_amount": "0.0001",
483
+ // "enabled": true
484
+ // },
485
+ // "withdraw_info": {
486
+ // "enabled": true,
487
+ // "min_amount": "0.0001",
488
+ // "fee": "0.0001"
489
+ // },
490
+ // "networks": [
491
+ // {
492
+ // "name": "Bitcoin",
493
+ // "code": "bitcoin",
494
+ // "deposit_info": {
495
+ // "status": "ENABLED"
496
+ // },
497
+ // "withdraw_info": {
498
+ // "status": "ENABLED",
499
+ // "fee": "0.0001"
500
+ // },
501
+ // "has_destination_tag": false
502
+ // }
503
+ // ],
504
+ // "default_network_code": "bitcoin"
505
+ // },
506
+ // "quote": {
507
+ // "symbol": "btc",
508
+ // "name": "Bitcoin",
509
+ // "type": "CRYPTO",
510
+ // "precision": 8,
511
+ // "category": {
512
+ // "code": "cripto",
513
+ // "name": "Cripto"
514
+ // },
515
+ // "deposit_info": {
516
+ // "min_to_confirm": "1",
517
+ // "min_amount": "0.0001",
518
+ // "enabled": true
519
+ // },
520
+ // "withdraw_info": {
521
+ // "enabled": true,
522
+ // "min_amount": "0.0001",
523
+ // "fee": "0.0001"
524
+ // },
525
+ // "networks": [
526
+ // {
527
+ // "name": "Bitcoin",
528
+ // "code": "bitcoin",
529
+ // "deposit_info": {
530
+ // "status": "ENABLED"
531
+ // },
532
+ // "withdraw_info": {
533
+ // "status": "ENABLED",
534
+ // "fee": "0.0001"
535
+ // },
536
+ // "has_destination_tag": false
537
+ // }
538
+ // ],
539
+ // "default_network_code": "bitcoin"
540
+ // },
541
+ // "order_type": [
542
+ // "LIMIT",
543
+ // "MARKET",
544
+ // "INSTANT",
545
+ // "STOP_LIMIT",
546
+ // "STOP_MARKET"
547
+ // ]
548
+ // }
549
+ // ]
550
+ // }
551
+ const markets = this.safeList(response, 'data', []);
552
+ return this.parseMarkets(markets);
553
+ }
554
+ /**
555
+ * @method
556
+ * @name foxbit#fetchTicker
557
+ * @description Get last 24 hours ticker information, in real-time, for given market.
558
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Market-Data/operation/MarketsController_ticker
559
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
560
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
561
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
562
+ */
563
+ async fetchTicker(symbol, params = {}) {
564
+ await this.loadMarkets();
565
+ const market = this.market(symbol);
566
+ const request = {
567
+ 'market': market['id'],
568
+ };
569
+ const response = await this.v3PublicGetMarketsMarketTicker24hr(this.extend(request, params));
570
+ // {
571
+ // "data": [
572
+ // {
573
+ // "market_symbol": "btcbrl",
574
+ // "last_trade": {
575
+ // "price": "358504.69340000",
576
+ // "volume": "0.00027893",
577
+ // "date": "2024-01-01T00:00:00.000Z"
578
+ // },
579
+ // "rolling_24h": {
580
+ // "price_change": "3211.87290000",
581
+ // "price_change_percent": "0.90400726",
582
+ // "volume": "20.03206866",
583
+ // "trades_count": "4376",
584
+ // "open": "355292.82050000",
585
+ // "high": "362999.99990000",
586
+ // "low": "355002.88880000"
587
+ // },
588
+ // "best": {
589
+ // "ask": {
590
+ // "price": "358504.69340000",
591
+ // "volume": "0.00027893"
592
+ // },
593
+ // "bid": {
594
+ // "price": "358504.69340000",
595
+ // "volume": "0.00027893"
596
+ // }
597
+ // }
598
+ // }
599
+ // ]
600
+ // }
601
+ const data = this.safeList(response, 'data', []);
602
+ const result = this.safeDict(data, 0, {});
603
+ return this.parseTicker(result, market);
604
+ }
605
+ /**
606
+ * @method
607
+ * @name foxbit#fetchTickers
608
+ * @description Retrieve the ticker data of all markets.
609
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Market-Data/operation/MarketsController_tickers
610
+ * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
611
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
612
+ * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
613
+ */
614
+ async fetchTickers(symbols = undefined, params = {}) {
615
+ await this.loadMarkets();
616
+ symbols = this.marketSymbols(symbols);
617
+ const response = await this.v3PublicGetMarketsTicker24hr(params);
618
+ // {
619
+ // "data": [
620
+ // {
621
+ // "market_symbol": "btcbrl",
622
+ // "last_trade": {
623
+ // "price": "358504.69340000",
624
+ // "volume": "0.00027893",
625
+ // "date": "2024-01-01T00:00:00.000Z"
626
+ // },
627
+ // "rolling_24h": {
628
+ // "price_change": "3211.87290000",
629
+ // "price_change_percent": "0.90400726",
630
+ // "volume": "20.03206866",
631
+ // "trades_count": "4376",
632
+ // "open": "355292.82050000",
633
+ // "high": "362999.99990000",
634
+ // "low": "355002.88880000"
635
+ // },
636
+ // }
637
+ // ]
638
+ // }
639
+ const data = this.safeList(response, 'data', []);
640
+ return this.parseTickers(data, symbols);
641
+ }
642
+ /**
643
+ * @method
644
+ * @name foxbit#fetchTradingFees
645
+ * @description fetch the trading fees for multiple markets
646
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Member-Info/operation/MembersController_listTradingFees
647
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
648
+ * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
649
+ */
650
+ async fetchTradingFees(params = {}) {
651
+ await this.loadMarkets();
652
+ const response = await this.v3PrivateGetMeFeesTrading(params);
653
+ // [
654
+ // {
655
+ // "market_symbol": "btcbrl",
656
+ // "maker": "0.0025",
657
+ // "taker": "0.005"
658
+ // }
659
+ // ]
660
+ const data = this.safeList(response, 'data', []);
661
+ const result = {};
662
+ for (let i = 0; i < data.length; i++) {
663
+ const entry = data[i];
664
+ const marketId = this.safeString(entry, 'market_symbol');
665
+ const market = this.safeMarket(marketId);
666
+ const symbol = market['symbol'];
667
+ result[symbol] = this.parseTradingFee(entry, market);
668
+ }
669
+ return result;
670
+ }
671
+ /**
672
+ * @method
673
+ * @name foxbit#fetchOrderBook
674
+ * @description Exports a copy of the order book of a specific market.
675
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Market-Data/operation/MarketsController_findOrderbook
676
+ * @param {string} symbol unified symbol of the market to fetch the order book for
677
+ * @param {int} [limit] the maximum amount of order book entries to return, the maximum is 100
678
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
679
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
680
+ */
681
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
682
+ await this.loadMarkets();
683
+ const market = this.market(symbol);
684
+ const defaultLimit = 20;
685
+ const request = {
686
+ 'market': market['id'],
687
+ 'depth': (limit === undefined) ? defaultLimit : limit,
688
+ };
689
+ const response = await this.v3PublicGetMarketsMarketOrderbook(this.extend(request, params));
690
+ // {
691
+ // "sequence_id": 1234567890,
692
+ // "timestamp": 1713187921336,
693
+ // "bids": [
694
+ // [
695
+ // "3.00000000",
696
+ // "300.00000000"
697
+ // ],
698
+ // [
699
+ // "1.70000000",
700
+ // "310.00000000"
701
+ // ]
702
+ // ],
703
+ // "asks": [
704
+ // [
705
+ // "3.00000000",
706
+ // "300.00000000"
707
+ // ],
708
+ // [
709
+ // "2.00000000",
710
+ // "321.00000000"
711
+ // ]
712
+ // ]
713
+ // }
714
+ const timestamp = this.safeInteger(response, 'timestamp');
715
+ return this.parseOrderBook(response, symbol, timestamp);
716
+ }
717
+ /**
718
+ * @method
719
+ * @name foxbit#fetchTrades
720
+ * @description Retrieve the trades of a specific market.
721
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Market-Data/operation/MarketsController_publicTrades
722
+ * @param {string} symbol unified symbol of the market to fetch trades for
723
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
724
+ * @param {int} [limit] the maximum amount of trades to fetch
725
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
726
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
727
+ */
728
+ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
729
+ await this.loadMarkets();
730
+ const market = this.market(symbol);
731
+ const request = {
732
+ 'market': market['id'],
733
+ };
734
+ if (limit !== undefined) {
735
+ request['page_size'] = limit;
736
+ if (limit > 200) {
737
+ request['page_size'] = 200;
738
+ }
739
+ }
740
+ // [
741
+ // {
742
+ // "id": 1,
743
+ // "price": "329248.74700000",
744
+ // "volume": "0.00100000",
745
+ // "taker_side": "BUY",
746
+ // "created_at": "2024-01-01T00:00:00Z"
747
+ // }
748
+ // ]
749
+ const response = await this.v3PublicGetMarketsMarketTradesHistory(this.extend(request, params));
750
+ const data = this.safeList(response, 'data', []);
751
+ return this.parseTrades(data, market, since, limit);
752
+ }
753
+ /**
754
+ * @method
755
+ * @name foxbit#fetchOHLCV
756
+ * @description Fetch historical candlestick data containing the open, high, low, and close price, and the volume of a market.
757
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Market-Data/operation/MarketsController_findCandlesticks
758
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
759
+ * @param {string} timeframe the length of time each candle represents
760
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
761
+ * @param {int} [limit] the maximum amount of candles to fetch
762
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
763
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
764
+ */
765
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
766
+ await this.loadMarkets();
767
+ const market = this.market(symbol);
768
+ const interval = this.safeString(this.timeframes, timeframe, timeframe);
769
+ const request = {
770
+ 'market': market['id'],
771
+ 'interval': interval,
772
+ };
773
+ if (since !== undefined) {
774
+ request['start_time'] = this.iso8601(since);
775
+ }
776
+ if (limit !== undefined) {
777
+ request['limit'] = limit;
778
+ if (limit > 500) {
779
+ request['limit'] = 500;
780
+ }
781
+ }
782
+ const response = await this.v3PublicGetMarketsMarketCandlesticks(this.extend(request, params));
783
+ // [
784
+ // [
785
+ // "1692918000000", // timestamp
786
+ // "127772.05150000", // open
787
+ // "128467.99980000", // high
788
+ // "127750.01000000", // low
789
+ // "128353.99990000", // close
790
+ // "1692918060000", // close timestamp
791
+ // "0.17080431", // base volume
792
+ // "21866.35948786", // quote volume
793
+ // 66, // number of trades
794
+ // "0.12073605", // taker buy base volume
795
+ // "15466.34096391" // taker buy quote volume
796
+ // ]
797
+ // ]
798
+ return this.parseOHLCVs(response, market, interval, since, limit);
799
+ }
800
+ /**
801
+ * @method
802
+ * @name foxbit#fetchBalance
803
+ * @description Query for balance and get the amount of funds available for trading or funds locked in orders.
804
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Account/operation/AccountsController_all
805
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
806
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
807
+ */
808
+ async fetchBalance(params = {}) {
809
+ await this.loadMarkets();
810
+ const response = await this.v3PrivateGetAccounts(params);
811
+ // {
812
+ // "data": [
813
+ // {
814
+ // "currency_symbol": "btc",
815
+ // "balance": "10000.0",
816
+ // "balance_available": "9000.0",
817
+ // "balance_locked": "1000.0"
818
+ // }
819
+ // ]
820
+ // }
821
+ const accounts = this.safeList(response, 'data', []);
822
+ const result = {
823
+ 'info': response,
824
+ };
825
+ for (let i = 0; i < accounts.length; i++) {
826
+ const account = accounts[i];
827
+ const currencyId = this.safeString(account, 'currency_symbol');
828
+ const currencyCode = this.safeCurrencyCode(currencyId);
829
+ const total = this.safeString(account, 'balance');
830
+ const used = this.safeString(account, 'balance_locked');
831
+ const free = this.safeString(account, 'balance_available');
832
+ const balanceObj = {
833
+ 'free': free,
834
+ 'used': used,
835
+ 'total': total,
836
+ };
837
+ result[currencyCode] = balanceObj;
838
+ }
839
+ return this.safeBalance(result);
840
+ }
841
+ /**
842
+ * @method
843
+ * @name foxbit#fetchOpenOrders
844
+ * @description Fetch all unfilled currently open orders.
845
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Trading/operation/OrdersController_listOrders
846
+ * @param {string} symbol unified market symbol
847
+ * @param {int} [since] the earliest time in ms to fetch open orders for
848
+ * @param {int} [limit] the maximum number of open order structures to retrieve
849
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
850
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
851
+ */
852
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
853
+ return await this.fetchOrdersByStatus('ACTIVE', symbol, since, limit, params);
854
+ }
855
+ /**
856
+ * @method
857
+ * @name foxbit#fetchClosedOrders
858
+ * @description Fetch all currently closed orders.
859
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Trading/operation/OrdersController_listOrders
860
+ * @param {string} symbol unified market symbol of the market orders were made in
861
+ * @param {int} [since] the earliest time in ms to fetch orders for
862
+ * @param {int} [limit] the maximum number of order structures to retrieve
863
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
864
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
865
+ */
866
+ async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
867
+ return await this.fetchOrdersByStatus('FILLED', symbol, since, limit, params);
868
+ }
869
+ async fetchCanceledOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
870
+ return await this.fetchOrdersByStatus('CANCELED', symbol, since, limit, params);
871
+ }
872
+ async fetchOrdersByStatus(status, symbol = undefined, since = undefined, limit = undefined, params = {}) {
873
+ await this.loadMarkets();
874
+ let market = undefined;
875
+ const request = {
876
+ 'state': status,
877
+ };
878
+ if (symbol !== undefined) {
879
+ market = this.market(symbol);
880
+ request['market_symbol'] = market['id'];
881
+ }
882
+ if (since !== undefined) {
883
+ request['start_time'] = this.iso8601(since);
884
+ }
885
+ if (limit !== undefined) {
886
+ request['page_size'] = limit;
887
+ if (limit > 100) {
888
+ request['page_size'] = 100;
889
+ }
890
+ }
891
+ const response = await this.v3PrivateGetOrders(this.extend(request, params));
892
+ const data = this.safeList(response, 'data', []);
893
+ return this.parseOrders(data);
894
+ }
895
+ /**
896
+ * @method
897
+ * @name foxbit#createOrder
898
+ * @description Create an order with the specified characteristics
899
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Trading/operation/OrdersController_create
900
+ * @param {string} symbol unified symbol of the market to create an order in
901
+ * @param {string} type 'market', 'limit', 'stop_market', 'stop_limit', 'instant'
902
+ * @param {string} side 'buy' or 'sell'
903
+ * @param {float} amount how much you want to trade in units of the base currency
904
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
905
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
906
+ * @param {string} [params.timeInForce] "GTC", "FOK", "IOC", "PO"
907
+ * @param {float} [params.triggerPrice] The time in force for the order. One of GTC, FOK, IOC, PO. See .features or foxbit's doc to see more details.
908
+ * @param {bool} [params.postOnly] true or false whether the order is post-only
909
+ * @param {string} [params.clientOrderId] a unique identifier for the order
910
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
911
+ */
912
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
913
+ await this.loadMarkets();
914
+ const market = this.market(symbol);
915
+ type = type.toUpperCase();
916
+ if (type !== 'LIMIT' && type !== 'MARKET' && type !== 'STOP_MARKET' && type !== 'STOP_LIMIT' && type !== 'INSTANT') {
917
+ throw new errors.InvalidOrder('Invalid order type: ' + type + '. Must be one of: limit, market, stop_market, stop_limit, instant.');
918
+ }
919
+ const timeInForce = this.safeStringUpper(params, 'timeInForce');
920
+ const postOnly = this.safeBool(params, 'postOnly', false);
921
+ const triggerPrice = this.safeNumber(params, 'triggerPrice');
922
+ const request = {
923
+ 'market_symbol': market['id'],
924
+ 'side': side.toUpperCase(),
925
+ 'type': type,
926
+ };
927
+ if (type === 'STOP_MARKET' || type === 'STOP_LIMIT') {
928
+ if (triggerPrice === undefined) {
929
+ throw new errors.InvalidOrder('Invalid order type: ' + type + '. Must have triggerPrice.');
930
+ }
931
+ }
932
+ if (timeInForce !== undefined) {
933
+ if (timeInForce === 'PO') {
934
+ request['post_only'] = true;
935
+ }
936
+ else {
937
+ request['time_in_force'] = timeInForce;
938
+ }
939
+ }
940
+ if (postOnly) {
941
+ request['post_only'] = true;
942
+ }
943
+ if (triggerPrice !== undefined) {
944
+ request['stop_price'] = this.priceToPrecision(symbol, triggerPrice);
945
+ }
946
+ if (type === 'INSTANT') {
947
+ request['amount'] = this.priceToPrecision(symbol, amount);
948
+ }
949
+ else {
950
+ request['quantity'] = this.amountToPrecision(symbol, amount);
951
+ }
952
+ if (type === 'LIMIT' || type === 'STOP_LIMIT') {
953
+ request['price'] = this.priceToPrecision(symbol, price);
954
+ }
955
+ const clientOrderId = this.safeString(params, 'clientOrderId');
956
+ if (clientOrderId !== undefined) {
957
+ request['client_order_id'] = clientOrderId;
958
+ }
959
+ params = this.omit(params, ['timeInForce', 'postOnly', 'triggerPrice', 'clientOrderId']);
960
+ const response = await this.v3PrivatePostOrders(this.extend(request, params));
961
+ // {
962
+ // "id": 1234567890,
963
+ // "sn": "OKMAKSDHRVVREK",
964
+ // "client_order_id": "451637946501"
965
+ // }
966
+ return this.parseOrder(response, market);
967
+ }
968
+ /**
969
+ * @method
970
+ * @name foxbit#createOrders
971
+ * @description create a list of trade orders
972
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Trading/operation/createBatch
973
+ * @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
974
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
975
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
976
+ */
977
+ async createOrders(orders, params = {}) {
978
+ await this.loadMarkets();
979
+ const ordersRequests = [];
980
+ for (let i = 0; i < orders.length; i++) {
981
+ const order = this.safeDict(orders, i);
982
+ const symbol = this.safeString(order, 'symbol');
983
+ const market = this.market(symbol);
984
+ const type = this.safeStringUpper(order, 'type');
985
+ const orderParams = this.safeDict(order, 'params', {});
986
+ if (type !== 'LIMIT' && type !== 'MARKET' && type !== 'STOP_MARKET' && type !== 'STOP_LIMIT' && type !== 'INSTANT') {
987
+ throw new errors.InvalidOrder('Invalid order type: ' + type + '. Must be one of: limit, market, stop_market, stop_limit, instant.');
988
+ }
989
+ const timeInForce = this.safeStringUpper(orderParams, 'timeInForce');
990
+ const postOnly = this.safeBool(orderParams, 'postOnly', false);
991
+ const triggerPrice = this.safeNumber(orderParams, 'triggerPrice');
992
+ const request = {
993
+ 'market_symbol': market['id'],
994
+ 'side': this.safeStringUpper(order, 'side'),
995
+ 'type': type,
996
+ };
997
+ if (type === 'STOP_MARKET' || type === 'STOP_LIMIT') {
998
+ if (triggerPrice === undefined) {
999
+ throw new errors.InvalidOrder('Invalid order type: ' + type + '. Must have triggerPrice.');
1000
+ }
1001
+ }
1002
+ if (timeInForce !== undefined) {
1003
+ if (timeInForce === 'PO') {
1004
+ request['post_only'] = true;
1005
+ }
1006
+ else {
1007
+ request['time_in_force'] = timeInForce;
1008
+ }
1009
+ delete orderParams['timeInForce'];
1010
+ }
1011
+ if (postOnly) {
1012
+ request['post_only'] = true;
1013
+ delete orderParams['postOnly'];
1014
+ }
1015
+ if (triggerPrice !== undefined) {
1016
+ request['stop_price'] = this.priceToPrecision(symbol, triggerPrice);
1017
+ delete orderParams['triggerPrice'];
1018
+ }
1019
+ if (type === 'INSTANT') {
1020
+ request['amount'] = this.priceToPrecision(symbol, this.safeString(order, 'amount'));
1021
+ }
1022
+ else {
1023
+ request['quantity'] = this.amountToPrecision(symbol, this.safeString(order, 'amount'));
1024
+ }
1025
+ if (type === 'LIMIT' || type === 'STOP_LIMIT') {
1026
+ request['price'] = this.priceToPrecision(symbol, this.safeString(order, 'price'));
1027
+ }
1028
+ ordersRequests.push(this.extend(request, orderParams));
1029
+ }
1030
+ const createOrdersRequest = { 'data': ordersRequests };
1031
+ const response = await this.v3PrivatePostOrdersBatch(this.extend(createOrdersRequest, params));
1032
+ // {
1033
+ // "data": [
1034
+ // {
1035
+ // "side": "BUY",
1036
+ // "type": "LIMIT",
1037
+ // "market_symbol": "btcbrl",
1038
+ // "client_order_id": "451637946501",
1039
+ // "remark": "A remarkable note for the order.",
1040
+ // "quantity": "0.42",
1041
+ // "price": "250000.0",
1042
+ // "post_only": true,
1043
+ // "time_in_force": "GTC"
1044
+ // }
1045
+ // ]
1046
+ // }
1047
+ const data = this.safeList(response, 'data', []);
1048
+ return this.parseOrders(data);
1049
+ }
1050
+ /**
1051
+ * @method
1052
+ * @name foxbit#cancelOrder
1053
+ * @description Cancel open orders.
1054
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Trading/operation/OrdersController_cancel
1055
+ * @param {string} id order id
1056
+ * @param {string} symbol unified symbol of the market the order was made in
1057
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1058
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1059
+ */
1060
+ async cancelOrder(id, symbol = undefined, params = {}) {
1061
+ await this.loadMarkets();
1062
+ const request = {
1063
+ 'id': this.parseNumber(id),
1064
+ 'type': 'ID',
1065
+ };
1066
+ const response = await this.v3PrivatePutOrdersCancel(this.extend(request, params));
1067
+ // {
1068
+ // "data": [
1069
+ // {
1070
+ // "sn": "OKMAKSDHRVVREK",
1071
+ // "id": 123456789
1072
+ // }
1073
+ // ]
1074
+ // }
1075
+ const data = this.safeList(response, 'data', []);
1076
+ const result = this.safeDict(data, 0, {});
1077
+ return this.parseOrder(result);
1078
+ }
1079
+ /**
1080
+ * @method
1081
+ * @name foxbit#cancelAllOrders
1082
+ * @description Cancel all open orders or all open orders for a specific market.
1083
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Trading/operation/OrdersController_cancel
1084
+ * @param {string} symbol unified market symbol of the market to cancel orders in
1085
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1086
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1087
+ */
1088
+ async cancelAllOrders(symbol = undefined, params = {}) {
1089
+ await this.loadMarkets();
1090
+ const request = {
1091
+ 'type': 'ALL',
1092
+ };
1093
+ if (symbol !== undefined) {
1094
+ const market = this.market(symbol);
1095
+ request['type'] = 'MARKET';
1096
+ request['market_symbol'] = market['id'];
1097
+ }
1098
+ const response = await this.v3PrivatePutOrdersCancel(this.extend(request, params));
1099
+ // {
1100
+ // "data": [
1101
+ // {
1102
+ // "sn": "OKMAKSDHRVVREK",
1103
+ // "id": 123456789
1104
+ // }
1105
+ // ]
1106
+ // }
1107
+ return [this.safeOrder({
1108
+ 'info': response,
1109
+ })];
1110
+ }
1111
+ /**
1112
+ * @method
1113
+ * @name foxbit#fetchOrder
1114
+ * @description Get an order by ID.
1115
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Trading/operation/OrdersController_findByOrderId
1116
+ * @param id
1117
+ * @param {string} symbol it is not used in the foxbit API
1118
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1119
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1120
+ */
1121
+ async fetchOrder(id, symbol = undefined, params = {}) {
1122
+ await this.loadMarkets();
1123
+ const request = {
1124
+ 'id': id,
1125
+ };
1126
+ const response = await this.v3PrivateGetOrdersByOrderIdId(this.extend(request, params));
1127
+ // {
1128
+ // "id": "1234567890",
1129
+ // "sn": "OKMAKSDHRVVREK",
1130
+ // "client_order_id": "451637946501",
1131
+ // "market_symbol": "btcbrl",
1132
+ // "side": "BUY",
1133
+ // "type": "LIMIT",
1134
+ // "state": "ACTIVE",
1135
+ // "price": "290000.0",
1136
+ // "price_avg": "295333.3333",
1137
+ // "quantity": "0.42",
1138
+ // "quantity_executed": "0.41",
1139
+ // "instant_amount": "290.0",
1140
+ // "instant_amount_executed": "290.0",
1141
+ // "created_at": "2021-02-15T22:06:32.999Z",
1142
+ // "trades_count": "2",
1143
+ // "remark": "A remarkable note for the order.",
1144
+ // "funds_received": "290.0"
1145
+ // }
1146
+ return this.parseOrder(response, undefined);
1147
+ }
1148
+ /**
1149
+ * @method
1150
+ * @name foxbit#fetchOrders
1151
+ * @description fetches information on multiple orders made by the user
1152
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Trading/operation/OrdersController_listOrders
1153
+ * @param {string} symbol unified market symbol of the market orders were made in
1154
+ * @param {int} [since] the earliest time in ms to fetch orders for
1155
+ * @param {int} [limit] the maximum number of order structures to retrieve
1156
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1157
+ * @param {string} [params.state] Enum: ACTIVE, CANCELED, FILLED, PARTIALLY_CANCELED, PARTIALLY_FILLED
1158
+ * @param {string} [params.side] Enum: BUY, SELL
1159
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1160
+ */
1161
+ async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1162
+ await this.loadMarkets();
1163
+ let market = undefined;
1164
+ const request = {};
1165
+ if (symbol !== undefined) {
1166
+ market = this.market(symbol);
1167
+ request['market_symbol'] = market['id'];
1168
+ }
1169
+ if (since !== undefined) {
1170
+ request['start_time'] = this.iso8601(since);
1171
+ }
1172
+ if (limit !== undefined) {
1173
+ request['page_size'] = limit;
1174
+ if (limit > 100) {
1175
+ request['page_size'] = 100;
1176
+ }
1177
+ }
1178
+ const response = await this.v3PrivateGetOrders(this.extend(request, params));
1179
+ // {
1180
+ // "data": [
1181
+ // {
1182
+ // "id": "1234567890",
1183
+ // "sn": "OKMAKSDHRVVREK",
1184
+ // "client_order_id": "451637946501",
1185
+ // "market_symbol": "btcbrl",
1186
+ // "side": "BUY",
1187
+ // "type": "LIMIT",
1188
+ // "state": "ACTIVE",
1189
+ // "price": "290000.0",
1190
+ // "price_avg": "295333.3333",
1191
+ // "quantity": "0.42",
1192
+ // "quantity_executed": "0.41",
1193
+ // "instant_amount": "290.0",
1194
+ // "instant_amount_executed": "290.0",
1195
+ // "created_at": "2021-02-15T22:06:32.999Z",
1196
+ // "trades_count": "2",
1197
+ // "remark": "A remarkable note for the order.",
1198
+ // "funds_received": "290.0"
1199
+ // }
1200
+ // ]
1201
+ // }
1202
+ const list = this.safeList(response, 'data', []);
1203
+ return this.parseOrders(list, market, since, limit);
1204
+ }
1205
+ /**
1206
+ * @method
1207
+ * @name foxbit#fetchMyTrades
1208
+ * @description Trade history queries will only have data available for the last 3 months, in descending order (most recents trades first).
1209
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Trading/operation/TradesController_all
1210
+ * @param {string} symbol unified market symbol
1211
+ * @param {int} [since] the earliest time in ms to fetch trades for
1212
+ * @param {int} [limit] the maximum number of trade structures to retrieve
1213
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1214
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1215
+ */
1216
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1217
+ if (symbol === undefined) {
1218
+ throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
1219
+ }
1220
+ await this.loadMarkets();
1221
+ const market = this.market(symbol);
1222
+ const request = {
1223
+ 'market_symbol': market['id'],
1224
+ };
1225
+ if (since !== undefined) {
1226
+ request['start_time'] = this.iso8601(since);
1227
+ }
1228
+ if (limit !== undefined) {
1229
+ request['page_size'] = limit;
1230
+ if (limit > 100) {
1231
+ request['page_size'] = 100;
1232
+ }
1233
+ }
1234
+ const response = await this.v3PrivateGetTrades(this.extend(request, params));
1235
+ // {
1236
+ // "data": [
1237
+ // "id": 1234567890,
1238
+ // "sn": "TC5JZVW2LLJ3IW",
1239
+ // "order_id": 1234567890,
1240
+ // "market_symbol": "btcbrl",
1241
+ // "side": "BUY",
1242
+ // "price": "290000.0",
1243
+ // "quantity": "1.0",
1244
+ // "fee": "0.01",
1245
+ // "fee_currency_symbol": "btc",
1246
+ // "created_at": "2021-02-15T22:06:32.999Z"
1247
+ // ]
1248
+ // }
1249
+ const data = this.safeList(response, 'data', []);
1250
+ return this.parseTrades(data, market, since, limit);
1251
+ }
1252
+ /**
1253
+ * @method
1254
+ * @name foxbit#fetchDepositAddress
1255
+ * @description Fetch the deposit address for a currency associated with this account.
1256
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Deposit/operation/DepositsController_depositAddress
1257
+ * @param {string} code unified currency code
1258
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1259
+ * @param {string} [params.networkCode] the blockchain network to create a deposit address on
1260
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
1261
+ */
1262
+ async fetchDepositAddress(code, params = {}) {
1263
+ await this.loadMarkets();
1264
+ const currency = this.currency(code);
1265
+ const request = {
1266
+ 'currency_symbol': currency['id'],
1267
+ };
1268
+ const [networkCode, paramsOmited] = this.handleNetworkCodeAndParams(params);
1269
+ if (networkCode !== undefined) {
1270
+ request['network_code'] = this.networkCodeToId(networkCode, code);
1271
+ }
1272
+ const response = await this.v3PrivateGetDepositsAddress(this.extend(request, paramsOmited));
1273
+ // {
1274
+ // "currency_symbol": "btc",
1275
+ // "address": "2N9sS8LgrY19rvcCWDmE1ou1tTVmqk4KQAB",
1276
+ // "message": "Address was retrieved successfully",
1277
+ // "destination_tag": "string",
1278
+ // "network": {
1279
+ // "name": "Bitcoin Network",
1280
+ // "code": "btc"
1281
+ // }
1282
+ // }
1283
+ return this.parseDepositAddress(response, currency);
1284
+ }
1285
+ /**
1286
+ * @method
1287
+ * @name foxbit#fetchDeposits
1288
+ * @description Fetch all deposits made to an account.
1289
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Deposit/operation/DepositsController_listOrders
1290
+ * @param {string} [code] unified currency code
1291
+ * @param {int} [since] the earliest time in ms to fetch deposits for
1292
+ * @param {int} [limit] the maximum number of deposit structures to retrieve
1293
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1294
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1295
+ */
1296
+ async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
1297
+ await this.loadMarkets();
1298
+ const request = {};
1299
+ let currency = undefined;
1300
+ if (code !== undefined) {
1301
+ currency = this.currency(code);
1302
+ }
1303
+ if (limit !== undefined) {
1304
+ request['page_size'] = limit;
1305
+ if (limit > 100) {
1306
+ request['page_size'] = 100;
1307
+ }
1308
+ }
1309
+ if (since !== undefined) {
1310
+ request['start_time'] = this.iso8601(since);
1311
+ }
1312
+ const response = await this.v3PrivateGetDeposits(this.extend(request, params));
1313
+ // {
1314
+ // "data": [
1315
+ // {
1316
+ // "sn": "OKMAKSDHRVVREK",
1317
+ // "state": "ACCEPTED",
1318
+ // "currency_symbol": "btc",
1319
+ // "amount": "1.0",
1320
+ // "fee": "0.1",
1321
+ // "created_at": "2022-02-18T22:06:32.999Z",
1322
+ // "details_crypto": {
1323
+ // "transaction_id": "e20f035387020c5d5ea18ad53244f09f3",
1324
+ // "receiving_address": "2N2rTrnKEFcyJjEJqvVjgWZ3bKvKT7Aij61"
1325
+ // }
1326
+ // }
1327
+ // ]
1328
+ // }
1329
+ const data = this.safeList(response, 'data', []);
1330
+ return this.parseTransactions(data, currency, since, limit);
1331
+ }
1332
+ /**
1333
+ * @method
1334
+ * @name foxbit#fetchWithdrawals
1335
+ * @description Fetch all withdrawals made from an account.
1336
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Withdrawal/operation/WithdrawalsController_listWithdrawals
1337
+ * @param {string} [code] unified currency code
1338
+ * @param {int} [since] the earliest time in ms to fetch withdrawals for
1339
+ * @param {int} [limit] the maximum number of withdrawal structures to retrieve
1340
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1341
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1342
+ */
1343
+ async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
1344
+ await this.loadMarkets();
1345
+ const request = {};
1346
+ let currency = undefined;
1347
+ if (code !== undefined) {
1348
+ currency = this.currency(code);
1349
+ }
1350
+ if (limit !== undefined) {
1351
+ request['page_size'] = limit;
1352
+ if (limit > 100) {
1353
+ request['page_size'] = 100;
1354
+ }
1355
+ }
1356
+ if (since !== undefined) {
1357
+ request['start_time'] = this.iso8601(since);
1358
+ }
1359
+ const response = await this.v3PrivateGetWithdrawals(this.extend(request, params));
1360
+ // {
1361
+ // "data": [
1362
+ // {
1363
+ // "sn": "OKMAKSDHRVVREK",
1364
+ // "state": "ACCEPTED",
1365
+ // "rejection_reason": "monthly_limit_exceeded",
1366
+ // "currency_symbol": "btc",
1367
+ // "amount": "1.0",
1368
+ // "fee": "0.1",
1369
+ // "created_at": "2022-02-18T22:06:32.999Z",
1370
+ // "details_crypto": {
1371
+ // "transaction_id": "e20f035387020c5d5ea18ad53244f09f3",
1372
+ // "destination_address": "2N2rTrnKEFcyJjEJqvVjgWZ3bKvKT7Aij61"
1373
+ // },
1374
+ // "details_fiat": {
1375
+ // "bank": {
1376
+ // "code": "1",
1377
+ // "branch": {
1378
+ // "number": "1234567890",
1379
+ // "digit": "1"
1380
+ // },
1381
+ // "account": {
1382
+ // "number": "1234567890",
1383
+ // "digit": "1",
1384
+ // "type": "CHECK"
1385
+ // }
1386
+ // }
1387
+ // }
1388
+ // }
1389
+ // ]
1390
+ // }
1391
+ const data = this.safeList(response, 'data', []);
1392
+ return this.parseTransactions(data, currency, since, limit);
1393
+ }
1394
+ /**
1395
+ * @method
1396
+ * @name foxbit#fetchTransactions
1397
+ * @description Fetch all transactions (deposits and withdrawals) made from an account.
1398
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Withdrawal/operation/WithdrawalsController_listWithdrawals
1399
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Deposit/operation/DepositsController_listOrders
1400
+ * @param {string} [code] unified currency code
1401
+ * @param {int} [since] the earliest time in ms to fetch withdrawals for
1402
+ * @param {int} [limit] the maximum number of withdrawal structures to retrieve
1403
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1404
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1405
+ */
1406
+ async fetchTransactions(code = undefined, since = undefined, limit = undefined, params = {}) {
1407
+ const withdrawals = await this.fetchWithdrawals(code, since, limit, params);
1408
+ const deposits = await this.fetchDeposits(code, since, limit, params);
1409
+ const allTransactions = this.arrayConcat(withdrawals, deposits);
1410
+ const result = this.sortBy(allTransactions, 'timestamp');
1411
+ return result;
1412
+ }
1413
+ /**
1414
+ * @method
1415
+ * @name foxbit#fetchStatus
1416
+ * @description The latest known information on the availability of the exchange API.
1417
+ * @see https://status.foxbit.com/
1418
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1419
+ * @returns {object} a [status structure]{@link https://docs.ccxt.com/#/?id=exchange-status-structure}
1420
+ */
1421
+ async fetchStatus(params = {}) {
1422
+ const response = await this.statusPublicGetStatus(params);
1423
+ // {
1424
+ // "data": {
1425
+ // "id": 1,
1426
+ // "attributes": {
1427
+ // "status": "NORMAL",
1428
+ // "createdAt": "2023-05-17T18:37:05.934Z",
1429
+ // "updatedAt": "2024-04-17T02:33:50.945Z",
1430
+ // "publishedAt": "2023-05-17T18:37:07.653Z",
1431
+ // "locale": "pt-BR"
1432
+ // }
1433
+ // },
1434
+ // "meta": {
1435
+ // }
1436
+ // }
1437
+ const data = this.safeDict(response, 'data', {});
1438
+ const attributes = this.safeDict(data, 'attributes', {});
1439
+ const statusRaw = this.safeString(attributes, 'status');
1440
+ const statusMap = {
1441
+ 'NORMAL': 'ok',
1442
+ 'UNDER_MAINTENANCE': 'maintenance',
1443
+ };
1444
+ return {
1445
+ 'status': this.safeString(statusMap, statusRaw, statusRaw),
1446
+ 'updated': this.safeString(attributes, 'updatedAt'),
1447
+ 'eta': undefined,
1448
+ 'url': undefined,
1449
+ 'info': response,
1450
+ };
1451
+ }
1452
+ /**
1453
+ * @method
1454
+ * @name foxbit#editOrder
1455
+ * @description Simultaneously cancel an existing order and create a new one.
1456
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Trading/operation/OrdersController_cancelReplace
1457
+ * @param {string} id order id
1458
+ * @param {string} symbol unified symbol of the market to create an order in
1459
+ * @param {string} type 'market' or 'limit'
1460
+ * @param {string} side 'buy' or 'sell'
1461
+ * @param {float} amount how much of the currency you want to trade in units of the base currency
1462
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders, used as stop_price on stop market orders
1463
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1464
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1465
+ */
1466
+ async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1467
+ if (symbol === undefined) {
1468
+ throw new errors.ArgumentsRequired(this.id + ' editOrder() requires a symbol argument');
1469
+ }
1470
+ type = type.toUpperCase();
1471
+ if (type !== 'LIMIT' && type !== 'MARKET' && type !== 'STOP_MARKET' && type !== 'INSTANT') {
1472
+ throw new errors.InvalidOrder('Invalid order type: ' + type + '. Must be one of: LIMIT, MARKET, STOP_MARKET, INSTANT.');
1473
+ }
1474
+ await this.loadMarkets();
1475
+ const market = this.market(symbol);
1476
+ const request = {
1477
+ 'mode': 'ALLOW_FAILURE',
1478
+ 'cancel': {
1479
+ 'type': 'ID',
1480
+ 'id': this.parseNumber(id),
1481
+ },
1482
+ 'create': {
1483
+ 'type': type,
1484
+ 'side': side.toUpperCase(),
1485
+ 'market_symbol': market['id'],
1486
+ },
1487
+ };
1488
+ if (type === 'LIMIT' || type === 'MARKET') {
1489
+ request['create']['quantity'] = this.amountToPrecision(symbol, amount);
1490
+ if (type === 'LIMIT') {
1491
+ request['create']['price'] = this.priceToPrecision(symbol, price);
1492
+ }
1493
+ }
1494
+ if (type === 'STOP_MARKET') {
1495
+ request['create']['stop_price'] = this.priceToPrecision(symbol, price);
1496
+ request['create']['quantity'] = this.amountToPrecision(symbol, amount);
1497
+ }
1498
+ if (type === 'INSTANT') {
1499
+ request['create']['amount'] = this.priceToPrecision(symbol, amount);
1500
+ }
1501
+ const response = await this.v3PrivatePostOrdersCancelReplace(this.extend(request, params));
1502
+ // {
1503
+ // "cancel": {
1504
+ // "id": 123456789
1505
+ // },
1506
+ // "create": {
1507
+ // "id": 1234567890,
1508
+ // "client_order_id": "451637946501"
1509
+ // }
1510
+ // }
1511
+ return this.parseOrder(response['create'], market);
1512
+ }
1513
+ /**
1514
+ * @method
1515
+ * @name foxbit#withdraw
1516
+ * @description Make a withdrawal.
1517
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Withdrawal/operation/WithdrawalsController_createWithdrawal
1518
+ * @param {string} code unified currency code
1519
+ * @param {float} amount the amount to withdraw
1520
+ * @param {string} address the address to withdraw to
1521
+ * @param {string} tag
1522
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1523
+ * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1524
+ */
1525
+ async withdraw(code, amount, address, tag = undefined, params = {}) {
1526
+ [tag, params] = this.handleWithdrawTagAndParams(tag, params);
1527
+ await this.loadMarkets();
1528
+ const currency = this.currency(code);
1529
+ const request = {
1530
+ 'currency_symbol': currency['id'],
1531
+ 'amount': this.numberToString(amount),
1532
+ 'destination_address': address,
1533
+ };
1534
+ if (tag !== undefined) {
1535
+ request['destination_tag'] = tag;
1536
+ }
1537
+ let networkCode = undefined;
1538
+ [networkCode, params] = this.handleNetworkCodeAndParams(params);
1539
+ if (networkCode !== undefined) {
1540
+ request['network_code'] = this.networkCodeToId(networkCode);
1541
+ }
1542
+ const response = await this.v3PrivatePostWithdrawals(this.extend(request, params));
1543
+ // {
1544
+ // "amount": "1",
1545
+ // "currency_symbol": "xrp",
1546
+ // "network_code": "ripple",
1547
+ // "destination_address": "0x1234567890123456789012345678",
1548
+ // "destination_tag": "123456"
1549
+ // }
1550
+ return this.parseTransaction(response);
1551
+ }
1552
+ /**
1553
+ * @method
1554
+ * @name foxbit#fetchLedger
1555
+ * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
1556
+ * @see https://docs.foxbit.com.br/rest/v3/#tag/Account/operation/AccountsController_getTransactions
1557
+ * @param {string} code unified currency code, default is undefined
1558
+ * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
1559
+ * @param {int} [limit] max number of ledger entrys to return, default is undefined
1560
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1561
+ * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
1562
+ */
1563
+ async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
1564
+ await this.loadMarkets();
1565
+ const request = {};
1566
+ if (code === undefined) {
1567
+ throw new errors.ArgumentsRequired(this.id + ' fetchLedger() requires a code argument');
1568
+ }
1569
+ if (limit !== undefined) {
1570
+ request['page_size'] = limit;
1571
+ if (limit > 100) {
1572
+ request['page_size'] = 100;
1573
+ }
1574
+ }
1575
+ if (since !== undefined) {
1576
+ request['start_time'] = this.iso8601(since);
1577
+ }
1578
+ const currency = this.currency(code);
1579
+ request['symbol'] = currency['id'];
1580
+ const response = await this.v3PrivateGetAccountsSymbolTransactions(this.extend(request, params));
1581
+ const data = this.safeList(response, 'data', []);
1582
+ return this.parseLedger(data, currency, since, limit);
1583
+ }
1584
+ parseMarket(market) {
1585
+ const id = this.safeString(market, 'symbol');
1586
+ const baseAssets = this.safeDict(market, 'base');
1587
+ const baseId = this.safeString(baseAssets, 'symbol');
1588
+ const quoteAssets = this.safeDict(market, 'quote');
1589
+ const quoteId = this.safeString(quoteAssets, 'symbol');
1590
+ const base = this.safeCurrencyCode(baseId);
1591
+ const quote = this.safeCurrencyCode(quoteId);
1592
+ const symbol = base + '/' + quote;
1593
+ const fees = this.safeDict(market, 'default_fees');
1594
+ return this.safeMarketStructure({
1595
+ 'id': id,
1596
+ 'symbol': symbol,
1597
+ 'base': base,
1598
+ 'quote': quote,
1599
+ 'baseId': baseId,
1600
+ 'quoteId': quoteId,
1601
+ 'active': true,
1602
+ 'type': 'spot',
1603
+ 'spot': true,
1604
+ 'margin': false,
1605
+ 'future': false,
1606
+ 'swap': false,
1607
+ 'option': false,
1608
+ 'contract': false,
1609
+ 'settle': undefined,
1610
+ 'settleId': undefined,
1611
+ 'contractSize': undefined,
1612
+ 'linear': undefined,
1613
+ 'inverse': undefined,
1614
+ 'expiry': undefined,
1615
+ 'expiryDatetime': undefined,
1616
+ 'strike': undefined,
1617
+ 'optionType': undefined,
1618
+ 'taker': this.safeNumber(fees, 'taker'),
1619
+ 'maker': this.safeNumber(fees, 'maker'),
1620
+ 'percentage': true,
1621
+ 'tierBased': false,
1622
+ 'feeSide': 'get',
1623
+ 'precision': {
1624
+ 'price': this.safeInteger(quoteAssets, 'precision'),
1625
+ 'amount': this.safeInteger(baseAssets, 'precision'),
1626
+ 'cost': this.safeInteger(quoteAssets, 'precision'),
1627
+ },
1628
+ 'limits': {
1629
+ 'amount': {
1630
+ 'min': this.safeNumber(market, 'quantity_min'),
1631
+ 'max': undefined,
1632
+ },
1633
+ 'price': {
1634
+ 'min': this.safeNumber(market, 'price_min'),
1635
+ 'max': undefined,
1636
+ },
1637
+ 'cost': {
1638
+ 'min': undefined,
1639
+ 'max': undefined,
1640
+ },
1641
+ 'leverage': {
1642
+ 'min': undefined,
1643
+ 'max': undefined,
1644
+ },
1645
+ },
1646
+ 'info': market,
1647
+ });
1648
+ }
1649
+ parseTradingFee(entry, market = undefined) {
1650
+ return {
1651
+ 'info': entry,
1652
+ 'symbol': market['symbol'],
1653
+ 'maker': this.safeNumber(entry, 'maker'),
1654
+ 'taker': this.safeNumber(entry, 'taker'),
1655
+ 'percentage': true,
1656
+ 'tierBased': true,
1657
+ };
1658
+ }
1659
+ parseTicker(ticker, market = undefined) {
1660
+ const marketId = this.safeString(ticker, 'market_symbol');
1661
+ const symbol = this.safeSymbol(marketId, market, undefined, 'spot');
1662
+ const rolling_24h = ticker['rolling_24h'];
1663
+ const best = this.safeDict(ticker, 'best');
1664
+ const bestAsk = this.safeDict(best, 'ask');
1665
+ const bestBid = this.safeDict(best, 'bid');
1666
+ const lastTrade = ticker['last_trade'];
1667
+ const lastPrice = this.safeString(lastTrade, 'price');
1668
+ return this.safeTicker({
1669
+ 'symbol': symbol,
1670
+ 'timestamp': this.parseDate(this.safeString(lastTrade, 'date')),
1671
+ 'datetime': this.iso8601(this.parseDate(this.safeString(lastTrade, 'date'))),
1672
+ 'high': this.safeNumber(rolling_24h, 'high'),
1673
+ 'low': this.safeNumber(rolling_24h, 'low'),
1674
+ 'bid': this.safeNumber(bestBid, 'price'),
1675
+ 'bidVolume': this.safeNumber(bestBid, 'volume'),
1676
+ 'ask': this.safeNumber(bestAsk, 'price'),
1677
+ 'askVolume': this.safeNumber(bestAsk, 'volume'),
1678
+ 'vwap': undefined,
1679
+ 'open': this.safeNumber(rolling_24h, 'open'),
1680
+ 'close': lastPrice,
1681
+ 'last': lastPrice,
1682
+ 'previousClose': undefined,
1683
+ 'change': this.safeString(rolling_24h, 'price_change'),
1684
+ 'percentage': this.safeString(rolling_24h, 'price_change_percent'),
1685
+ 'average': undefined,
1686
+ 'baseVolume': this.safeString(rolling_24h, 'volume'),
1687
+ 'quoteVolume': undefined,
1688
+ 'info': ticker,
1689
+ }, market);
1690
+ }
1691
+ parseOHLCV(ohlcv, market = undefined) {
1692
+ return [
1693
+ this.safeInteger(ohlcv, 0),
1694
+ this.safeNumber(ohlcv, 1),
1695
+ this.safeNumber(ohlcv, 2),
1696
+ this.safeNumber(ohlcv, 3),
1697
+ this.safeNumber(ohlcv, 4),
1698
+ this.safeNumber(ohlcv, 6),
1699
+ ];
1700
+ }
1701
+ parseTrade(trade, market = undefined) {
1702
+ const timestamp = this.parseDate(this.safeString(trade, 'created_at'));
1703
+ const price = this.safeString(trade, 'price');
1704
+ const amount = this.safeString(trade, 'volume', this.safeString(trade, 'quantity'));
1705
+ const privateSideField = this.safeStringLower(trade, 'side');
1706
+ const side = this.safeStringLower(trade, 'taker_side', privateSideField);
1707
+ const cost = Precise["default"].stringMul(price, amount);
1708
+ const fee = {
1709
+ 'currency': this.safeSymbol(this.safeString(trade, 'fee_currency_symbol')),
1710
+ 'cost': this.safeNumber(trade, 'fee'),
1711
+ 'rate': undefined,
1712
+ };
1713
+ return this.safeTrade({
1714
+ 'id': this.safeString(trade, 'id'),
1715
+ 'info': trade,
1716
+ 'timestamp': timestamp,
1717
+ 'datetime': this.iso8601(timestamp),
1718
+ 'symbol': market['symbol'],
1719
+ 'order': undefined,
1720
+ 'type': undefined,
1721
+ 'side': side,
1722
+ 'takerOrMaker': undefined,
1723
+ 'price': price,
1724
+ 'amount': amount,
1725
+ 'cost': cost,
1726
+ 'fee': fee,
1727
+ }, market);
1728
+ }
1729
+ parseOrderStatus(status) {
1730
+ const statuses = {
1731
+ 'PARTIALLY_CANCELED': 'open',
1732
+ 'ACTIVE': 'open',
1733
+ 'PARTIALLY_FILLED': 'open',
1734
+ 'FILLED': 'closed',
1735
+ 'PENDING_CANCEL': 'canceled',
1736
+ 'CANCELED': 'canceled',
1737
+ };
1738
+ return this.safeString(statuses, status, status);
1739
+ }
1740
+ parseOrder(order, market = undefined) {
1741
+ let symbol = this.safeString(order, 'market_symbol');
1742
+ if (market === undefined && symbol !== undefined) {
1743
+ market = this.market(symbol);
1744
+ }
1745
+ if (market !== undefined) {
1746
+ symbol = market['symbol'];
1747
+ }
1748
+ const timestamp = this.parseDate(this.safeString(order, 'created_at'));
1749
+ const price = this.safeString(order, 'price');
1750
+ const filled = this.safeString(order, 'quantity_executed');
1751
+ const remaining = this.safeString(order, 'quantity');
1752
+ // TODO: validate logic of amount here, should this be calculated?
1753
+ let amount = undefined;
1754
+ if (remaining !== undefined && filled !== undefined) {
1755
+ amount = Precise["default"].stringAdd(remaining, filled);
1756
+ }
1757
+ let cost = this.safeString(order, 'funds_received');
1758
+ if (!cost) {
1759
+ const priceAverage = this.safeString(order, 'price_avg');
1760
+ const priceToCalculate = this.safeString(order, 'price', priceAverage);
1761
+ cost = Precise["default"].stringMul(priceToCalculate, amount);
1762
+ }
1763
+ const side = this.safeStringLower(order, 'side');
1764
+ let feeCurrency = this.safeStringUpper(market, 'quoteId');
1765
+ if (side === 'buy') {
1766
+ feeCurrency = this.safeStringUpper(market, 'baseId');
1767
+ }
1768
+ return this.safeOrder({
1769
+ 'id': this.safeString(order, 'id'),
1770
+ 'info': order,
1771
+ 'clientOrderId': this.safeString(order, 'client_order_id'),
1772
+ 'timestamp': timestamp,
1773
+ 'datetime': this.iso8601(timestamp),
1774
+ 'lastTradeTimestamp': undefined,
1775
+ 'status': this.parseOrderStatus(this.safeString(order, 'state')),
1776
+ 'symbol': this.safeString(market, 'symbol'),
1777
+ 'type': this.safeString(order, 'type'),
1778
+ 'timeInForce': this.safeString(order, 'time_in_force'),
1779
+ 'postOnly': this.safeBool(order, 'post_only'),
1780
+ 'reduceOnly': undefined,
1781
+ 'side': side,
1782
+ 'price': this.parseNumber(price),
1783
+ 'triggerPrice': this.safeNumber(order, 'stop_price'),
1784
+ 'takeProfitPrice': undefined,
1785
+ 'stopLossPrice': undefined,
1786
+ 'cost': this.parseNumber(cost),
1787
+ 'average': this.safeNumber(order, 'price_avg'),
1788
+ 'amount': this.parseNumber(amount),
1789
+ 'filled': this.parseNumber(filled),
1790
+ 'remaining': this.parseNumber(remaining),
1791
+ 'trades': undefined,
1792
+ 'fee': {
1793
+ 'currency': feeCurrency,
1794
+ 'cost': this.safeNumber(order, 'fee_paid'),
1795
+ },
1796
+ });
1797
+ }
1798
+ parseDepositAddress(depositAddress, currency = undefined) {
1799
+ const network = this.safeDict(depositAddress, 'network');
1800
+ const networkId = this.safeString(network, 'code');
1801
+ const currencyCode = this.safeCurrencyCode(undefined, currency);
1802
+ const unifiedNetwork = this.networkIdToCode(networkId, currencyCode);
1803
+ return {
1804
+ 'address': this.safeString(depositAddress, 'address'),
1805
+ 'tag': this.safeString(depositAddress, 'tag'),
1806
+ 'currency': currencyCode,
1807
+ 'network': unifiedNetwork,
1808
+ 'info': depositAddress,
1809
+ };
1810
+ }
1811
+ parseTransactionStatus(status) {
1812
+ const statuses = {
1813
+ // BOTH
1814
+ 'SUBMITTING': 'pending',
1815
+ 'SUBMITTED': 'pending',
1816
+ 'REJECTED': 'failed',
1817
+ // DEPOSIT-SPECIFIC
1818
+ 'CANCELLED': 'canceled',
1819
+ 'ACCEPTED': 'ok',
1820
+ 'WARNING': 'pending',
1821
+ 'UNBLOCKED': 'pending',
1822
+ 'BLOCKED': 'pending',
1823
+ // WITHDRAWAL-SPECIFIC
1824
+ 'PROCESSING': 'pending',
1825
+ 'CANCELED': 'canceled',
1826
+ 'FAILED': 'failed',
1827
+ 'DONE': 'ok',
1828
+ };
1829
+ return this.safeString(statuses, status, status);
1830
+ }
1831
+ parseTransaction(transaction, currency = undefined, since = undefined, limit = undefined) {
1832
+ const cryptoDetails = this.safeDict(transaction, 'details_crypto');
1833
+ const address = this.safeString2(cryptoDetails, 'receiving_address', 'destination_address');
1834
+ const sn = this.safeString(transaction, 'sn');
1835
+ let type = 'withdrawal';
1836
+ if (sn !== undefined && sn[0] === 'D') {
1837
+ type = 'deposit';
1838
+ }
1839
+ const fee = this.safeString(transaction, 'fee', '0');
1840
+ const amount = this.safeString(transaction, 'amount');
1841
+ const currencySymbol = this.safeString(transaction, 'currency_symbol');
1842
+ let actualAmount = amount;
1843
+ const currencyCode = this.safeCurrencyCode(currencySymbol);
1844
+ const status = this.parseTransactionStatus(this.safeString(transaction, 'state'));
1845
+ const created_at = this.safeString(transaction, 'created_at');
1846
+ const timestamp = this.parseDate(created_at);
1847
+ const datetime = this.iso8601(timestamp);
1848
+ if (fee !== undefined && amount !== undefined) {
1849
+ // actualAmount = amount - fee;
1850
+ actualAmount = Precise["default"].stringSub(amount, fee);
1851
+ }
1852
+ const feeRate = Precise["default"].stringDiv(fee, actualAmount);
1853
+ const feeObj = {
1854
+ 'cost': this.parseNumber(fee),
1855
+ 'currency': currencyCode,
1856
+ 'rate': this.parseNumber(feeRate),
1857
+ };
1858
+ return {
1859
+ 'info': transaction,
1860
+ 'id': this.safeString(transaction, 'sn'),
1861
+ 'txid': this.safeString(cryptoDetails, 'transaction_id'),
1862
+ 'timestamp': timestamp,
1863
+ 'datetime': datetime,
1864
+ 'network': this.safeString(transaction, 'network_code'),
1865
+ 'address': address,
1866
+ 'addressTo': address,
1867
+ 'addressFrom': undefined,
1868
+ 'tag': this.safeString(transaction, 'destination_tag'),
1869
+ 'tagTo': this.safeString(transaction, 'destination_tag'),
1870
+ 'tagFrom': undefined,
1871
+ 'type': type,
1872
+ 'amount': this.parseNumber(amount),
1873
+ 'currency': currencyCode,
1874
+ 'status': status,
1875
+ 'updated': undefined,
1876
+ 'fee': feeObj,
1877
+ 'comment': undefined,
1878
+ 'internal': undefined,
1879
+ };
1880
+ }
1881
+ parseLedgerEntryType(type) {
1882
+ const types = {
1883
+ 'DEPOSITING': 'transaction',
1884
+ 'WITHDRAWING': 'transaction',
1885
+ 'TRADING': 'trade',
1886
+ 'INTERNAL_TRANSFERING': 'transfer',
1887
+ 'OTHERS': 'transaction',
1888
+ };
1889
+ return this.safeString(types, type, type);
1890
+ }
1891
+ parseLedgerEntry(item, currency = undefined) {
1892
+ // {
1893
+ // "uuid": "f8e9f2d6-3c1e-4f2d-8f8e-9f2d6c1e4f2d",
1894
+ // "amount": "0.0001",
1895
+ // "balance": "0.0002",
1896
+ // "created_at": "2021-07-01T12:00:00Z",
1897
+ // "currency_symbol": "btc",
1898
+ // "fee": "0.0001",
1899
+ // "locked": "0.0001",
1900
+ // "locked_amount": "0.0001",
1901
+ // "reason_type": "DEPOSITING"
1902
+ // }
1903
+ const id = this.safeString(item, 'uuid');
1904
+ const createdAt = this.safeString(item, 'created_at');
1905
+ const timestamp = this.parse8601(createdAt);
1906
+ const reasonType = this.safeString(item, 'reason_type');
1907
+ const type = this.parseLedgerEntryType(reasonType);
1908
+ const exchangeSymbol = this.safeString(item, 'currency_symbol');
1909
+ const currencySymbol = this.safeCurrencyCode(exchangeSymbol);
1910
+ let direction = 'in';
1911
+ const amount = this.safeNumber(item, 'amount');
1912
+ let realAmount = amount;
1913
+ const balance = this.safeNumber(item, 'balance');
1914
+ const fee = {
1915
+ 'cost': this.safeNumber(item, 'fee'),
1916
+ 'currency': currencySymbol,
1917
+ };
1918
+ if (amount < 0) {
1919
+ direction = 'out';
1920
+ realAmount = amount * -1;
1921
+ }
1922
+ return {
1923
+ 'id': id,
1924
+ 'info': item,
1925
+ 'timestamp': timestamp,
1926
+ 'datetime': this.iso8601(timestamp),
1927
+ 'direction': direction,
1928
+ 'account': undefined,
1929
+ 'referenceId': undefined,
1930
+ 'referenceAccount': undefined,
1931
+ 'type': type,
1932
+ 'currency': currencySymbol,
1933
+ 'amount': realAmount,
1934
+ 'before': balance - amount,
1935
+ 'after': balance,
1936
+ 'status': 'ok',
1937
+ 'fee': fee,
1938
+ };
1939
+ }
1940
+ sign(path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
1941
+ const version = api[0];
1942
+ let urlPath = api[1];
1943
+ let fullPath = '/rest/' + version + '/' + this.implodeParams(path, params);
1944
+ if (version === 'status') {
1945
+ fullPath = '/status';
1946
+ urlPath = 'status';
1947
+ }
1948
+ let url = this.urls['api'][urlPath] + fullPath;
1949
+ params = this.omit(params, this.extractParams(path));
1950
+ const timestamp = this.milliseconds();
1951
+ let query = '';
1952
+ let signatureQuery = '';
1953
+ if (method === 'GET') {
1954
+ const paramKeys = Object.keys(params);
1955
+ const paramKeysLength = paramKeys.length;
1956
+ if (paramKeysLength > 0) {
1957
+ query = this.urlencode(params);
1958
+ url += '?' + query;
1959
+ }
1960
+ for (let i = 0; i < paramKeys.length; i++) {
1961
+ const key = paramKeys[i];
1962
+ const value = this.safeString(params, key);
1963
+ if (value !== undefined) {
1964
+ signatureQuery += key + '=' + value;
1965
+ }
1966
+ if (i < paramKeysLength - 1) {
1967
+ signatureQuery += '&';
1968
+ }
1969
+ }
1970
+ }
1971
+ if (method === 'POST' || method === 'PUT') {
1972
+ body = this.json(params);
1973
+ }
1974
+ let bodyToSignature = '';
1975
+ if (body !== undefined) {
1976
+ bodyToSignature = body;
1977
+ }
1978
+ headers = {
1979
+ 'Content-Type': 'application/json',
1980
+ };
1981
+ if (urlPath === 'private') {
1982
+ this.checkRequiredCredentials();
1983
+ const preHash = this.numberToString(timestamp) + method + fullPath + signatureQuery + bodyToSignature;
1984
+ const signature = this.hmac(this.encode(preHash), this.encode(this.secret), sha256.sha256, 'hex');
1985
+ headers['X-FB-ACCESS-KEY'] = this.apiKey;
1986
+ headers['X-FB-ACCESS-TIMESTAMP'] = this.numberToString(timestamp);
1987
+ headers['X-FB-ACCESS-SIGNATURE'] = signature;
1988
+ }
1989
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1990
+ }
1991
+ handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1992
+ if (response === undefined) {
1993
+ return undefined;
1994
+ }
1995
+ const error = this.safeDict(response, 'error');
1996
+ const code = this.safeString(error, 'code');
1997
+ const details = this.safeList(error, 'details');
1998
+ const message = this.safeString(error, 'message');
1999
+ let detailsString = '';
2000
+ if (details) {
2001
+ for (let i = 0; i < details.length; i++) {
2002
+ detailsString = detailsString + details[i] + ' ';
2003
+ }
2004
+ }
2005
+ if (error !== undefined) {
2006
+ const feedback = this.id + ' ' + message + ' details: ' + detailsString;
2007
+ this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
2008
+ this.throwBroadlyMatchedException(this.exceptions['broad'], detailsString, feedback);
2009
+ this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
2010
+ throw new errors.ExchangeError(feedback);
2011
+ }
2012
+ return undefined;
2013
+ }
2014
+ }
2015
+
2016
+ module.exports = foxbit;