ccxt 4.3.5 → 4.3.7

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 (211) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/ccxt.js +1 -1
  3. package/dist/cjs/src/ace.js +5 -0
  4. package/dist/cjs/src/alpaca.js +6 -0
  5. package/dist/cjs/src/base/Exchange.js +37 -0
  6. package/dist/cjs/src/binance.js +4 -0
  7. package/dist/cjs/src/bingx.js +47 -0
  8. package/dist/cjs/src/bitbank.js +3 -0
  9. package/dist/cjs/src/bitget.js +74 -1
  10. package/dist/cjs/src/bithumb.js +4 -0
  11. package/dist/cjs/src/bitmex.js +26 -0
  12. package/dist/cjs/src/bitopro.js +5 -0
  13. package/dist/cjs/src/bitso.js +3 -0
  14. package/dist/cjs/src/bitstamp.js +3 -0
  15. package/dist/cjs/src/bitteam.js +4 -0
  16. package/dist/cjs/src/bitvavo.js +3 -0
  17. package/dist/cjs/src/bl3p.js +3 -0
  18. package/dist/cjs/src/btcalpha.js +3 -0
  19. package/dist/cjs/src/btcbox.js +3 -0
  20. package/dist/cjs/src/btcmarkets.js +3 -0
  21. package/dist/cjs/src/btcturk.js +3 -0
  22. package/dist/cjs/src/bybit.js +209 -12
  23. package/dist/cjs/src/cex.js +6 -0
  24. package/dist/cjs/src/coinbase.js +100 -21
  25. package/dist/cjs/src/coinbaseinternational.js +2 -0
  26. package/dist/cjs/src/coinbasepro.js +6 -0
  27. package/dist/cjs/src/coincheck.js +3 -0
  28. package/dist/cjs/src/coinex.js +180 -75
  29. package/dist/cjs/src/coinlist.js +4 -0
  30. package/dist/cjs/src/coinmate.js +3 -0
  31. package/dist/cjs/src/coinone.js +3 -0
  32. package/dist/cjs/src/coinsph.js +4 -0
  33. package/dist/cjs/src/coinspot.js +3 -0
  34. package/dist/cjs/src/cryptocom.js +34 -0
  35. package/dist/cjs/src/exmo.js +5 -0
  36. package/dist/cjs/src/gate.js +124 -22
  37. package/dist/cjs/src/hitbtc.js +4 -3
  38. package/dist/cjs/src/htx.js +30 -0
  39. package/dist/cjs/src/hyperliquid.js +40 -0
  40. package/dist/cjs/src/idex.js +3 -0
  41. package/dist/cjs/src/independentreserve.js +3 -0
  42. package/dist/cjs/src/indodax.js +3 -0
  43. package/dist/cjs/src/kraken.js +30 -0
  44. package/dist/cjs/src/krakenfutures.js +28 -0
  45. package/dist/cjs/src/kucoin.js +2 -0
  46. package/dist/cjs/src/kucoinfutures.js +4 -2
  47. package/dist/cjs/src/latoken.js +6 -0
  48. package/dist/cjs/src/luno.js +3 -0
  49. package/dist/cjs/src/lykke.js +5 -0
  50. package/dist/cjs/src/mercado.js +3 -0
  51. package/dist/cjs/src/mexc.js +111 -0
  52. package/dist/cjs/src/ndax.js +4 -0
  53. package/dist/cjs/src/novadax.js +4 -0
  54. package/dist/cjs/src/okx.js +196 -0
  55. package/dist/cjs/src/onetrading.js +3 -0
  56. package/dist/cjs/src/p2b.js +3 -0
  57. package/dist/cjs/src/pro/bitget.js +1 -1
  58. package/dist/cjs/src/pro/bybit.js +1 -1
  59. package/dist/cjs/src/pro/coinbase.js +30 -29
  60. package/dist/cjs/src/probit.js +3 -0
  61. package/dist/cjs/src/timex.js +3 -0
  62. package/dist/cjs/src/tradeogre.js +3 -0
  63. package/dist/cjs/src/wavesexchange.js +3 -0
  64. package/dist/cjs/src/wazirx.js +3 -0
  65. package/dist/cjs/src/whitebit.js +42 -0
  66. package/dist/cjs/src/woo.js +31 -0
  67. package/dist/cjs/src/yobit.js +3 -0
  68. package/js/ccxt.d.ts +1 -1
  69. package/js/ccxt.js +1 -1
  70. package/js/src/abstract/binance.d.ts +1 -0
  71. package/js/src/abstract/binancecoinm.d.ts +1 -0
  72. package/js/src/abstract/binanceus.d.ts +1 -0
  73. package/js/src/abstract/binanceusdm.d.ts +1 -0
  74. package/js/src/abstract/bingx.d.ts +1 -0
  75. package/js/src/abstract/coinbase.d.ts +5 -0
  76. package/js/src/abstract/woo.d.ts +1 -0
  77. package/js/src/ace.js +5 -0
  78. package/js/src/alpaca.js +6 -0
  79. package/js/src/ascendex.d.ts +2 -2
  80. package/js/src/base/Exchange.d.ts +5 -0
  81. package/js/src/base/Exchange.js +37 -0
  82. package/js/src/bigone.d.ts +1 -1
  83. package/js/src/binance.d.ts +3 -3
  84. package/js/src/binance.js +4 -0
  85. package/js/src/bingx.d.ts +2 -1
  86. package/js/src/bingx.js +47 -0
  87. package/js/src/bitbank.d.ts +1 -1
  88. package/js/src/bitbank.js +3 -0
  89. package/js/src/bitfinex.d.ts +1 -1
  90. package/js/src/bitfinex2.d.ts +1 -1
  91. package/js/src/bitflyer.d.ts +1 -1
  92. package/js/src/bitget.d.ts +4 -3
  93. package/js/src/bitget.js +74 -1
  94. package/js/src/bithumb.d.ts +1 -1
  95. package/js/src/bithumb.js +4 -0
  96. package/js/src/bitmart.d.ts +1 -1
  97. package/js/src/bitmex.d.ts +2 -1
  98. package/js/src/bitmex.js +26 -0
  99. package/js/src/bitopro.d.ts +1 -1
  100. package/js/src/bitopro.js +5 -0
  101. package/js/src/bitrue.d.ts +1 -1
  102. package/js/src/bitso.d.ts +1 -1
  103. package/js/src/bitso.js +3 -0
  104. package/js/src/bitstamp.d.ts +1 -1
  105. package/js/src/bitstamp.js +3 -0
  106. package/js/src/bitteam.js +4 -0
  107. package/js/src/bitvavo.d.ts +1 -1
  108. package/js/src/bitvavo.js +3 -0
  109. package/js/src/bl3p.js +3 -0
  110. package/js/src/blockchaincom.d.ts +1 -1
  111. package/js/src/btcalpha.js +3 -0
  112. package/js/src/btcbox.js +3 -0
  113. package/js/src/btcmarkets.d.ts +1 -1
  114. package/js/src/btcmarkets.js +3 -0
  115. package/js/src/btcturk.js +3 -0
  116. package/js/src/bybit.d.ts +8 -6
  117. package/js/src/bybit.js +209 -12
  118. package/js/src/cex.js +6 -0
  119. package/js/src/coinbase.d.ts +1 -1
  120. package/js/src/coinbase.js +100 -21
  121. package/js/src/coinbaseinternational.d.ts +1 -1
  122. package/js/src/coinbaseinternational.js +2 -0
  123. package/js/src/coinbasepro.d.ts +1 -1
  124. package/js/src/coinbasepro.js +6 -0
  125. package/js/src/coincheck.js +3 -0
  126. package/js/src/coinex.d.ts +8 -7
  127. package/js/src/coinex.js +180 -75
  128. package/js/src/coinlist.d.ts +1 -1
  129. package/js/src/coinlist.js +4 -0
  130. package/js/src/coinmate.d.ts +1 -1
  131. package/js/src/coinmate.js +3 -0
  132. package/js/src/coinone.js +3 -0
  133. package/js/src/coinsph.d.ts +1 -1
  134. package/js/src/coinsph.js +4 -0
  135. package/js/src/coinspot.js +3 -0
  136. package/js/src/cryptocom.d.ts +3 -2
  137. package/js/src/cryptocom.js +34 -0
  138. package/js/src/delta.d.ts +2 -2
  139. package/js/src/deribit.d.ts +1 -1
  140. package/js/src/digifinex.d.ts +3 -3
  141. package/js/src/exmo.d.ts +3 -3
  142. package/js/src/exmo.js +5 -0
  143. package/js/src/gate.d.ts +8 -7
  144. package/js/src/gate.js +124 -22
  145. package/js/src/gemini.d.ts +1 -1
  146. package/js/src/hitbtc.d.ts +3 -3
  147. package/js/src/hitbtc.js +4 -3
  148. package/js/src/hollaex.d.ts +1 -1
  149. package/js/src/htx.d.ts +2 -1
  150. package/js/src/htx.js +30 -0
  151. package/js/src/huobijp.d.ts +1 -1
  152. package/js/src/hyperliquid.d.ts +3 -2
  153. package/js/src/hyperliquid.js +40 -0
  154. package/js/src/idex.d.ts +1 -1
  155. package/js/src/idex.js +3 -0
  156. package/js/src/independentreserve.js +3 -0
  157. package/js/src/indodax.d.ts +1 -1
  158. package/js/src/indodax.js +3 -0
  159. package/js/src/kraken.d.ts +2 -1
  160. package/js/src/kraken.js +30 -0
  161. package/js/src/krakenfutures.d.ts +1 -0
  162. package/js/src/krakenfutures.js +28 -0
  163. package/js/src/kucoin.d.ts +1 -1
  164. package/js/src/kucoin.js +2 -0
  165. package/js/src/kucoinfutures.d.ts +1 -1
  166. package/js/src/kucoinfutures.js +4 -2
  167. package/js/src/kuna.d.ts +1 -1
  168. package/js/src/latoken.js +6 -0
  169. package/js/src/lbank.d.ts +1 -1
  170. package/js/src/luno.js +3 -0
  171. package/js/src/lykke.d.ts +1 -1
  172. package/js/src/lykke.js +5 -0
  173. package/js/src/mercado.d.ts +1 -1
  174. package/js/src/mercado.js +3 -0
  175. package/js/src/mexc.d.ts +4 -3
  176. package/js/src/mexc.js +111 -0
  177. package/js/src/ndax.d.ts +1 -1
  178. package/js/src/ndax.js +4 -0
  179. package/js/src/novadax.d.ts +1 -1
  180. package/js/src/novadax.js +4 -0
  181. package/js/src/okcoin.d.ts +1 -1
  182. package/js/src/okx.d.ts +11 -8
  183. package/js/src/okx.js +196 -0
  184. package/js/src/onetrading.d.ts +1 -1
  185. package/js/src/onetrading.js +3 -0
  186. package/js/src/p2b.js +3 -0
  187. package/js/src/phemex.d.ts +1 -1
  188. package/js/src/poloniex.d.ts +1 -1
  189. package/js/src/pro/bitget.d.ts +1 -1
  190. package/js/src/pro/bitget.js +1 -1
  191. package/js/src/pro/bybit.js +1 -1
  192. package/js/src/pro/coinbase.d.ts +2 -2
  193. package/js/src/pro/coinbase.js +30 -29
  194. package/js/src/probit.d.ts +1 -1
  195. package/js/src/probit.js +3 -0
  196. package/js/src/timex.js +3 -0
  197. package/js/src/tokocrypto.d.ts +1 -1
  198. package/js/src/tradeogre.js +3 -0
  199. package/js/src/upbit.d.ts +1 -1
  200. package/js/src/wavesexchange.d.ts +1 -1
  201. package/js/src/wavesexchange.js +3 -0
  202. package/js/src/wazirx.js +3 -0
  203. package/js/src/whitebit.d.ts +2 -1
  204. package/js/src/whitebit.js +42 -0
  205. package/js/src/woo.d.ts +3 -2
  206. package/js/src/woo.js +31 -0
  207. package/js/src/yobit.d.ts +1 -1
  208. package/js/src/yobit.js +3 -0
  209. package/js/src/zaif.d.ts +1 -1
  210. package/js/src/zonda.d.ts +1 -1
  211. package/package.json +1 -1
@@ -90,8 +90,10 @@ class mexc extends mexc$1 {
90
90
  'fetchOrders': true,
91
91
  'fetchOrderTrades': true,
92
92
  'fetchPosition': true,
93
+ 'fetchPositionHistory': 'emulated',
93
94
  'fetchPositionMode': true,
94
95
  'fetchPositions': true,
96
+ 'fetchPositionsHistory': true,
95
97
  'fetchPositionsRisk': undefined,
96
98
  'fetchPremiumIndexOHLCV': false,
97
99
  'fetchStatus': true,
@@ -4863,6 +4865,8 @@ class mexc extends mexc$1 {
4863
4865
  return this.parsePositions(data, symbols);
4864
4866
  }
4865
4867
  parsePosition(position, market = undefined) {
4868
+ //
4869
+ // fetchPositions
4866
4870
  //
4867
4871
  // {
4868
4872
  // "positionId": 1394650,
@@ -4887,6 +4891,40 @@ class mexc extends mexc$1 {
4887
4891
  // "autoAddIm": false
4888
4892
  // }
4889
4893
  //
4894
+ // fetchPositionsHistory
4895
+ //
4896
+ // {
4897
+ // positionId: '390281084',
4898
+ // symbol: 'RVN_USDT',
4899
+ // positionType: '1',
4900
+ // openType: '2',
4901
+ // state: '3',
4902
+ // holdVol: '0',
4903
+ // frozenVol: '0',
4904
+ // closeVol: '1141',
4905
+ // holdAvgPrice: '0.03491',
4906
+ // holdAvgPriceFullyScale: '0.03491',
4907
+ // openAvgPrice: '0.03491',
4908
+ // openAvgPriceFullyScale: '0.03491',
4909
+ // closeAvgPrice: '0.03494',
4910
+ // liquidatePrice: '0.03433',
4911
+ // oim: '0',
4912
+ // im: '0',
4913
+ // holdFee: '0',
4914
+ // realised: '0.1829',
4915
+ // leverage: '50',
4916
+ // createTime: '1711512408000',
4917
+ // updateTime: '1711512553000',
4918
+ // autoAddIm: false,
4919
+ // version: '4',
4920
+ // profitRatio: '0.0227',
4921
+ // newOpenAvgPrice: '0.03491',
4922
+ // newCloseAvgPrice: '0.03494',
4923
+ // closeProfitLoss: '0.3423',
4924
+ // fee: '0.1593977',
4925
+ // positionShowStatus: 'CLOSED'
4926
+ // }
4927
+ //
4890
4928
  market = this.safeMarket(this.safeString(position, 'symbol'), market);
4891
4929
  const symbol = market['symbol'];
4892
4930
  const contracts = this.safeString(position, 'holdVol');
@@ -5524,6 +5562,79 @@ class mexc extends mexc$1 {
5524
5562
  }
5525
5563
  return [marginMode, params];
5526
5564
  }
5565
+ async fetchPositionsHistory(symbols = undefined, since = undefined, limit = undefined, params = {}) {
5566
+ /**
5567
+ * @method
5568
+ * @name mexc#fetchPositionsHistory
5569
+ * @description fetches historical positions
5570
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-user-s-history-position-information
5571
+ * @param {string[]} [symbols] unified contract symbols
5572
+ * @param {int} [since] not used by mexc fetchPositionsHistory
5573
+ * @param {int} [limit] the maximum amount of candles to fetch, default=1000
5574
+ * @param {object} params extra parameters specific to the exchange api endpoint
5575
+ *
5576
+ * EXCHANGE SPECIFIC PARAMETERS
5577
+ * @param {int} type position type,1: long, 2: short
5578
+ * @param {int} page_num current page number, default is 1
5579
+ * @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
5580
+ */
5581
+ await this.loadMarkets();
5582
+ const request = {};
5583
+ if (symbols !== undefined) {
5584
+ const symbolsLength = symbols.length;
5585
+ if (symbolsLength === 1) {
5586
+ const market = this.market(symbols[0]);
5587
+ request['symbol'] = market['id'];
5588
+ }
5589
+ }
5590
+ if (limit !== undefined) {
5591
+ request['page_size'] = limit;
5592
+ }
5593
+ const response = await this.contractPrivateGetPositionListHistoryPositions(this.extend(request, params));
5594
+ //
5595
+ // {
5596
+ // success: true,
5597
+ // code: '0',
5598
+ // data: [
5599
+ // {
5600
+ // positionId: '390281084',
5601
+ // symbol: 'RVN_USDT',
5602
+ // positionType: '1',
5603
+ // openType: '2',
5604
+ // state: '3',
5605
+ // holdVol: '0',
5606
+ // frozenVol: '0',
5607
+ // closeVol: '1141',
5608
+ // holdAvgPrice: '0.03491',
5609
+ // holdAvgPriceFullyScale: '0.03491',
5610
+ // openAvgPrice: '0.03491',
5611
+ // openAvgPriceFullyScale: '0.03491',
5612
+ // closeAvgPrice: '0.03494',
5613
+ // liquidatePrice: '0.03433',
5614
+ // oim: '0',
5615
+ // im: '0',
5616
+ // holdFee: '0',
5617
+ // realised: '0.1829',
5618
+ // leverage: '50',
5619
+ // createTime: '1711512408000',
5620
+ // updateTime: '1711512553000',
5621
+ // autoAddIm: false,
5622
+ // version: '4',
5623
+ // profitRatio: '0.0227',
5624
+ // newOpenAvgPrice: '0.03491',
5625
+ // newCloseAvgPrice: '0.03494',
5626
+ // closeProfitLoss: '0.3423',
5627
+ // fee: '0.1593977',
5628
+ // positionShowStatus: 'CLOSED'
5629
+ // },
5630
+ // ...
5631
+ // ]
5632
+ // }
5633
+ //
5634
+ const data = this.safeList(response, 'data');
5635
+ const positions = this.parsePositions(data, symbols, params);
5636
+ return this.filterBySinceLimit(positions, since, limit);
5637
+ }
5527
5638
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
5528
5639
  const section = this.safeString(api, 0);
5529
5640
  const access = this.safeString(api, 1);
@@ -70,7 +70,11 @@ class ndax extends ndax$1 {
70
70
  'fetchOrders': true,
71
71
  'fetchOrderTrades': true,
72
72
  'fetchPosition': false,
73
+ 'fetchPositionHistory': false,
74
+ 'fetchPositionMode': false,
73
75
  'fetchPositions': false,
76
+ 'fetchPositionsForSymbol': false,
77
+ 'fetchPositionsHistory': false,
74
78
  'fetchPositionsRisk': false,
75
79
  'fetchPremiumIndexOHLCV': false,
76
80
  'fetchTicker': true,
@@ -75,7 +75,11 @@ class novadax extends novadax$1 {
75
75
  'fetchOrders': true,
76
76
  'fetchOrderTrades': true,
77
77
  'fetchPosition': false,
78
+ 'fetchPositionHistory': false,
79
+ 'fetchPositionMode': false,
78
80
  'fetchPositions': false,
81
+ 'fetchPositionsForSymbol': false,
82
+ 'fetchPositionsHistory': false,
79
83
  'fetchPositionsRisk': false,
80
84
  'fetchPremiumIndexOHLCV': false,
81
85
  'fetchTicker': true,
@@ -31,8 +31,10 @@ class okx extends okx$1 {
31
31
  'option': true,
32
32
  'addMargin': true,
33
33
  'cancelAllOrders': false,
34
+ 'cancelAllOrdersAfter': true,
34
35
  'cancelOrder': true,
35
36
  'cancelOrders': true,
37
+ 'cancelOrdersForSymbols': true,
36
38
  'closeAllPositions': false,
37
39
  'closePosition': true,
38
40
  'createConvertTrade': true,
@@ -109,8 +111,10 @@ class okx extends okx$1 {
109
111
  'fetchOrderTrades': true,
110
112
  'fetchPermissions': undefined,
111
113
  'fetchPosition': true,
114
+ 'fetchPositionHistory': 'emulated',
112
115
  'fetchPositions': true,
113
116
  'fetchPositionsForSymbol': true,
117
+ 'fetchPositionsHistory': true,
114
118
  'fetchPositionsRisk': false,
115
119
  'fetchPremiumIndexOHLCV': false,
116
120
  'fetchSettlementHistory': true,
@@ -3282,6 +3286,117 @@ class okx extends okx$1 {
3282
3286
  const ordersData = this.safeList(response, 'data', []);
3283
3287
  return this.parseOrders(ordersData, market, undefined, undefined, params);
3284
3288
  }
3289
+ async cancelOrdersForSymbols(orders, params = {}) {
3290
+ /**
3291
+ * @method
3292
+ * @name okx#cancelOrdersForSymbols
3293
+ * @description cancel multiple orders for multiple symbols
3294
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-multiple-orders
3295
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-cancel-algo-order
3296
+ * @param {CancellationRequest[]} orders each order should contain the parameters required by cancelOrder namely id and symbol
3297
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3298
+ * @param {boolean} [params.trigger] whether the order is a stop/trigger order
3299
+ * @param {boolean} [params.trailing] set to true if you want to cancel trailing orders
3300
+ * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
3301
+ */
3302
+ await this.loadMarkets();
3303
+ const request = [];
3304
+ const options = this.safeDict(this.options, 'cancelOrders', {});
3305
+ const defaultMethod = this.safeString(options, 'method', 'privatePostTradeCancelBatchOrders');
3306
+ let method = this.safeString(params, 'method', defaultMethod);
3307
+ const stop = this.safeBool2(params, 'stop', 'trigger');
3308
+ const trailing = this.safeBool(params, 'trailing', false);
3309
+ const isStopOrTrailing = stop || trailing;
3310
+ if (isStopOrTrailing) {
3311
+ method = 'privatePostTradeCancelAlgos';
3312
+ }
3313
+ for (let i = 0; i < orders.length; i++) {
3314
+ const order = orders[i];
3315
+ const id = this.safeString(order, 'id');
3316
+ const clientOrderId = this.safeString2(order, 'clOrdId', 'clientOrderId');
3317
+ const symbol = this.safeString(order, 'symbol');
3318
+ const market = this.market(symbol);
3319
+ let idKey = 'ordId';
3320
+ if (isStopOrTrailing) {
3321
+ idKey = 'algoId';
3322
+ }
3323
+ else if (clientOrderId !== undefined) {
3324
+ idKey = 'clOrdId';
3325
+ }
3326
+ const requestItem = {
3327
+ 'instId': market['id'],
3328
+ };
3329
+ requestItem[idKey] = (clientOrderId !== undefined) ? clientOrderId : id;
3330
+ request.push(requestItem);
3331
+ }
3332
+ let response = undefined;
3333
+ if (method === 'privatePostTradeCancelAlgos') {
3334
+ response = await this.privatePostTradeCancelAlgos(request); // * dont extend with params, otherwise ARRAY will be turned into OBJECT
3335
+ }
3336
+ else {
3337
+ response = await this.privatePostTradeCancelBatchOrders(request); // * dont extend with params, otherwise ARRAY will be turned into OBJECT
3338
+ }
3339
+ //
3340
+ // {
3341
+ // "code": "0",
3342
+ // "data": [
3343
+ // {
3344
+ // "clOrdId": "e123456789ec4dBC1123456ba123b45e",
3345
+ // "ordId": "405071912345641543",
3346
+ // "sCode": "0",
3347
+ // "sMsg": ""
3348
+ // },
3349
+ // ...
3350
+ // ],
3351
+ // "msg": ""
3352
+ // }
3353
+ //
3354
+ // Algo order
3355
+ //
3356
+ // {
3357
+ // "code": "0",
3358
+ // "data": [
3359
+ // {
3360
+ // "algoId": "431375349042380800",
3361
+ // "sCode": "0",
3362
+ // "sMsg": ""
3363
+ // }
3364
+ // ],
3365
+ // "msg": ""
3366
+ // }
3367
+ //
3368
+ const ordersData = this.safeList(response, 'data', []);
3369
+ return this.parseOrders(ordersData, undefined, undefined, undefined, params);
3370
+ }
3371
+ async cancelAllOrdersAfter(timeout, params = {}) {
3372
+ /**
3373
+ * @method
3374
+ * @name okx#cancelAllOrdersAfter
3375
+ * @description dead man's switch, cancel all orders after the given timeout
3376
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-all-after
3377
+ * @param {number} timeout time in milliseconds, 0 represents cancel the timer
3378
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3379
+ * @returns {object} the api result
3380
+ */
3381
+ await this.loadMarkets();
3382
+ const request = {
3383
+ 'timeOut': (timeout > 0) ? this.parseToInt(timeout / 1000) : 0,
3384
+ };
3385
+ const response = await this.privatePostTradeCancelAllAfter(this.extend(request, params));
3386
+ //
3387
+ // {
3388
+ // "code":"0",
3389
+ // "msg":"",
3390
+ // "data":[
3391
+ // {
3392
+ // "triggerTime":"1587971460",
3393
+ // "ts":"1587971400"
3394
+ // }
3395
+ // ]
3396
+ // }
3397
+ //
3398
+ return response;
3399
+ }
3285
3400
  parseOrderStatus(status) {
3286
3401
  const statuses = {
3287
3402
  'canceled': 'canceled',
@@ -8086,6 +8201,87 @@ class okx extends okx$1 {
8086
8201
  const modifications = this.parseMarginModifications(data);
8087
8202
  return this.filterBySymbolSinceLimit(modifications, symbol, since, limit);
8088
8203
  }
8204
+ async fetchPositionsHistory(symbols = undefined, since = undefined, limit = undefined, params = {}) {
8205
+ /**
8206
+ * @method
8207
+ * @name okx#fetchPositionsHistory
8208
+ * @description fetches historical positions
8209
+ * @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-positions-history
8210
+ * @param {string} [symbols] unified market symbols
8211
+ * @param {int} [since] timestamp in ms of the earliest position to fetch
8212
+ * @param {int} [limit] the maximum amount of records to fetch, default=100, max=100
8213
+ * @param {object} params extra parameters specific to the exchange api endpoint
8214
+ * @param {string} [params.marginMode] "cross" or "isolated"
8215
+ *
8216
+ * EXCHANGE SPECIFIC PARAMETERS
8217
+ * @param {string} [params.instType] margin, swap, futures or option
8218
+ * @param {string} [params.type] the type of latest close position 1: close position partially, 2:close all, 3:liquidation, 4:partial liquidation; 5:adl, is it is the latest type if there are several types for the same position
8219
+ * @param {string} [params.posId] position id, there is attribute expiration, the posid will be expired if it is more than 30 days after the last full close position, then position will use new posid
8220
+ * @param {string} [params.before] timestamp in ms of the earliest position to fetch based on the last update time of the position
8221
+ * @param {string} [params.after] timestamp in ms of the latest position to fetch based on the last update time of the position
8222
+ * @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
8223
+ */
8224
+ await this.loadMarkets();
8225
+ const marginMode = this.safeString(params, 'marginMode');
8226
+ const instType = this.safeStringUpper(params, 'instType');
8227
+ params = this.omit(params, ['until', 'marginMode', 'instType']);
8228
+ if (limit === undefined) {
8229
+ limit = 100;
8230
+ }
8231
+ const request = {
8232
+ 'limit': limit,
8233
+ };
8234
+ if (symbols !== undefined) {
8235
+ const symbolsLength = symbols.length;
8236
+ if (symbolsLength === 1) {
8237
+ const market = this.market(symbols[0]);
8238
+ request['instId'] = market['id'];
8239
+ }
8240
+ }
8241
+ if (marginMode !== undefined) {
8242
+ request['mgnMode'] = marginMode;
8243
+ }
8244
+ if (instType !== undefined) {
8245
+ request['instType'] = instType;
8246
+ }
8247
+ const response = await this.privateGetAccountPositionsHistory(this.extend(request, params));
8248
+ //
8249
+ // {
8250
+ // code: '0',
8251
+ // data: [
8252
+ // {
8253
+ // cTime: '1708735940395',
8254
+ // ccy: 'USDT',
8255
+ // closeAvgPx: '0.6330444444444444',
8256
+ // closeTotalPos: '27',
8257
+ // direction: 'long',
8258
+ // fee: '-1.69566',
8259
+ // fundingFee: '-11.870404179341788',
8260
+ // instId: 'XRP-USDT-SWAP',
8261
+ // instType: 'SWAP',
8262
+ // lever: '3.0',
8263
+ // liqPenalty: '0',
8264
+ // mgnMode: 'cross',
8265
+ // openAvgPx: '0.623',
8266
+ // openMaxPos: '15',
8267
+ // pnl: '27.11999999999988',
8268
+ // pnlRatio: '0.0241732402722634',
8269
+ // posId: '681423155054862336',
8270
+ // realizedPnl: '13.553935820658092',
8271
+ // triggerPx: '',
8272
+ // type: '2',
8273
+ // uTime: '1711088748170',
8274
+ // uly: 'XRP-USDT'
8275
+ // },
8276
+ // ...
8277
+ // ],
8278
+ // msg: ''
8279
+ // }
8280
+ //
8281
+ const data = this.safeList(response, 'data');
8282
+ const positions = this.parsePositions(data, symbols, params);
8283
+ return this.filterBySinceLimit(positions, since, limit);
8284
+ }
8089
8285
  }
8090
8286
 
8091
8287
  module.exports = okx;
@@ -74,8 +74,11 @@ class onetrading extends onetrading$1 {
74
74
  'fetchOrders': false,
75
75
  'fetchOrderTrades': true,
76
76
  'fetchPosition': false,
77
+ 'fetchPositionHistory': false,
77
78
  'fetchPositionMode': false,
78
79
  'fetchPositions': false,
80
+ 'fetchPositionsForSymbol': false,
81
+ 'fetchPositionsHistory': false,
79
82
  'fetchPositionsRisk': false,
80
83
  'fetchPremiumIndexOHLCV': false,
81
84
  'fetchTicker': true,
@@ -79,8 +79,11 @@ class p2b extends p2b$1 {
79
79
  'fetchOrderTrades': true,
80
80
  'fetchPermissions': false,
81
81
  'fetchPosition': false,
82
+ 'fetchPositionHistory': false,
83
+ 'fetchPositionMode': false,
82
84
  'fetchPositions': false,
83
85
  'fetchPositionsForSymbol': false,
86
+ 'fetchPositionsHistory': false,
84
87
  'fetchPositionsRisk': false,
85
88
  'fetchPremiumIndexOHLCV': false,
86
89
  'fetchTicker': true,
@@ -1004,7 +1004,7 @@ class bitget extends bitget$1 {
1004
1004
  }
1005
1005
  return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
1006
1006
  }
1007
- handleOrder(client, message, subscription = undefined) {
1007
+ handleOrder(client, message) {
1008
1008
  //
1009
1009
  // spot
1010
1010
  //
@@ -117,7 +117,7 @@ class bybit extends bybit$1 {
117
117
  },
118
118
  'streaming': {
119
119
  'ping': this.ping,
120
- 'keepAlive': 20000,
120
+ 'keepAlive': 19000,
121
121
  },
122
122
  });
123
123
  }
@@ -46,7 +46,7 @@ class coinbase extends coinbase$1 {
46
46
  },
47
47
  });
48
48
  }
49
- async subscribe(name, symbol = undefined, params = {}) {
49
+ async subscribe(name, isPrivate, symbol = undefined, params = {}) {
50
50
  /**
51
51
  * @ignore
52
52
  * @method
@@ -58,7 +58,6 @@ class coinbase extends coinbase$1 {
58
58
  * @returns {object} subscription to a websocket channel
59
59
  */
60
60
  await this.loadMarkets();
61
- this.checkRequiredCredentials();
62
61
  let market = undefined;
63
62
  let messageHash = name;
64
63
  let productIds = [];
@@ -75,8 +74,6 @@ class coinbase extends coinbase$1 {
75
74
  }
76
75
  const url = this.urls['api']['ws'];
77
76
  const timestamp = this.numberToString(this.seconds());
78
- const isCloudAPiKey = (this.apiKey.indexOf('organizations/') >= 0) || (this.secret.startsWith('-----BEGIN'));
79
- const auth = timestamp + name + productIds.join(',');
80
77
  const subscribe = {
81
78
  'type': 'subscribe',
82
79
  'product_ids': productIds,
@@ -85,25 +82,30 @@ class coinbase extends coinbase$1 {
85
82
  // 'timestamp': timestamp,
86
83
  // 'signature': this.hmac (this.encode (auth), this.encode (this.secret), sha256),
87
84
  };
88
- if (!isCloudAPiKey) {
89
- subscribe['api_key'] = this.apiKey;
90
- subscribe['timestamp'] = timestamp;
91
- subscribe['signature'] = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
92
- }
93
- else {
94
- if (this.apiKey.startsWith('-----BEGIN')) {
95
- throw new errors.ArgumentsRequired(this.id + ' apiKey should contain the name (eg: organizations/3b910e93....) and not the public key');
85
+ if (isPrivate) {
86
+ this.checkRequiredCredentials();
87
+ const isCloudAPiKey = (this.apiKey.indexOf('organizations/') >= 0) || (this.secret.startsWith('-----BEGIN'));
88
+ const auth = timestamp + name + productIds.join(',');
89
+ if (!isCloudAPiKey) {
90
+ subscribe['api_key'] = this.apiKey;
91
+ subscribe['timestamp'] = timestamp;
92
+ subscribe['signature'] = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
96
93
  }
97
- const currentToken = this.safeString(this.options, 'wsToken');
98
- const tokenTimestamp = this.safeInteger(this.options, 'wsTokenTimestamp', 0);
99
- const seconds = this.seconds();
100
- if (currentToken === undefined || tokenTimestamp + 120 < seconds) {
101
- // we should generate new token
102
- const token = this.createAuthToken(seconds);
103
- this.options['wsToken'] = token;
104
- this.options['wsTokenTimestamp'] = seconds;
94
+ else {
95
+ if (this.apiKey.startsWith('-----BEGIN')) {
96
+ throw new errors.ArgumentsRequired(this.id + ' apiKey should contain the name (eg: organizations/3b910e93....) and not the public key');
97
+ }
98
+ const currentToken = this.safeString(this.options, 'wsToken');
99
+ const tokenTimestamp = this.safeInteger(this.options, 'wsTokenTimestamp', 0);
100
+ const seconds = this.seconds();
101
+ if (currentToken === undefined || tokenTimestamp + 120 < seconds) {
102
+ // we should generate new token
103
+ const token = this.createAuthToken(seconds);
104
+ this.options['wsToken'] = token;
105
+ this.options['wsTokenTimestamp'] = seconds;
106
+ }
107
+ subscribe['jwt'] = this.safeString(this.options, 'wsToken');
105
108
  }
106
- subscribe['jwt'] = this.safeString(this.options, 'wsToken');
107
109
  }
108
110
  return await this.watch(url, messageHash, subscribe, messageHash);
109
111
  }
@@ -118,7 +120,7 @@ class coinbase extends coinbase$1 {
118
120
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
119
121
  */
120
122
  const name = 'ticker';
121
- return await this.subscribe(name, symbol, params);
123
+ return await this.subscribe(name, false, symbol, params);
122
124
  }
123
125
  async watchTickers(symbols = undefined, params = {}) {
124
126
  /**
@@ -134,7 +136,7 @@ class coinbase extends coinbase$1 {
134
136
  symbols = this.symbols;
135
137
  }
136
138
  const name = 'ticker_batch';
137
- const tickers = await this.subscribe(name, symbols, params);
139
+ const tickers = await this.subscribe(name, false, symbols, params);
138
140
  if (this.newUpdates) {
139
141
  return tickers;
140
142
  }
@@ -298,7 +300,7 @@ class coinbase extends coinbase$1 {
298
300
  await this.loadMarkets();
299
301
  symbol = this.symbol(symbol);
300
302
  const name = 'market_trades';
301
- const trades = await this.subscribe(name, symbol, params);
303
+ const trades = await this.subscribe(name, false, symbol, params);
302
304
  if (this.newUpdates) {
303
305
  limit = trades.getLimit(symbol, limit);
304
306
  }
@@ -318,7 +320,7 @@ class coinbase extends coinbase$1 {
318
320
  */
319
321
  await this.loadMarkets();
320
322
  const name = 'user';
321
- const orders = await this.subscribe(name, symbol, params);
323
+ const orders = await this.subscribe(name, true, symbol, params);
322
324
  if (this.newUpdates) {
323
325
  limit = orders.getLimit(symbol, limit);
324
326
  }
@@ -339,7 +341,7 @@ class coinbase extends coinbase$1 {
339
341
  const name = 'level2';
340
342
  const market = this.market(symbol);
341
343
  symbol = market['symbol'];
342
- const orderbook = await this.subscribe(name, symbol, params);
344
+ const orderbook = await this.subscribe(name, false, symbol, params);
343
345
  return orderbook.limit();
344
346
  }
345
347
  handleTrade(client, message) {
@@ -557,8 +559,8 @@ class coinbase extends coinbase$1 {
557
559
  this.orderbooks[symbol] = this.orderBook({}, limit);
558
560
  const orderbook = this.orderbooks[symbol];
559
561
  this.handleOrderBookHelper(orderbook, updates);
560
- orderbook['timestamp'] = undefined;
561
- orderbook['datetime'] = undefined;
562
+ orderbook['timestamp'] = this.parse8601(datetime);
563
+ orderbook['datetime'] = datetime;
562
564
  orderbook['symbol'] = symbol;
563
565
  client.resolve(orderbook, messageHash);
564
566
  if (messageHash.endsWith('USD')) {
@@ -577,7 +579,6 @@ class coinbase extends coinbase$1 {
577
579
  }
578
580
  }
579
581
  }
580
- return message;
581
582
  }
582
583
  handleSubscriptionStatus(client, message) {
583
584
  //
@@ -67,8 +67,11 @@ class probit extends probit$1 {
67
67
  'fetchOrder': true,
68
68
  'fetchOrderBook': true,
69
69
  'fetchPosition': false,
70
+ 'fetchPositionHistory': false,
70
71
  'fetchPositionMode': false,
71
72
  'fetchPositions': false,
73
+ 'fetchPositionsForSymbol': false,
74
+ 'fetchPositionsHistory': false,
72
75
  'fetchPositionsRisk': false,
73
76
  'fetchPremiumIndexOHLCV': false,
74
77
  'fetchTicker': true,
@@ -64,8 +64,11 @@ class timex extends timex$1 {
64
64
  'fetchOrder': true,
65
65
  'fetchOrderBook': true,
66
66
  'fetchPosition': false,
67
+ 'fetchPositionHistory': false,
67
68
  'fetchPositionMode': false,
68
69
  'fetchPositions': false,
70
+ 'fetchPositionsForSymbol': false,
71
+ 'fetchPositionsHistory': false,
69
72
  'fetchPositionsRisk': false,
70
73
  'fetchPremiumIndexOHLCV': false,
71
74
  'fetchTicker': true,
@@ -79,8 +79,11 @@ class tradeogre extends tradeogre$1 {
79
79
  'fetchOrderTrades': false,
80
80
  'fetchPermissions': false,
81
81
  'fetchPosition': false,
82
+ 'fetchPositionHistory': false,
83
+ 'fetchPositionMode': false,
82
84
  'fetchPositions': false,
83
85
  'fetchPositionsForSymbol': false,
86
+ 'fetchPositionsHistory': false,
84
87
  'fetchPositionsRisk': false,
85
88
  'fetchPremiumIndexOHLCV': false,
86
89
  'fetchTicker': true,
@@ -66,8 +66,11 @@ class wavesexchange extends wavesexchange$1 {
66
66
  'fetchOrderBook': true,
67
67
  'fetchOrders': true,
68
68
  'fetchPosition': false,
69
+ 'fetchPositionHistory': false,
69
70
  'fetchPositionMode': false,
70
71
  'fetchPositions': false,
72
+ 'fetchPositionsForSymbol': false,
73
+ 'fetchPositionsHistory': false,
71
74
  'fetchPositionsRisk': false,
72
75
  'fetchPremiumIndexOHLCV': false,
73
76
  'fetchTicker': true,
@@ -71,8 +71,11 @@ class wazirx extends wazirx$1 {
71
71
  'fetchOrderBook': true,
72
72
  'fetchOrders': true,
73
73
  'fetchPosition': false,
74
+ 'fetchPositionHistory': false,
74
75
  'fetchPositionMode': false,
75
76
  'fetchPositions': false,
77
+ 'fetchPositionsForSymbol': false,
78
+ 'fetchPositionsHistory': false,
76
79
  'fetchPositionsRisk': false,
77
80
  'fetchPremiumIndexOHLCV': false,
78
81
  'fetchStatus': true,