ccxt 4.1.53 → 4.1.54

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 (118) hide show
  1. package/README.md +8 -7
  2. package/dist/ccxt.browser.js +2164 -620
  3. package/dist/ccxt.browser.min.js +10 -10
  4. package/dist/cjs/ccxt.js +4 -1
  5. package/dist/cjs/src/abstract/p2b.js +9 -0
  6. package/dist/cjs/src/base/Exchange.js +10 -6
  7. package/dist/cjs/src/bitget.js +670 -405
  8. package/dist/cjs/src/p2b.js +1246 -0
  9. package/js/ccxt.d.ts +5 -2
  10. package/js/ccxt.js +4 -2
  11. package/js/src/abstract/bitget.d.ts +495 -254
  12. package/js/src/abstract/p2b.d.ts +25 -0
  13. package/js/src/abstract/p2b.js +11 -0
  14. package/js/src/ace.d.ts +3 -3
  15. package/js/src/alpaca.d.ts +1 -1
  16. package/js/src/ascendex.d.ts +6 -6
  17. package/js/src/base/Exchange.d.ts +5 -5
  18. package/js/src/base/Exchange.js +10 -6
  19. package/js/src/base/types.d.ts +11 -8
  20. package/js/src/bigone.d.ts +3 -3
  21. package/js/src/binance.d.ts +11 -11
  22. package/js/src/bingx.d.ts +6 -6
  23. package/js/src/bitbank.d.ts +1 -1
  24. package/js/src/bitbns.d.ts +2 -2
  25. package/js/src/bitfinex.d.ts +4 -4
  26. package/js/src/bitfinex2.d.ts +4 -4
  27. package/js/src/bitflyer.d.ts +2 -2
  28. package/js/src/bitget.d.ts +5 -5
  29. package/js/src/bitget.js +670 -405
  30. package/js/src/bithumb.d.ts +2 -2
  31. package/js/src/bitmart.d.ts +3 -3
  32. package/js/src/bitmex.d.ts +6 -6
  33. package/js/src/bitopro.d.ts +4 -4
  34. package/js/src/bitpanda.d.ts +3 -3
  35. package/js/src/bitrue.d.ts +5 -5
  36. package/js/src/bitso.d.ts +3 -3
  37. package/js/src/bitstamp.d.ts +3 -3
  38. package/js/src/bittrex.d.ts +5 -5
  39. package/js/src/bitvavo.d.ts +3 -3
  40. package/js/src/blockchaincom.d.ts +2 -2
  41. package/js/src/btcalpha.d.ts +3 -3
  42. package/js/src/btcmarkets.d.ts +1 -1
  43. package/js/src/btcturk.d.ts +3 -3
  44. package/js/src/bybit.d.ts +6 -6
  45. package/js/src/cex.d.ts +2 -2
  46. package/js/src/coinbase.d.ts +5 -5
  47. package/js/src/coinbasepro.d.ts +2 -2
  48. package/js/src/coinex.d.ts +7 -7
  49. package/js/src/coinlist.d.ts +3 -3
  50. package/js/src/coinone.d.ts +2 -2
  51. package/js/src/coinsph.d.ts +2 -2
  52. package/js/src/coinspot.d.ts +2 -2
  53. package/js/src/cryptocom.d.ts +4 -4
  54. package/js/src/currencycom.d.ts +3 -3
  55. package/js/src/delta.d.ts +5 -5
  56. package/js/src/deribit.d.ts +4 -4
  57. package/js/src/digifinex.d.ts +6 -6
  58. package/js/src/exmo.d.ts +4 -4
  59. package/js/src/gate.d.ts +6 -6
  60. package/js/src/gemini.d.ts +2 -2
  61. package/js/src/hitbtc.d.ts +6 -6
  62. package/js/src/hollaex.d.ts +5 -5
  63. package/js/src/htx.d.ts +8 -8
  64. package/js/src/huobijp.d.ts +3 -3
  65. package/js/src/idex.d.ts +2 -2
  66. package/js/src/indodax.d.ts +2 -2
  67. package/js/src/kraken.d.ts +3 -3
  68. package/js/src/krakenfutures.d.ts +6 -6
  69. package/js/src/kucoin.d.ts +3 -3
  70. package/js/src/kucoinfutures.d.ts +2 -2
  71. package/js/src/kuna.d.ts +2 -2
  72. package/js/src/latoken.d.ts +2 -2
  73. package/js/src/lbank.d.ts +3 -3
  74. package/js/src/luno.d.ts +2 -2
  75. package/js/src/lykke.d.ts +2 -2
  76. package/js/src/mexc.d.ts +6 -6
  77. package/js/src/ndax.d.ts +1 -1
  78. package/js/src/novadax.d.ts +3 -3
  79. package/js/src/oceanex.d.ts +4 -4
  80. package/js/src/okcoin.d.ts +3 -3
  81. package/js/src/okx.d.ts +6 -6
  82. package/js/src/p2b.d.ts +34 -0
  83. package/js/src/p2b.js +1246 -0
  84. package/js/src/phemex.d.ts +4 -4
  85. package/js/src/poloniex.d.ts +5 -5
  86. package/js/src/poloniexfutures.d.ts +4 -4
  87. package/js/src/pro/binance.d.ts +4 -4
  88. package/js/src/pro/bitget.d.ts +3 -3
  89. package/js/src/pro/bitpanda.d.ts +3 -3
  90. package/js/src/pro/bybit.d.ts +4 -4
  91. package/js/src/pro/cex.d.ts +2 -2
  92. package/js/src/pro/coinbasepro.d.ts +4 -4
  93. package/js/src/pro/coinex.d.ts +2 -2
  94. package/js/src/pro/cryptocom.d.ts +3 -3
  95. package/js/src/pro/gate.d.ts +4 -4
  96. package/js/src/pro/hitbtc.d.ts +2 -2
  97. package/js/src/pro/htx.d.ts +2 -2
  98. package/js/src/pro/kraken.d.ts +1 -1
  99. package/js/src/pro/krakenfutures.d.ts +3 -3
  100. package/js/src/pro/kucoin.d.ts +2 -2
  101. package/js/src/pro/okx.d.ts +4 -4
  102. package/js/src/pro/poloniex.d.ts +2 -2
  103. package/js/src/pro/wazirx.d.ts +2 -2
  104. package/js/src/pro/woo.d.ts +2 -2
  105. package/js/src/probit.d.ts +4 -4
  106. package/js/src/tidex.d.ts +3 -3
  107. package/js/src/timex.d.ts +3 -3
  108. package/js/src/tokocrypto.d.ts +3 -3
  109. package/js/src/upbit.d.ts +4 -4
  110. package/js/src/wavesexchange.d.ts +4 -4
  111. package/js/src/wazirx.d.ts +3 -3
  112. package/js/src/whitebit.d.ts +5 -5
  113. package/js/src/woo.d.ts +4 -4
  114. package/js/src/yobit.d.ts +3 -3
  115. package/js/src/zaif.d.ts +1 -1
  116. package/js/src/zonda.d.ts +3 -3
  117. package/package.json +1 -1
  118. package/skip-tests.json +7 -0
package/js/src/p2b.js ADDED
@@ -0,0 +1,1246 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ // ---------------------------------------------------------------------------
8
+ import { Precise } from '../ccxt.js';
9
+ import Exchange from './abstract/p2b.js';
10
+ import { InsufficientFunds, AuthenticationError, BadRequest, ExchangeNotAvailable, ArgumentsRequired } from './base/errors.js';
11
+ import { TICK_SIZE } from './base/functions/number.js';
12
+ import { sha512 } from './static_dependencies/noble-hashes/sha512.js';
13
+ // ---------------------------------------------------------------------------
14
+ /**
15
+ * @class p2b
16
+ * @extends Exchange
17
+ */
18
+ export default class p2b extends Exchange {
19
+ describe() {
20
+ return this.deepExtend(super.describe(), {
21
+ 'id': 'p2b',
22
+ 'name': 'p2b',
23
+ 'countries': ['LT'],
24
+ 'rateLimit': 100,
25
+ 'version': 'v2',
26
+ 'has': {
27
+ 'CORS': undefined,
28
+ 'spot': true,
29
+ 'margin': false,
30
+ 'swap': false,
31
+ 'future': false,
32
+ 'option': false,
33
+ 'addMargin': false,
34
+ 'cancelAllOrders': false,
35
+ 'cancelOrder': true,
36
+ 'cancelOrders': false,
37
+ 'createDepositAddress': false,
38
+ 'createMarketOrder': false,
39
+ 'createOrder': true,
40
+ 'createOrders': false,
41
+ 'createPostOnlyOrder': false,
42
+ 'createReduceOnlyOrder': false,
43
+ 'createStopLimitOrder': false,
44
+ 'createStopMarketOrder': false,
45
+ 'createStopOrder': false,
46
+ 'fetchAccounts': false,
47
+ 'fetchBalance': true,
48
+ 'fetchBorrowInterest': false,
49
+ 'fetchBorrowRate': false,
50
+ 'fetchBorrowRateHistory': false,
51
+ 'fetchBorrowRates': false,
52
+ 'fetchBorrowRatesPerSymbol': false,
53
+ 'fetchClosedOrders': true,
54
+ 'fetchDeposit': false,
55
+ 'fetchDepositAddress': false,
56
+ 'fetchDepositAddresses': false,
57
+ 'fetchDepositAddressesByNetwork': false,
58
+ 'fetchDeposits': false,
59
+ 'fetchDepositsWithdrawals': false,
60
+ 'fetchFundingHistory': false,
61
+ 'fetchFundingRate': false,
62
+ 'fetchFundingRateHistory': false,
63
+ 'fetchFundingRates': false,
64
+ 'fetchIndexOHLCV': false,
65
+ 'fetchLedger': false,
66
+ 'fetchLedgerEntry': false,
67
+ 'fetchLeverageTiers': false,
68
+ 'fetchMarketLeverageTiers': false,
69
+ 'fetchMarkets': true,
70
+ 'fetchMarkOHLCV': false,
71
+ 'fetchMyTrades': true,
72
+ 'fetchOHLCV': true,
73
+ 'fetchOpenInterest': false,
74
+ 'fetchOpenInterestHistory': false,
75
+ 'fetchOpenOrders': true,
76
+ 'fetchOrderBook': true,
77
+ 'fetchOrderBooks': false,
78
+ 'fetchOrders': true,
79
+ 'fetchOrderTrades': true,
80
+ 'fetchPermissions': false,
81
+ 'fetchPosition': false,
82
+ 'fetchPositions': false,
83
+ 'fetchPositionsBySymbol': false,
84
+ 'fetchPositionsRisk': false,
85
+ 'fetchPremiumIndexOHLCV': false,
86
+ 'fetchTicker': true,
87
+ 'fetchTickers': true,
88
+ 'fetchTrades': true,
89
+ 'fetchTradingLimits': false,
90
+ 'fetchTransactionFee': false,
91
+ 'fetchTransactionFees': false,
92
+ 'fetchTransactions': false,
93
+ 'fetchTransfers': false,
94
+ 'fetchWithdrawAddresses': false,
95
+ 'fetchWithdrawal': false,
96
+ 'fetchWithdrawals': false,
97
+ 'reduceMargin': false,
98
+ 'setLeverage': false,
99
+ 'setMargin': false,
100
+ 'setMarginMode': false,
101
+ 'setPositionMode': false,
102
+ 'signIn': false,
103
+ 'transfer': false,
104
+ 'withdraw': false,
105
+ },
106
+ 'timeframes': {
107
+ '1m': '1m',
108
+ '1h': '1h',
109
+ '1d': '1d',
110
+ },
111
+ 'urls': {
112
+ 'extension': '.json',
113
+ 'referral': 'https://p2pb2b.com?referral=ee784c53',
114
+ 'logo': 'https://cdn.worldvectorlogo.com/logos/p2b-1.svg',
115
+ 'api': {
116
+ 'public': 'https://api.p2pb2b.com/api/v2/public',
117
+ 'private': 'https://api.p2pb2b.com/api/v2',
118
+ },
119
+ 'www': 'https://p2pb2b.com/',
120
+ 'doc': 'https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md',
121
+ 'fees': 'https://p2pb2b.com/fee-schedule/',
122
+ },
123
+ 'api': {
124
+ 'public': {
125
+ 'get': {
126
+ 'markets': 1,
127
+ 'market': 1,
128
+ 'tickers': 1,
129
+ 'ticker': 1,
130
+ 'book': 1,
131
+ 'history': 1,
132
+ 'depth/result': 1,
133
+ 'market/kline': 1,
134
+ },
135
+ },
136
+ 'private': {
137
+ 'post': {
138
+ 'account/balances': 1,
139
+ 'account/balance': 1,
140
+ 'order/new': 1,
141
+ 'order/cancel': 1,
142
+ 'orders': 1,
143
+ 'account/market_order_history': 1,
144
+ 'account/market_deal_history': 1,
145
+ 'account/order': 1,
146
+ 'account/order_history': 1,
147
+ 'account/executed_history': 1,
148
+ },
149
+ },
150
+ },
151
+ 'fees': {
152
+ 'trading': {
153
+ 'tierBased': true,
154
+ 'percentage': true,
155
+ 'taker': [
156
+ [this.parseNumber('0'), this.parseNumber('0.2')],
157
+ [this.parseNumber('1'), this.parseNumber('0.19')],
158
+ [this.parseNumber('5'), this.parseNumber('0.18')],
159
+ [this.parseNumber('10'), this.parseNumber('0.17')],
160
+ [this.parseNumber('25'), this.parseNumber('0.16')],
161
+ [this.parseNumber('75'), this.parseNumber('0.15')],
162
+ [this.parseNumber('100'), this.parseNumber('0.14')],
163
+ [this.parseNumber('150'), this.parseNumber('0.13')],
164
+ [this.parseNumber('300'), this.parseNumber('0.12')],
165
+ [this.parseNumber('450'), this.parseNumber('0.11')],
166
+ [this.parseNumber('500'), this.parseNumber('0.1')],
167
+ ],
168
+ 'maker': [
169
+ [this.parseNumber('0'), this.parseNumber('0.2')],
170
+ [this.parseNumber('1'), this.parseNumber('0.18')],
171
+ [this.parseNumber('5'), this.parseNumber('0.16')],
172
+ [this.parseNumber('10'), this.parseNumber('0.14')],
173
+ [this.parseNumber('25'), this.parseNumber('0.12')],
174
+ [this.parseNumber('75'), this.parseNumber('0.1')],
175
+ [this.parseNumber('100'), this.parseNumber('0.08')],
176
+ [this.parseNumber('150'), this.parseNumber('0.06')],
177
+ [this.parseNumber('300'), this.parseNumber('0.04')],
178
+ [this.parseNumber('450'), this.parseNumber('0.02')],
179
+ [this.parseNumber('500'), this.parseNumber('0.01')],
180
+ ],
181
+ },
182
+ },
183
+ 'commonCurrencies': {},
184
+ 'precisionMode': TICK_SIZE,
185
+ 'exceptions': {
186
+ '1001': AuthenticationError,
187
+ '1002': AuthenticationError,
188
+ '1003': AuthenticationError,
189
+ '1004': AuthenticationError,
190
+ '1005': AuthenticationError,
191
+ '1006': AuthenticationError,
192
+ '1007': AuthenticationError,
193
+ '1008': AuthenticationError,
194
+ '1009': AuthenticationError,
195
+ '1010': AuthenticationError,
196
+ '1011': AuthenticationError,
197
+ '1012': AuthenticationError,
198
+ '1013': AuthenticationError,
199
+ '1014': AuthenticationError,
200
+ '1015': AuthenticationError,
201
+ '1016': AuthenticationError,
202
+ '2010': BadRequest,
203
+ '2020': BadRequest,
204
+ '2021': BadRequest,
205
+ '2030': BadRequest,
206
+ '2040': InsufficientFunds,
207
+ '2050': BadRequest,
208
+ '2051': BadRequest,
209
+ '2052': BadRequest,
210
+ '2060': BadRequest,
211
+ '2061': BadRequest,
212
+ '2062': BadRequest,
213
+ '2070': BadRequest,
214
+ '3001': BadRequest,
215
+ '3020': BadRequest,
216
+ '3030': BadRequest,
217
+ '3040': BadRequest,
218
+ '3050': BadRequest,
219
+ '3060': BadRequest,
220
+ '3070': BadRequest,
221
+ '3080': BadRequest,
222
+ '3090': BadRequest,
223
+ '3100': BadRequest,
224
+ '3110': BadRequest,
225
+ '4001': ExchangeNotAvailable,
226
+ '6010': InsufficientFunds, // Balance not enough. Insufficient balance.
227
+ },
228
+ 'options': {},
229
+ });
230
+ }
231
+ async fetchMarkets(params = {}) {
232
+ /**
233
+ * @method
234
+ * @name p2b#fetchMarkets
235
+ * @description retrieves data on all markets for bigone
236
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#markets
237
+ * @param {object} [params] extra parameters specific to the exchange api endpoint
238
+ * @returns {object[]} an array of objects representing market data
239
+ */
240
+ const response = await this.publicGetMarkets(params);
241
+ //
242
+ // {
243
+ // "success": true,
244
+ // "errorCode": "",
245
+ // "message": "",
246
+ // "result": [
247
+ // {
248
+ // "name": "ETH_BTC",
249
+ // "stock": "ETH",
250
+ // "money": "BTC",
251
+ // "precision": {
252
+ // "money": "6",
253
+ // "stock": "4",
254
+ // "fee": "4"
255
+ // },
256
+ // "limits": {
257
+ // "min_amount": "0.001",
258
+ // "max_amount": "100000",
259
+ // "step_size": "0.0001",
260
+ // "min_price": "0.00001",
261
+ // "max_price": "922327",
262
+ // "tick_size": "0.00001",
263
+ // "min_total": "0.0001"
264
+ // }
265
+ // },
266
+ // ...
267
+ // ]
268
+ // }
269
+ //
270
+ const markets = this.safeValue(response, 'result', []);
271
+ const result = [];
272
+ for (let i = 0; i < markets.length; i++) {
273
+ const market = markets[i];
274
+ const marketId = this.safeString(market, 'name');
275
+ const baseId = this.safeValue(market, 'stock');
276
+ const quoteId = this.safeValue(market, 'money');
277
+ const base = this.safeCurrencyCode(baseId);
278
+ const quote = this.safeCurrencyCode(quoteId);
279
+ const precision = this.safeValue(market, 'precision');
280
+ const limits = this.safeValue(market, 'limits');
281
+ const maxAmount = this.safeString(limits, 'max_amount');
282
+ const maxPrice = this.safeString(limits, 'max_price');
283
+ const entry = this.safeMarketStructure({
284
+ 'id': marketId,
285
+ 'symbol': base + '/' + quote,
286
+ 'base': base,
287
+ 'quote': quote,
288
+ 'settle': undefined,
289
+ 'baseId': baseId,
290
+ 'quoteId': quoteId,
291
+ 'settleId': undefined,
292
+ 'type': 'spot',
293
+ 'spot': true,
294
+ 'margin': false,
295
+ 'swap': false,
296
+ 'future': false,
297
+ 'option': false,
298
+ 'active': true,
299
+ 'contract': false,
300
+ 'linear': undefined,
301
+ 'inverse': undefined,
302
+ 'contractSize': undefined,
303
+ 'expiry': undefined,
304
+ 'expiryDatetime': undefined,
305
+ 'strike': undefined,
306
+ 'optionType': undefined,
307
+ 'precision': {
308
+ 'amount': this.safeNumber(limits, 'step_size'),
309
+ 'price': this.safeNumber(limits, 'tick_size'),
310
+ 'base': this.parsePrecision(this.safeString(precision, 'stock')),
311
+ 'quote': this.parsePrecision(this.safeString(precision, 'money')),
312
+ },
313
+ 'limits': {
314
+ 'leverage': {
315
+ 'min': undefined,
316
+ 'max': undefined,
317
+ },
318
+ 'amount': {
319
+ 'min': this.safeNumber(limits, 'min_amount'),
320
+ 'max': Precise.stringEq(maxAmount, '0') ? undefined : this.parseNumber(maxAmount),
321
+ },
322
+ 'price': {
323
+ 'min': this.safeString(limits, 'min_price'),
324
+ 'max': Precise.stringEq(maxPrice, '0') ? undefined : this.parseNumber(maxPrice),
325
+ },
326
+ 'cost': {
327
+ 'min': undefined,
328
+ 'max': undefined,
329
+ },
330
+ },
331
+ 'created': undefined,
332
+ 'info': market,
333
+ });
334
+ result.push(entry);
335
+ }
336
+ return result;
337
+ }
338
+ async fetchTickers(symbols = undefined, params = {}) {
339
+ /**
340
+ * @method
341
+ * @name p2b#fetchTickers
342
+ * @description fetches price tickers for multiple markets, statistical calculations with the information calculated over the past 24 hours each market
343
+ * @see https://futures-docs.poloniex.com/#get-real-time-ticker-of-all-symbols
344
+ * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
345
+ * @param {object} [params] extra parameters specific to the p2b api endpoint
346
+ * @returns {object} a dictionary of [ticker structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#ticker-structure}
347
+ */
348
+ await this.loadMarkets();
349
+ const response = await this.publicGetTickers(params);
350
+ //
351
+ // {
352
+ // success: true,
353
+ // errorCode: '',
354
+ // message: '',
355
+ // result: {
356
+ // KNOLIX_BTC: {
357
+ // at: '1699252631',
358
+ // ticker: {
359
+ // bid: '0.0000332',
360
+ // ask: '0.0000333',
361
+ // low: '0.0000301',
362
+ // high: '0.0000338',
363
+ // last: '0.0000333',
364
+ // vol: '15.66',
365
+ // deal: '0.000501828',
366
+ // change: '10.63'
367
+ // }
368
+ // },
369
+ // ...
370
+ // },
371
+ // cache_time: '1699252631.103631',
372
+ // current_time: '1699252644.487566'
373
+ // }
374
+ //
375
+ const result = this.safeValue(response, 'result', {});
376
+ return this.parseTickers(result, symbols);
377
+ }
378
+ async fetchTicker(symbol, params = {}) {
379
+ /**
380
+ * @method
381
+ * @name p2b#fetchTicker
382
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
383
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#ticker
384
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
385
+ * @param {object} [params] extra parameters specific to the p2b api endpoint
386
+ * @returns {object} a [ticker structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#ticker-structure}
387
+ */
388
+ await this.loadMarkets();
389
+ const market = this.market(symbol);
390
+ const request = {
391
+ 'market': market['id'],
392
+ };
393
+ const response = await this.publicGetTicker(this.extend(request, params));
394
+ //
395
+ // {
396
+ // success: true,
397
+ // errorCode: '',
398
+ // message: '',
399
+ // result: {
400
+ // bid: '0.342',
401
+ // ask: '0.3421',
402
+ // open: '0.3317',
403
+ // high: '0.3499',
404
+ // low: '0.3311',
405
+ // last: '0.3421',
406
+ // volume: '17855383.1',
407
+ // deal: '6107478.3423',
408
+ // change: '3.13'
409
+ // },
410
+ // cache_time: '1699252953.832795',
411
+ // current_time: '1699252958.859391'
412
+ // }
413
+ //
414
+ const result = this.safeValue(response, 'result', {});
415
+ const timestamp = this.safeIntegerProduct(response, 'cache_time', 1000);
416
+ return this.extend({ 'timestamp': timestamp, 'datetime': this.iso8601(timestamp) }, this.parseTicker(result, market));
417
+ }
418
+ parseTicker(ticker, market = undefined) {
419
+ //
420
+ // parseTickers
421
+ //
422
+ // {
423
+ // at: '1699252631',
424
+ // ticker: {
425
+ // bid: '0.0000332',
426
+ // ask: '0.0000333',
427
+ // low: '0.0000301',
428
+ // high: '0.0000338',
429
+ // last: '0.0000333',
430
+ // vol: '15.66',
431
+ // deal: '0.000501828',
432
+ // change: '10.63'
433
+ // }
434
+ // }
435
+ //
436
+ // parseTicker
437
+ //
438
+ // {
439
+ // bid: '0.342',
440
+ // ask: '0.3421',
441
+ // open: '0.3317',
442
+ // high: '0.3499',
443
+ // low: '0.3311',
444
+ // last: '0.3421',
445
+ // volume: '17855383.1',
446
+ // deal: '6107478.3423',
447
+ // change: '3.13'
448
+ // }
449
+ //
450
+ const timestamp = this.safeIntegerProduct(ticker, 'at', 1000);
451
+ if ('ticker' in ticker) {
452
+ ticker = this.safeValue(ticker, 'ticker');
453
+ }
454
+ const last = this.safeString(ticker, 'last');
455
+ return this.safeTicker({
456
+ 'symbol': this.safeString(market, 'symbol'),
457
+ 'timestamp': timestamp,
458
+ 'datetime': this.iso8601(timestamp),
459
+ 'high': this.safeString(ticker, 'high'),
460
+ 'low': this.safeString(ticker, 'low'),
461
+ 'bid': this.safeString(ticker, 'bid'),
462
+ 'bidVolume': undefined,
463
+ 'ask': this.safeString(ticker, 'ask'),
464
+ 'askVolume': undefined,
465
+ 'vwap': undefined,
466
+ 'open': this.safeString(ticker, 'open'),
467
+ 'close': last,
468
+ 'last': last,
469
+ 'previousClose': undefined,
470
+ 'change': undefined,
471
+ 'percentage': this.safeString(ticker, 'change'),
472
+ 'average': undefined,
473
+ 'baseVolume': this.safeString2(ticker, 'vol', 'volume'),
474
+ 'quoteVolume': this.safeString(ticker, 'deal'),
475
+ 'info': ticker,
476
+ }, market);
477
+ }
478
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
479
+ /**
480
+ * @method
481
+ * @name p2bfutures#fetchOrderBook
482
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
483
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#depth-result
484
+ * @param {string} symbol unified symbol of the market to fetch the order book for
485
+ * @param {int} [limit] the maximum amount of order book entries to return
486
+ * @param {object} [params] extra parameters specific to the p2bfutures api endpoint
487
+ *
488
+ * EXCHANGE SPECIFIC PARAMETERS
489
+ * @param {string} [params.interval] 0 (default), 0.00000001, 0.0000001, 0.000001, 0.00001, 0.0001, 0.001, 0.01, 0.1, 1
490
+ * @returns {object} A dictionary of [order book structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure} indexed by market symbols
491
+ */
492
+ await this.loadMarkets();
493
+ const market = this.market(symbol);
494
+ const request = {
495
+ 'market': market['id'],
496
+ };
497
+ if (limit !== undefined) {
498
+ request['limit'] = limit;
499
+ }
500
+ const response = await this.publicGetDepthResult(this.extend(request, params));
501
+ //
502
+ // {
503
+ // "success": true,
504
+ // "errorCode": "",
505
+ // "message": "",
506
+ // "result": {
507
+ // "asks": [
508
+ // [
509
+ // "4.53", // Price
510
+ // "523.95" // Amount
511
+ // ],
512
+ // ...
513
+ // ],
514
+ // "bids": [
515
+ // [
516
+ // "4.51",
517
+ // "244.75"
518
+ // ],
519
+ // ...
520
+ // ]
521
+ // },
522
+ // "cache_time": 1698733470.469175,
523
+ // "current_time": 1698733470.469274
524
+ // }
525
+ //
526
+ const result = this.safeValue(response, 'result', {});
527
+ const timestamp = this.safeIntegerProduct(response, 'current_time', 1000);
528
+ return this.parseOrderBook(result, market['symbol'], timestamp, 'bids', 'asks', 0, 1);
529
+ }
530
+ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
531
+ /**
532
+ * @method
533
+ * @name p2b#fetchTrades
534
+ * @description get the list of most recent trades for a particular symbol
535
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#history
536
+ * @param {string} symbol unified symbol of the market to fetch trades for
537
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
538
+ * @param {int} [limit] 1-100, default=50
539
+ * @param {object} [params] extra parameters specific to the p2b api endpoint
540
+ *
541
+ * @param {int} params.lastId order id
542
+ * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#public-trades}
543
+ */
544
+ await this.loadMarkets();
545
+ const lastId = this.safeInteger(params, 'lastId');
546
+ if (lastId === undefined) {
547
+ throw new ArgumentsRequired(this.id + ' fetchTrades () requires an extra parameter params["lastId"]');
548
+ }
549
+ const market = this.market(symbol);
550
+ const request = {
551
+ 'market': market['id'],
552
+ 'lastId': lastId,
553
+ };
554
+ if (limit !== undefined) {
555
+ request['limit'] = limit;
556
+ }
557
+ const response = await this.publicGetHistory(this.extend(request, params));
558
+ //
559
+ // {
560
+ // success: true,
561
+ // errorCode: '',
562
+ // message: '',
563
+ // result: [
564
+ // {
565
+ // id: '7495738622',
566
+ // type: 'sell',
567
+ // time: '1699255565.445418',
568
+ // amount: '252.6',
569
+ // price: '0.3422'
570
+ // },
571
+ // ...
572
+ // ],
573
+ // cache_time: '1699255571.413633',
574
+ // current_time: '1699255571.413828'
575
+ // }
576
+ //
577
+ const result = this.safeValue(response, 'result', []);
578
+ return this.parseTrades(result, market, since, limit);
579
+ }
580
+ parseTrade(trade, market = undefined) {
581
+ //
582
+ // fetchTrades
583
+ //
584
+ // {
585
+ // id: '7495738622',
586
+ // type: 'sell',
587
+ // time: '1699255565.445418',
588
+ // amount: '252.6',
589
+ // price: '0.3422'
590
+ // }
591
+ //
592
+ // fetchMyTrades
593
+ //
594
+ // {
595
+ // "deal_id": 7450617292, // Deal id
596
+ // "deal_time": 1698506956.66224, // Deal execution time
597
+ // "deal_order_id": 171955225751, // Deal order id
598
+ // "opposite_order_id": 171955110512, // Opposite order id
599
+ // "side": "sell", // Deal side
600
+ // "price": "0.05231", // Deal price
601
+ // "amount": "0.002", // Deal amount
602
+ // "deal": "0.00010462", // Total (price * amount)
603
+ // "deal_fee": "0.000000188316", // Deal fee
604
+ // "role": "taker", // Role. Taker or maker
605
+ // "isSelfTrade": false // is self trade
606
+ // }
607
+ //
608
+ // fetchOrderTrades
609
+ //
610
+ // {
611
+ // "id": 7429883128, // Deal id
612
+ // "time": 1698237535.41196, // Deal execution time
613
+ // "fee": "0.01755848704", // Deal fee
614
+ // "price": "34293.92", // Deal price
615
+ // "amount": "0.00032", // Deal amount
616
+ // "dealOrderId": 171366551416, // Deal order id
617
+ // "role": 1, // Deal role (1 - maker, 2 - taker)
618
+ // "deal": "10.9740544" // Total (price * amount)
619
+ // }
620
+ //
621
+ const timestamp = this.safeIntegerProduct2(trade, 'time', 'deal_time', 1000);
622
+ let takerOrMaker = this.safeString(trade, 'role');
623
+ if (takerOrMaker === '1') {
624
+ takerOrMaker = 'maker';
625
+ }
626
+ else if (takerOrMaker === '2') {
627
+ takerOrMaker = 'taker';
628
+ }
629
+ return this.safeTrade({
630
+ 'info': trade,
631
+ 'id': this.safeString2(trade, 'id', 'deal_id'),
632
+ 'timestamp': timestamp,
633
+ 'datetime': this.iso8601(timestamp),
634
+ 'symbol': this.safeString(market, 'symbol'),
635
+ 'order': this.safeString2(trade, 'dealOrderId', 'deal_order_id'),
636
+ 'type': undefined,
637
+ 'side': this.safeString2(trade, 'type', 'side'),
638
+ 'takerOrMaker': takerOrMaker,
639
+ 'price': this.safeString(trade, 'price'),
640
+ 'amount': this.safeString(trade, 'amount'),
641
+ 'cost': this.safeString(trade, 'deal'),
642
+ 'fee': {
643
+ 'currency': market['quote'],
644
+ 'cost': this.safeString2(trade, 'fee', 'deal_fee'),
645
+ },
646
+ }, market);
647
+ }
648
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
649
+ /**
650
+ * @method
651
+ * @name poloniexfutures#fetchOHLCV
652
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
653
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#kline
654
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
655
+ * @param {string} timeframe 1m, 1h, or 1d
656
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
657
+ * @param {int} [limit] 1-500, default=50
658
+ * @param {object} [params] extra parameters specific to the poloniexfutures api endpoint
659
+ *
660
+ * @param {int} [params.offset] default=0, with this value the last candles are returned
661
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
662
+ */
663
+ await this.loadMarkets();
664
+ const market = this.market(symbol);
665
+ const request = {
666
+ 'market': market['id'],
667
+ 'interval': timeframe,
668
+ };
669
+ if (limit !== undefined) {
670
+ request['limit'] = limit;
671
+ }
672
+ const response = await this.publicGetMarketKline(this.extend(request, params));
673
+ //
674
+ // {
675
+ // success: true,
676
+ // errorCode: '',
677
+ // message: '',
678
+ // result: [
679
+ // [
680
+ // 1699253400, // Kline open time
681
+ // '0.3429', // Open price
682
+ // '0.3427', // Close price
683
+ // '0.3429', // Highest price
684
+ // '0.3427', // Lowest price
685
+ // '1900.4', // Volume for stock currency
686
+ // '651.46278', // Volume for money currency
687
+ // 'ADA_USDT' // Market name
688
+ // ],
689
+ // ...
690
+ // ],
691
+ // cache_time: '1699256375.030292',
692
+ // current_time: '1699256375.030494'
693
+ // }
694
+ //
695
+ const result = this.safeValue(response, 'result', []);
696
+ return this.parseOHLCVs(result, market, timeframe, since, limit);
697
+ }
698
+ parseOHLCV(ohlcv, market = undefined) {
699
+ //
700
+ // [
701
+ // 1699253400, // Kline open time
702
+ // '0.3429', // Open price
703
+ // '0.3427', // Close price
704
+ // '0.3429', // Highest price
705
+ // '0.3427', // Lowest price
706
+ // '1900.4', // Volume for stock currency
707
+ // '651.46278', // Volume for money currency
708
+ // 'ADA_USDT' // Market name
709
+ // ],
710
+ //
711
+ return [
712
+ this.safeIntegerProduct(ohlcv, 0, 1000),
713
+ this.safeNumber(ohlcv, 1),
714
+ this.safeNumber(ohlcv, 3),
715
+ this.safeNumber(ohlcv, 4),
716
+ this.safeNumber(ohlcv, 2),
717
+ this.safeNumber(ohlcv, 5),
718
+ ];
719
+ }
720
+ async fetchBalance(params = {}) {
721
+ /**
722
+ * @method
723
+ * @name p2b#fetchBalance
724
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
725
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#all-balances
726
+ * @param {object} [params] extra parameters specific to the p2b api endpoint
727
+ * @returns {object} a [balance structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#balance-structure}
728
+ */
729
+ await this.loadMarkets();
730
+ const response = await this.privatePostAccountBalances(params);
731
+ //
732
+ // {
733
+ // "success": true,
734
+ // "errorCode": "",
735
+ // "message": "",
736
+ // "result": {
737
+ // "USDT": {
738
+ // "available": "71.81328046",
739
+ // "freeze": "10.46103091"
740
+ // },
741
+ // "BTC": {
742
+ // "available": "0.00135674",
743
+ // "freeze": "0.00020003"
744
+ // }
745
+ // }
746
+ // }
747
+ //
748
+ const result = this.safeValue(response, 'result', {});
749
+ return this.parseBalance(result);
750
+ }
751
+ parseBalance(response) {
752
+ //
753
+ // {
754
+ // "USDT": {
755
+ // "available": "71.81328046",
756
+ // "freeze": "10.46103091"
757
+ // },
758
+ // "BTC": {
759
+ // "available": "0.00135674",
760
+ // "freeze": "0.00020003"
761
+ // }
762
+ // }
763
+ //
764
+ const result = {
765
+ 'info': response,
766
+ };
767
+ const keys = Object.keys(response);
768
+ for (let i = 0; i < keys.length; i++) {
769
+ const currencyId = keys[i];
770
+ const balance = response[currencyId];
771
+ const code = this.safeCurrencyCode(currencyId);
772
+ const used = this.safeString(balance, 'freeze');
773
+ const available = this.safeString(balance, 'available');
774
+ const account = {
775
+ 'free': available,
776
+ 'used': used,
777
+ };
778
+ result[code] = account;
779
+ }
780
+ return this.safeBalance(result);
781
+ }
782
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
783
+ /**
784
+ * @method
785
+ * @name p2b#createOrder
786
+ * @description create a trade order
787
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#create-order
788
+ * @param {string} symbol unified symbol of the market to create an order in
789
+ * @param {string} type must be 'limit'
790
+ * @param {string} side 'buy' or 'sell'
791
+ * @param {float} amount how much of currency you want to trade in units of base currency
792
+ * @param {float} price the price at which the order is to be fullfilled, in units of the quote currency
793
+ * @param {object} [params] extra parameters specific to the p2b api endpoint
794
+ * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
795
+ */
796
+ await this.loadMarkets();
797
+ if (type === 'market') {
798
+ throw new BadRequest(this.id + ' createOrder () can only accept orders with type "limit"');
799
+ }
800
+ const market = this.market(symbol);
801
+ const request = {
802
+ 'market': market['id'],
803
+ 'side': side,
804
+ 'amount': this.amountToPrecision(symbol, amount),
805
+ 'price': this.priceToPrecision(symbol, price),
806
+ };
807
+ const response = await this.privatePostOrderNew(this.extend(request, params));
808
+ //
809
+ // {
810
+ // "success": true,
811
+ // "errorCode": "",
812
+ // "message": "",
813
+ // "result": {
814
+ // "orderId": 171906478744, // Order id
815
+ // "market": "ETH_BTC", // Market name
816
+ // "price": "0.04348", // Price
817
+ // "side": "buy", // Side
818
+ // "type": "limit", // Order type
819
+ // "timestamp": 1698484861.746517, // Order creation time
820
+ // "dealMoney": "0", // Filled total
821
+ // "dealStock": "0", // Filled amount
822
+ // "amount": "0.0277", // Original amount
823
+ // "takerFee": "0.002", // taker fee
824
+ // "makerFee": "0.002", // maker fee
825
+ // "left": "0.0277", // Unfilled amount
826
+ // "dealFee": "0" // Filled fee
827
+ // }
828
+ // }
829
+ //
830
+ const result = this.safeValue(response, 'result');
831
+ return this.parseOrder(result, market);
832
+ }
833
+ async cancelOrder(id, symbol = undefined, params = {}) {
834
+ /**
835
+ * @method
836
+ * @name p2b#cancelOrder
837
+ * @description cancels an open order
838
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#cancel-order
839
+ * @param {string} id order id
840
+ * @param {string} symbol unified symbol of the market the order was made in
841
+ * @param {object} [params] extra parameters specific to the p2b api endpoint
842
+ * @returns {object} An [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
843
+ */
844
+ await this.loadMarkets();
845
+ this.checkRequiredArgument('cancelOrder', symbol, 'symbol');
846
+ const market = this.market(symbol);
847
+ const request = {
848
+ 'market': market['id'],
849
+ 'orderId': id,
850
+ };
851
+ const response = await this.privatePostOrderCancel(this.extend(request, params));
852
+ //
853
+ // {
854
+ // "success": true,
855
+ // "errorCode": "",
856
+ // "message": "",
857
+ // "result": {
858
+ // "orderId": 171906478744,
859
+ // "market": "ETH_BTC",
860
+ // "price": "0.04348",
861
+ // "side": "buy",
862
+ // "type": "limit",
863
+ // "timestamp": 1698484861.746517,
864
+ // "dealMoney": "0",
865
+ // "dealStock": "0",
866
+ // "amount": "0.0277",
867
+ // "takerFee": "0.002",
868
+ // "makerFee": "0.002",
869
+ // "left": "0.0277",
870
+ // "dealFee": "0"
871
+ // }
872
+ // }
873
+ //
874
+ const result = this.safeValue(response, 'result');
875
+ return this.parseOrder(result);
876
+ }
877
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
878
+ /**
879
+ * @method
880
+ * @name p2b#fetchOpenOrders
881
+ * @description fetch all unfilled currently open orders
882
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#open-orders
883
+ * @param {string} symbol unified market symbol of the market orders were made in
884
+ * @param {int} [since] the earliest time in ms to fetch orders for
885
+ * @param {int} [limit] the maximum number of order structures to retrieve
886
+ * @param {object} [params] extra parameters specific to the p2b api endpoint
887
+ *
888
+ * EXCHANGE SPECIFIC PARAMETERS
889
+ * @param {int} [params.offset] 0-10000, default=0
890
+ * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
891
+ */
892
+ if (symbol === undefined) {
893
+ throw new ArgumentsRequired(this.id + ' fetchOpenOrders () requires the symbol argument');
894
+ }
895
+ await this.loadMarkets();
896
+ const market = this.market(symbol);
897
+ const request = {
898
+ 'market': market['id'],
899
+ };
900
+ if (limit !== undefined) {
901
+ request['limit'] = limit;
902
+ }
903
+ const response = await this.privatePostOrders(this.extend(request, params));
904
+ //
905
+ // {
906
+ // "success": true,
907
+ // "errorCode": "",
908
+ // "message": "",
909
+ // "result": [
910
+ // {
911
+ // "orderId": 171913325964,
912
+ // "market": "ETH_BTC",
913
+ // "price": "0.06534",
914
+ // "side": "sell",
915
+ // "type": "limit",
916
+ // "timestamp": 1698487986.836821,
917
+ // "dealMoney": "0",
918
+ // "dealStock": "0",
919
+ // "amount": "0.0018",
920
+ // "takerFee": "0.0018",
921
+ // "makerFee": "0.0016",
922
+ // "left": "0.0018",
923
+ // "dealFee": "0"
924
+ // },
925
+ // ...
926
+ // ]
927
+ // }
928
+ //
929
+ const result = this.safeValue(response, 'result', []);
930
+ return this.parseOrders(result, market, since, limit);
931
+ }
932
+ async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
933
+ /**
934
+ * @method
935
+ * @name p2b#fetchOrderTrades
936
+ * @description fetch all the trades made from a single order
937
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#deals-by-order-id
938
+ * @param {string} id order id
939
+ * @param {string} symbol unified market symbol
940
+ * @param {int} [since] the earliest time in ms to fetch trades for
941
+ * @param {int} [limit] 1-100, default=50
942
+ * @param {object} [params] extra parameters specific to the p2b api endpoint
943
+ *
944
+ * EXCHANGE SPECIFIC PARAMETERS
945
+ * @param {int} [params.offset] 0-10000, default=0
946
+ * @returns {object[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#trade-structure}
947
+ */
948
+ await this.loadMarkets();
949
+ const market = this.safeMarket(symbol);
950
+ const request = {
951
+ 'orderId': id,
952
+ };
953
+ if (limit !== undefined) {
954
+ request['limit'] = limit;
955
+ }
956
+ const response = await this.privatePostAccountOrder(this.extend(request, params));
957
+ //
958
+ // {
959
+ // "success": true,
960
+ // "errorCode": "",
961
+ // "message": "",
962
+ // "result": {
963
+ // "offset": 0,
964
+ // "limit": 50,
965
+ // "records": [
966
+ // {
967
+ // "id": 7429883128, // Deal id
968
+ // "time": 1698237535.41196, // Deal execution time
969
+ // "fee": "0.01755848704", // Deal fee
970
+ // "price": "34293.92", // Deal price
971
+ // "amount": "0.00032", // Deal amount
972
+ // "dealOrderId": 171366551416, // Deal order id
973
+ // "role": 1, // Deal role (1 - maker, 2 - taker)
974
+ // "deal": "10.9740544" // Total (price * amount)
975
+ // }
976
+ // ]
977
+ // }
978
+ // }
979
+ //
980
+ const result = this.safeValue(response, 'result', {});
981
+ const records = this.safeValue(result, 'records', []);
982
+ return this.parseTrades(records, market, since, limit);
983
+ }
984
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
985
+ /**
986
+ * @method
987
+ * @name p2b#fetchMyTrades
988
+ * @description fetch all trades made by the user, only the transaction records in the past 3 month can be queried, the time between since and params["until"] cannot be longer than 24 hours
989
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#deals-history-by-market
990
+ * @param {string} symbol unified market symbol of the market orders were made in
991
+ * @param {int} [since] the earliest time in ms to fetch orders for, default = params["until"] - 86400000
992
+ * @param {int} [limit] 1-100, default=50
993
+ * @param {object} [params] extra parameters specific to the p2b api endpoint
994
+ * @param {int} [params.until] the latest time in ms to fetch orders for, default = current timestamp or since + 86400000
995
+ *
996
+ * EXCHANGE SPECIFIC PARAMETERS
997
+ * @param {int} [params.offset] 0-10000, default=0
998
+ * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#public-trades}
999
+ */
1000
+ await this.loadMarkets();
1001
+ let until = this.safeInteger(params, 'until');
1002
+ params = this.omit(params, 'until');
1003
+ this.checkRequiredArgument('fetchMyTrades', symbol, 'symbol');
1004
+ if (until === undefined) {
1005
+ if (since === undefined) {
1006
+ until = this.milliseconds();
1007
+ }
1008
+ else {
1009
+ until = since + 86400000;
1010
+ }
1011
+ }
1012
+ if (since === undefined) {
1013
+ since = until - 86400000;
1014
+ }
1015
+ if ((until - since) > 86400000) {
1016
+ throw new BadRequest(this.id + ' fetchMyTrades () the time between since and params["until"] cannot be greater than 24 hours');
1017
+ }
1018
+ const market = this.market(symbol);
1019
+ const request = {
1020
+ 'market': market['id'],
1021
+ 'startTime': this.parseToInt(since / 1000),
1022
+ 'endTime': this.parseToInt(until / 1000),
1023
+ };
1024
+ if (limit !== undefined) {
1025
+ request['limit'] = limit;
1026
+ }
1027
+ const response = await this.privatePostAccountMarketDealHistory(this.extend(request, params));
1028
+ //
1029
+ // {
1030
+ // "success": true,
1031
+ // "errorCode": "",
1032
+ // "message": "",
1033
+ // "result": {
1034
+ // "total": 2, // Total records in the queried range
1035
+ // "deals": [
1036
+ // {
1037
+ // "deal_id": 7450617292, // Deal id
1038
+ // "deal_time": 1698506956.66224, // Deal execution time
1039
+ // "deal_order_id": 171955225751, // Deal order id
1040
+ // "opposite_order_id": 171955110512, // Opposite order id
1041
+ // "side": "sell", // Deal side
1042
+ // "price": "0.05231", // Deal price
1043
+ // "amount": "0.002", // Deal amount
1044
+ // "deal": "0.00010462", // Total (price * amount)
1045
+ // "deal_fee": "0.000000188316", // Deal fee
1046
+ // "role": "taker", // Role. Taker or maker
1047
+ // "isSelfTrade": false // is self trade
1048
+ // },
1049
+ // ...
1050
+ // ]
1051
+ // }
1052
+ // }
1053
+ //
1054
+ const result = this.safeValue(response, 'result', {});
1055
+ const deals = this.safeValue(result, 'deals', []);
1056
+ return this.parseTrades(deals, market, since, limit);
1057
+ }
1058
+ async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1059
+ /**
1060
+ * @method
1061
+ * @name p2b#fetchClosedOrders
1062
+ * @description fetches information on multiple closed orders made by the user, the time between since and params["untnil"] cannot be longer than 24 hours
1063
+ * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#orders-history-by-market
1064
+ * @param {string} symbol unified market symbol of the market orders were made in
1065
+ * @param {int} [since] the earliest time in ms to fetch orders for, default = params["until"] - 86400000
1066
+ * @param {int} [limit] 1-100, default=50
1067
+ * @param {object} [params] extra parameters specific to the p2b api endpoint
1068
+ * @param {int} [params.until] the latest time in ms to fetch orders for, default = current timestamp or since + 86400000
1069
+ *
1070
+ * EXCHANGE SPECIFIC PARAMETERS
1071
+ * @param {int} [params.offset] 0-10000, default=0
1072
+ * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1073
+ */
1074
+ await this.loadMarkets();
1075
+ let until = this.safeInteger(params, 'until');
1076
+ params = this.omit(params, 'until');
1077
+ let market = undefined;
1078
+ if (symbol !== undefined) {
1079
+ market = this.market(symbol);
1080
+ }
1081
+ if (until === undefined) {
1082
+ if (since === undefined) {
1083
+ until = this.milliseconds();
1084
+ }
1085
+ else {
1086
+ until = since + 86400000;
1087
+ }
1088
+ }
1089
+ if (since === undefined) {
1090
+ since = until - 86400000;
1091
+ }
1092
+ if ((until - since) > 86400000) {
1093
+ throw new BadRequest(this.id + ' fetchClosedOrders () the time between since and params["until"] cannot be greater than 24 hours');
1094
+ }
1095
+ const request = {
1096
+ 'startTime': this.parseToInt(since / 1000),
1097
+ 'endTime': this.parseToInt(until / 1000),
1098
+ };
1099
+ if (market !== undefined) {
1100
+ request['market'] = market['id'];
1101
+ }
1102
+ if (limit !== undefined) {
1103
+ request['limit'] = limit;
1104
+ }
1105
+ const response = await this.privatePostAccountOrderHistory(this.extend(request, params));
1106
+ //
1107
+ // {
1108
+ // "success": true,
1109
+ // "errorCode": "",
1110
+ // "message": "",
1111
+ // "result": {
1112
+ // "LTC_USDT": [
1113
+ // {
1114
+ // "id": 173985944395,
1115
+ // "amount": "0.1",
1116
+ // "price": "73",
1117
+ // "type": "limit",
1118
+ // "side": "sell",
1119
+ // "ctime": 1699436194.390845,
1120
+ // "ftime": 1699436194.390847,
1121
+ // "market": "LTC_USDT",
1122
+ // "takerFee": "0.002",
1123
+ // "makerFee": "0.002",
1124
+ // "dealFee": "0.01474",
1125
+ // "dealStock": "0.1",
1126
+ // "dealMoney": "7.37"
1127
+ // }
1128
+ // ]
1129
+ // }
1130
+ // }
1131
+ //
1132
+ const result = this.safeValue(response, 'result');
1133
+ let orders = [];
1134
+ const keys = Object.keys(result);
1135
+ for (let i = 0; i < keys.length; i++) {
1136
+ const marketId = keys[i];
1137
+ const marketOrders = result[marketId];
1138
+ const parsedOrders = this.parseOrders(marketOrders, market, since, limit);
1139
+ orders = this.arrayConcat(orders, parsedOrders);
1140
+ }
1141
+ return orders;
1142
+ }
1143
+ parseOrder(order, market = undefined) {
1144
+ //
1145
+ // cancelOrder, fetchOpenOrders, createOrder
1146
+ //
1147
+ // {
1148
+ // "orderId": 171906478744,
1149
+ // "market": "ETH_BTC",
1150
+ // "price": "0.04348",
1151
+ // "side": "buy",
1152
+ // "type": "limit",
1153
+ // "timestamp": 1698484861.746517,
1154
+ // "dealMoney": "0",
1155
+ // "dealStock": "0",
1156
+ // "amount": "0.0277",
1157
+ // "takerFee": "0.002",
1158
+ // "makerFee": "0.002",
1159
+ // "left": "0.0277",
1160
+ // "dealFee": "0"
1161
+ // }
1162
+ //
1163
+ // fetchClosedOrders
1164
+ //
1165
+ // {
1166
+ // "id": 171366547790, // Order id
1167
+ // "amount": "0.00032", // Original amount
1168
+ // "price": "34293.92", // Order price
1169
+ // "type": "limit", // Order type
1170
+ // "side": "sell", // Order side
1171
+ // "ctime": 1698237533.497241, // Order creation time
1172
+ // "ftime": 1698237535.41196, // Order fill time
1173
+ // "market": "BTC_USDT", // Market name
1174
+ // "takerFee": "0.0018", // Taker fee
1175
+ // "makerFee": "0.0016", // Market fee
1176
+ // "dealFee": "0.01755848704", // Deal fee
1177
+ // "dealStock": "0.00032", // Filled amount
1178
+ // "dealMoney": "10.9740544" // Filled total
1179
+ // }
1180
+ //
1181
+ const timestamp = this.safeIntegerProduct2(order, 'timestamp', 'ctime', 1000);
1182
+ const marketId = this.safeString(order, 'market');
1183
+ market = this.safeMarket(marketId, market);
1184
+ return this.safeOrder({
1185
+ 'info': order,
1186
+ 'id': this.safeString2(order, 'id', 'orderId'),
1187
+ 'clientOrderId': undefined,
1188
+ 'timestamp': timestamp,
1189
+ 'datetime': this.iso8601(timestamp),
1190
+ 'lastTradeTimestamp': undefined,
1191
+ 'symbol': market['symbol'],
1192
+ 'type': this.safeString(order, 'type'),
1193
+ 'timeInForce': undefined,
1194
+ 'postOnly': undefined,
1195
+ 'side': this.safeString(order, 'side'),
1196
+ 'price': this.safeString(order, 'price'),
1197
+ 'stopPrice': undefined,
1198
+ 'amount': this.safeString(order, 'amount'),
1199
+ 'cost': undefined,
1200
+ 'average': undefined,
1201
+ 'filled': this.safeString(order, 'dealStock'),
1202
+ 'remaining': this.safeString(order, 'left'),
1203
+ 'status': undefined,
1204
+ 'fee': {
1205
+ 'currency': market['quote'],
1206
+ 'cost': this.safeString(order, 'dealFee'),
1207
+ },
1208
+ 'trades': undefined,
1209
+ }, market);
1210
+ }
1211
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1212
+ let url = this.urls['api'][api] + '/' + this.implodeParams(path, params);
1213
+ params = this.omit(params, this.extractParams(path));
1214
+ if (method === 'GET') {
1215
+ if (Object.keys(params).length) {
1216
+ url += '?' + this.urlencode(params);
1217
+ }
1218
+ }
1219
+ if (api === 'private') {
1220
+ params['request'] = '/api/v2/' + path;
1221
+ params['nonce'] = this.nonce().toString();
1222
+ const payload = this.stringToBase64(this.json(params)); // Body json encoded in base64
1223
+ headers = {
1224
+ 'Content-Type': 'application/json',
1225
+ 'X-TXC-APIKEY': this.apiKey,
1226
+ 'X-TXC-PAYLOAD': payload,
1227
+ 'X-TXC-SIGNATURE': this.hmac(this.encode(payload), this.encode(this.secret), sha512),
1228
+ };
1229
+ body = this.json(params);
1230
+ }
1231
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1232
+ }
1233
+ handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1234
+ if (response === undefined) {
1235
+ return undefined;
1236
+ }
1237
+ if (code === 400) {
1238
+ const error = this.safeValue(response, 'error');
1239
+ const errorCode = this.safeString(error, 'code');
1240
+ const feedback = this.id + ' ' + this.json(response);
1241
+ this.throwExactlyMatchedException(this.exceptions, errorCode, feedback);
1242
+ // fallback to default error handler
1243
+ }
1244
+ return undefined;
1245
+ }
1246
+ }