ccxt 4.1.53 → 4.1.55

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