ccxt 4.1.74 → 4.1.76

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 (140) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +620 -342
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/ace.js +2 -0
  6. package/dist/cjs/src/alpaca.js +2 -0
  7. package/dist/cjs/src/base/Exchange.js +14 -2
  8. package/dist/cjs/src/base/errors.js +7 -7
  9. package/dist/cjs/src/base/ws/Client.js +13 -14
  10. package/dist/cjs/src/bigone.js +38 -9
  11. package/dist/cjs/src/binance.js +4 -0
  12. package/dist/cjs/src/binanceus.js +2 -0
  13. package/dist/cjs/src/bingx.js +134 -40
  14. package/dist/cjs/src/bit2c.js +2 -0
  15. package/dist/cjs/src/bitbank.js +2 -0
  16. package/dist/cjs/src/bithumb.js +2 -0
  17. package/dist/cjs/src/bitmart.js +33 -11
  18. package/dist/cjs/src/bitopro.js +2 -0
  19. package/dist/cjs/src/bitpanda.js +2 -0
  20. package/dist/cjs/src/bitso.js +2 -0
  21. package/dist/cjs/src/bitstamp.js +2 -0
  22. package/dist/cjs/src/bittrex.js +2 -0
  23. package/dist/cjs/src/bitvavo.js +2 -0
  24. package/dist/cjs/src/bl3p.js +2 -0
  25. package/dist/cjs/src/btcalpha.js +2 -0
  26. package/dist/cjs/src/btcbox.js +2 -0
  27. package/dist/cjs/src/btcmarkets.js +2 -0
  28. package/dist/cjs/src/btcturk.js +2 -0
  29. package/dist/cjs/src/bybit.js +2 -0
  30. package/dist/cjs/src/coinbase.js +2 -0
  31. package/dist/cjs/src/coincheck.js +2 -0
  32. package/dist/cjs/src/coinlist.js +2 -0
  33. package/dist/cjs/src/coinmate.js +2 -0
  34. package/dist/cjs/src/coinone.js +2 -0
  35. package/dist/cjs/src/coinsph.js +2 -0
  36. package/dist/cjs/src/coinspot.js +2 -0
  37. package/dist/cjs/src/cryptocom.js +2 -185
  38. package/dist/cjs/src/gate.js +1 -0
  39. package/dist/cjs/src/gemini.js +23 -19
  40. package/dist/cjs/src/idex.js +2 -0
  41. package/dist/cjs/src/independentreserve.js +2 -0
  42. package/dist/cjs/src/indodax.js +2 -0
  43. package/dist/cjs/src/kraken.js +154 -11
  44. package/dist/cjs/src/kucoin.js +2 -0
  45. package/dist/cjs/src/kuna.js +2 -0
  46. package/dist/cjs/src/latoken.js +2 -0
  47. package/dist/cjs/src/luno.js +2 -0
  48. package/dist/cjs/src/mercado.js +2 -0
  49. package/dist/cjs/src/mexc.js +2 -0
  50. package/dist/cjs/src/ndax.js +2 -0
  51. package/dist/cjs/src/novadax.js +2 -0
  52. package/dist/cjs/src/okx.js +24 -9
  53. package/dist/cjs/src/p2b.js +2 -0
  54. package/dist/cjs/src/poloniex.js +27 -25
  55. package/dist/cjs/src/pro/binance.js +60 -8
  56. package/dist/cjs/src/pro/coinbasepro.js +1 -1
  57. package/dist/cjs/src/static_dependencies/proxies/http-proxy-agent/index.js +8 -11
  58. package/dist/cjs/src/static_dependencies/proxies/https-proxy-agent/index.js +5 -8
  59. package/dist/cjs/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +5 -12
  60. package/dist/cjs/src/wavesexchange.js +2 -0
  61. package/dist/cjs/src/wazirx.js +2 -0
  62. package/dist/cjs/src/woo.js +2 -0
  63. package/dist/cjs/src/yobit.js +2 -0
  64. package/dist/cjs/src/zonda.js +2 -0
  65. package/js/ccxt.d.ts +1 -1
  66. package/js/ccxt.js +1 -1
  67. package/js/src/abstract/binance.d.ts +2 -0
  68. package/js/src/abstract/binancecoinm.d.ts +2 -0
  69. package/js/src/abstract/binanceus.d.ts +2 -0
  70. package/js/src/abstract/binanceusdm.d.ts +2 -0
  71. package/js/src/abstract/okx.d.ts +14 -0
  72. package/js/src/ace.js +2 -0
  73. package/js/src/alpaca.js +2 -0
  74. package/js/src/base/Exchange.d.ts +4 -0
  75. package/js/src/base/Exchange.js +14 -2
  76. package/js/src/base/errors.d.ts +4 -4
  77. package/js/src/base/errors.js +7 -7
  78. package/js/src/base/ws/Client.js +13 -14
  79. package/js/src/bigone.d.ts +1 -0
  80. package/js/src/bigone.js +38 -9
  81. package/js/src/binance.js +4 -0
  82. package/js/src/binanceus.js +2 -0
  83. package/js/src/bingx.d.ts +7 -3
  84. package/js/src/bingx.js +135 -41
  85. package/js/src/bit2c.js +2 -0
  86. package/js/src/bitbank.js +2 -0
  87. package/js/src/bithumb.js +2 -0
  88. package/js/src/bitmart.d.ts +1 -0
  89. package/js/src/bitmart.js +33 -11
  90. package/js/src/bitopro.js +2 -0
  91. package/js/src/bitpanda.js +2 -0
  92. package/js/src/bitso.js +2 -0
  93. package/js/src/bitstamp.js +2 -0
  94. package/js/src/bittrex.js +2 -0
  95. package/js/src/bitvavo.js +2 -0
  96. package/js/src/bl3p.js +2 -0
  97. package/js/src/btcalpha.js +2 -0
  98. package/js/src/btcbox.js +2 -0
  99. package/js/src/btcmarkets.js +2 -0
  100. package/js/src/btcturk.js +2 -0
  101. package/js/src/bybit.js +2 -0
  102. package/js/src/coinbase.js +2 -0
  103. package/js/src/coincheck.js +2 -0
  104. package/js/src/coinlist.js +2 -0
  105. package/js/src/coinmate.js +2 -0
  106. package/js/src/coinone.js +2 -0
  107. package/js/src/coinsph.js +2 -0
  108. package/js/src/coinspot.js +2 -0
  109. package/js/src/cryptocom.d.ts +0 -24
  110. package/js/src/cryptocom.js +2 -185
  111. package/js/src/gate.js +1 -0
  112. package/js/src/gemini.js +23 -19
  113. package/js/src/idex.js +2 -0
  114. package/js/src/independentreserve.js +2 -0
  115. package/js/src/indodax.js +2 -0
  116. package/js/src/kraken.d.ts +2 -0
  117. package/js/src/kraken.js +154 -11
  118. package/js/src/kucoin.js +2 -0
  119. package/js/src/kuna.js +2 -0
  120. package/js/src/latoken.js +2 -0
  121. package/js/src/luno.js +2 -0
  122. package/js/src/mercado.js +2 -0
  123. package/js/src/mexc.js +2 -0
  124. package/js/src/ndax.js +2 -0
  125. package/js/src/novadax.js +2 -0
  126. package/js/src/okx.js +24 -9
  127. package/js/src/p2b.js +2 -0
  128. package/js/src/poloniex.js +27 -25
  129. package/js/src/pro/binance.d.ts +1 -0
  130. package/js/src/pro/binance.js +61 -9
  131. package/js/src/pro/coinbasepro.js +1 -1
  132. package/js/src/static_dependencies/proxies/http-proxy-agent/index.js +9 -8
  133. package/js/src/static_dependencies/proxies/https-proxy-agent/index.js +5 -7
  134. package/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +5 -7
  135. package/js/src/wavesexchange.js +2 -0
  136. package/js/src/wazirx.js +2 -0
  137. package/js/src/woo.js +2 -0
  138. package/js/src/yobit.js +2 -0
  139. package/js/src/zonda.js +2 -0
  140. package/package.json +1 -1
package/dist/cjs/ccxt.js CHANGED
@@ -172,7 +172,7 @@ var woo$1 = require('./src/pro/woo.js');
172
172
 
173
173
  //-----------------------------------------------------------------------------
174
174
  // this is updated by vss.js when building
175
- const version = '4.1.74';
175
+ const version = '4.1.76';
176
176
  Exchange["default"].ccxtVersion = version;
177
177
  const exchanges = {
178
178
  'ace': ace,
@@ -31,6 +31,8 @@ class ace extends ace$1 {
31
31
  'cancelAllOrders': false,
32
32
  'cancelOrder': true,
33
33
  'cancelOrders': false,
34
+ 'closeAllPositions': false,
35
+ 'closePosition': false,
34
36
  'createOrder': true,
35
37
  'editOrder': false,
36
38
  'fetchBalance': true,
@@ -47,6 +47,8 @@ class alpaca extends alpaca$1 {
47
47
  'option': false,
48
48
  'cancelAllOrders': true,
49
49
  'cancelOrder': true,
50
+ 'closeAllPositions': false,
51
+ 'closePosition': false,
50
52
  'createOrder': true,
51
53
  'fetchBalance': true,
52
54
  'fetchBidsAsks': false,
@@ -355,6 +355,8 @@ class Exchange {
355
355
  'cancelAllOrders': undefined,
356
356
  'cancelOrder': true,
357
357
  'cancelOrders': undefined,
358
+ 'closeAllPositions': undefined,
359
+ 'closePosition': undefined,
358
360
  'createDepositAddress': undefined,
359
361
  'createLimitOrder': true,
360
362
  'createMarketOrder': true,
@@ -3698,6 +3700,12 @@ class Exchange {
3698
3700
  async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3699
3701
  throw new errors.NotSupported(this.id + ' fetchFundingHistory() is not supported yet');
3700
3702
  }
3703
+ async closePosition(symbol, side = undefined, marginMode = undefined, params = {}) {
3704
+ throw new errors.NotSupported(this.id + ' closePositions() is not supported yet');
3705
+ }
3706
+ async closeAllPositions(params = {}) {
3707
+ throw new errors.NotSupported(this.id + ' closeAllPositions() is not supported yet');
3708
+ }
3701
3709
  parseLastPrice(price, market = undefined) {
3702
3710
  throw new errors.NotSupported(this.id + ' parseLastPrice() is not supported yet');
3703
3711
  }
@@ -4689,6 +4697,10 @@ class Exchange {
4689
4697
  if (cursorValue === undefined) {
4690
4698
  break;
4691
4699
  }
4700
+ const lastTimestamp = this.safeInteger(last, 'timestamp');
4701
+ if (lastTimestamp !== undefined && lastTimestamp < since) {
4702
+ break;
4703
+ }
4692
4704
  }
4693
4705
  catch (e) {
4694
4706
  errors += 1;
@@ -4741,10 +4753,10 @@ class Exchange {
4741
4753
  const first = this.safeValue(result, 0);
4742
4754
  if (first !== undefined) {
4743
4755
  if ('timestamp' in first) {
4744
- return this.sortBy(result, 'timestamp');
4756
+ return this.sortBy(result, 'timestamp', true);
4745
4757
  }
4746
4758
  if ('id' in first) {
4747
- return this.sortBy(result, 'id');
4759
+ return this.sortBy(result, 'id', true);
4748
4760
  }
4749
4761
  }
4750
4762
  return result;
@@ -190,8 +190,14 @@ class NotSupported extends ExchangeError {
190
190
  this.name = 'NotSupported';
191
191
  }
192
192
  }
193
+ class OperationFailed extends BaseError {
194
+ constructor(message) {
195
+ super(message);
196
+ this.name = 'OperationFailed';
197
+ }
198
+ }
193
199
  // Network error
194
- class NetworkError extends BaseError {
200
+ class NetworkError extends OperationFailed {
195
201
  constructor(message) {
196
202
  super(message);
197
203
  this.name = 'NetworkError';
@@ -233,12 +239,6 @@ class RequestTimeout extends NetworkError {
233
239
  this.name = 'RequestTimeout';
234
240
  }
235
241
  }
236
- class OperationFailed extends BaseError {
237
- constructor(message) {
238
- super(message);
239
- this.name = 'OperationFailed';
240
- }
241
- }
242
242
  /* ------------------------------------------------------------------------ */
243
243
  // export default subclass (
244
244
  // // Root class
@@ -200,6 +200,7 @@ class Client {
200
200
  this.reset(this.error);
201
201
  this.onErrorCallback(this, this.error);
202
202
  }
203
+ /* eslint-disable no-shadow */
203
204
  onClose(event) {
204
205
  if (this.verbose) {
205
206
  this.log(new Date(), 'onClose', event);
@@ -227,6 +228,7 @@ class Client {
227
228
  message = (typeof message === 'string') ? message : JSON.stringify(message);
228
229
  const future = Future.createFuture();
229
230
  if (platform.isNode) {
231
+ /* eslint-disable no-inner-declarations */
230
232
  function onSendComplete(error) {
231
233
  if (error) {
232
234
  future.reject(error);
@@ -251,23 +253,20 @@ class Client {
251
253
  // MessageEvent {isTrusted: true, data: "{"e":"depthUpdate","E":1581358737706,"s":"ETHBTC",…"0.06200000"]],"a":[["0.02261300","0.00000000"]]}", origin: "wss://stream.binance.com:9443", lastEventId: "", source: null, …}
252
254
  let message = messageEvent.data;
253
255
  let arrayBuffer;
254
- if (this.gunzip || this.inflate) {
255
- if (typeof message === 'string') {
256
- arrayBuffer = index.utf8.decode(message);
257
- }
258
- else {
256
+ if (typeof message !== 'string') {
257
+ if (this.gunzip || this.inflate) {
259
258
  arrayBuffer = new Uint8Array(message.buffer.slice(message.byteOffset, message.byteOffset + message.byteLength));
259
+ if (this.gunzip) {
260
+ arrayBuffer = browser.gunzipSync(arrayBuffer);
261
+ }
262
+ else if (this.inflate) {
263
+ arrayBuffer = browser.inflateSync(arrayBuffer);
264
+ }
265
+ message = index.utf8.encode(arrayBuffer);
260
266
  }
261
- if (this.gunzip) {
262
- arrayBuffer = browser.gunzipSync(arrayBuffer);
263
- }
264
- else if (this.inflate) {
265
- arrayBuffer = browser.inflateSync(arrayBuffer);
267
+ else {
268
+ message = message.toString();
266
269
  }
267
- message = index.utf8.encode(arrayBuffer);
268
- }
269
- if (typeof message !== 'string') {
270
- message = message.toString();
271
270
  }
272
271
  try {
273
272
  if (encode.isJsonEncodedObject(message)) {
@@ -30,6 +30,8 @@ class bigone extends bigone$1 {
30
30
  'option': undefined,
31
31
  'cancelAllOrders': true,
32
32
  'cancelOrder': true,
33
+ 'createMarketBuyOrderWithCost': true,
34
+ 'createMarketSellOrderWithCost': false,
33
35
  'createOrder': true,
34
36
  'createPostOnlyOrder': true,
35
37
  'createStopLimitOrder': true,
@@ -1152,6 +1154,20 @@ class bigone extends bigone$1 {
1152
1154
  'trades': undefined,
1153
1155
  }, market);
1154
1156
  }
1157
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1158
+ /**
1159
+ * @method
1160
+ * @name bigone#createMarketBuyOrderWithCost
1161
+ * @see https://open.big.one/docs/spot_orders.html#create-order
1162
+ * @description create a market buy order by providing the symbol and cost
1163
+ * @param {string} symbol unified symbol of the market to create an order in
1164
+ * @param {float} cost how much you want to trade in units of the quote currency
1165
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1166
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1167
+ */
1168
+ params['createMarketBuyOrderRequiresPrice'] = false;
1169
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1170
+ }
1155
1171
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1156
1172
  /**
1157
1173
  * @method
@@ -1179,7 +1195,7 @@ class bigone extends bigone$1 {
1179
1195
  const requestSide = isBuy ? 'BID' : 'ASK';
1180
1196
  let uppercaseType = type.toUpperCase();
1181
1197
  const isLimit = uppercaseType === 'LIMIT';
1182
- const exchangeSpecificParam = this.safeValue(params, 'post_only');
1198
+ const exchangeSpecificParam = this.safeValue(params, 'post_only', false);
1183
1199
  let postOnly = undefined;
1184
1200
  [postOnly, params] = this.handlePostOnly((uppercaseType === 'MARKET'), exchangeSpecificParam, params);
1185
1201
  const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'stop_price']);
@@ -1203,21 +1219,34 @@ class bigone extends bigone$1 {
1203
1219
  request['post_only'] = true;
1204
1220
  }
1205
1221
  }
1222
+ request['amount'] = this.amountToPrecision(symbol, amount);
1206
1223
  }
1207
1224
  else {
1208
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice');
1209
- if (createMarketBuyOrderRequiresPrice && (side === 'buy')) {
1210
- if (price === undefined) {
1211
- throw new errors.InvalidOrder(this.id + ' createOrder() requires price argument for market buy orders on spot markets to calculate the total amount to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to false and pass in the cost to spend into the amount parameter');
1225
+ if (isBuy) {
1226
+ let createMarketBuyOrderRequiresPrice = true;
1227
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1228
+ const cost = this.safeNumber(params, 'cost');
1229
+ params = this.omit(params, 'cost');
1230
+ if (createMarketBuyOrderRequiresPrice) {
1231
+ if ((price === undefined) && (cost === undefined)) {
1232
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument');
1233
+ }
1234
+ else {
1235
+ const amountString = this.numberToString(amount);
1236
+ const priceString = this.numberToString(price);
1237
+ const quoteAmount = this.parseToNumeric(Precise["default"].stringMul(amountString, priceString));
1238
+ const costRequest = (cost !== undefined) ? cost : quoteAmount;
1239
+ request['amount'] = this.costToPrecision(symbol, costRequest);
1240
+ }
1212
1241
  }
1213
1242
  else {
1214
- const amountString = this.numberToString(amount);
1215
- const priceString = this.numberToString(price);
1216
- amount = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
1243
+ request['amount'] = this.costToPrecision(symbol, amount);
1217
1244
  }
1218
1245
  }
1246
+ else {
1247
+ request['amount'] = this.amountToPrecision(symbol, amount);
1248
+ }
1219
1249
  }
1220
- request['amount'] = this.amountToPrecision(symbol, amount);
1221
1250
  if (triggerPrice !== undefined) {
1222
1251
  request['stop_price'] = this.priceToPrecision(symbol, triggerPrice);
1223
1252
  request['operator'] = isBuy ? 'GTE' : 'LTE';
@@ -38,6 +38,8 @@ class binance extends binance$1 {
38
38
  'cancelAllOrders': true,
39
39
  'cancelOrder': true,
40
40
  'cancelOrders': true,
41
+ 'closeAllPositions': false,
42
+ 'closePosition': false,
41
43
  'createDepositAddress': false,
42
44
  'createOrder': true,
43
45
  'createOrders': true,
@@ -874,6 +876,7 @@ class binance extends binance$1 {
874
876
  'uiKlines': 0.4,
875
877
  'ticker/24hr': { 'cost': 0.4, 'noSymbol': 16 },
876
878
  'ticker': { 'cost': 0.4, 'noSymbol': 16 },
879
+ 'ticker/tradingDay': 0.8,
877
880
  'ticker/price': { 'cost': 0.4, 'noSymbol': 0.8 },
878
881
  'ticker/bookTicker': { 'cost': 0.4, 'noSymbol': 0.8 },
879
882
  'exchangeInfo': 4,
@@ -902,6 +905,7 @@ class binance extends binance$1 {
902
905
  'rateLimit/order': 8,
903
906
  'myPreventedMatches': 4,
904
907
  'myAllocations': 4,
908
+ 'account/commission': 4,
905
909
  },
906
910
  'post': {
907
911
  'order/oco': 0.2,
@@ -48,6 +48,8 @@ class binanceus extends binance {
48
48
  'option': false,
49
49
  'addMargin': false,
50
50
  'borrowMargin': false,
51
+ 'closeAllPositions': false,
52
+ 'closePosition': false,
51
53
  'createReduceOnlyOrder': false,
52
54
  'fetchBorrowInterest': false,
53
55
  'fetchBorrowRate': false,
@@ -29,6 +29,9 @@ class bingx extends bingx$1 {
29
29
  'cancelAllOrders': true,
30
30
  'cancelOrder': true,
31
31
  'cancelOrders': true,
32
+ 'createMarketBuyOrderWithCost': true,
33
+ 'createMarketOrderWithCost': true,
34
+ 'createMarketSellOrderWithCost': true,
32
35
  'createOrder': true,
33
36
  'createOrders': true,
34
37
  'fetchBalance': true,
@@ -77,10 +80,18 @@ class bingx extends bingx$1 {
77
80
  'www': 'https://bingx.com/',
78
81
  'doc': 'https://bingx-api.github.io/docs/',
79
82
  'referral': 'https://bingx.com/invite/OHETOM',
80
- 'fees': {
81
- 'trading': {
82
- 'tierBased': true,
83
- },
83
+ },
84
+ 'fees': {
85
+ 'tierBased': true,
86
+ 'spot': {
87
+ 'feeSide': 'get',
88
+ 'maker': this.parseNumber('0.001'),
89
+ 'taker': this.parseNumber('0.001'),
90
+ },
91
+ 'swap': {
92
+ 'feeSide': 'quote',
93
+ 'maker': this.parseNumber('0.0002'),
94
+ 'taker': this.parseNumber('0.0005'),
84
95
  },
85
96
  },
86
97
  'requiredCredentials': {
@@ -299,9 +310,6 @@ class bingx extends bingx$1 {
299
310
  '1w': '1w',
300
311
  '1M': '1M',
301
312
  },
302
- 'fees': {
303
- 'trading': {},
304
- },
305
313
  'precisionMode': number.DECIMAL_PLACES,
306
314
  'exceptions': {
307
315
  'exact': {
@@ -553,11 +561,12 @@ class bingx extends bingx$1 {
553
561
  if (settle !== undefined) {
554
562
  symbol += ':' + settle;
555
563
  }
564
+ const fees = this.safeValue(this.fees, type, {});
556
565
  const contractSize = this.safeNumber(market, 'size');
557
566
  const isActive = this.safeString(market, 'status') === '1';
558
567
  const isInverse = (spot) ? undefined : false;
559
568
  const isLinear = (spot) ? undefined : swap;
560
- return {
569
+ return this.safeMarketStructure({
561
570
  'id': id,
562
571
  'symbol': symbol,
563
572
  'base': base,
@@ -576,8 +585,9 @@ class bingx extends bingx$1 {
576
585
  'contract': swap,
577
586
  'linear': isLinear,
578
587
  'inverse': isInverse,
579
- 'taker': undefined,
580
- 'maker': undefined,
588
+ 'taker': this.safeNumber(fees, 'taker'),
589
+ 'maker': this.safeNumber(fees, 'maker'),
590
+ 'feeSide': this.safeString(fees, 'feeSide'),
581
591
  'contractSize': contractSize,
582
592
  'expiry': undefined,
583
593
  'expiryDatetime': undefined,
@@ -607,7 +617,7 @@ class bingx extends bingx$1 {
607
617
  },
608
618
  'created': undefined,
609
619
  'info': market,
610
- };
620
+ });
611
621
  }
612
622
  async fetchMarkets(params = {}) {
613
623
  /**
@@ -1573,23 +1583,28 @@ class bingx extends bingx$1 {
1573
1583
  // "avgPrice": "2.2",
1574
1584
  // "leverage": 10,
1575
1585
  // }
1586
+ //
1576
1587
  // standard position
1588
+ //
1577
1589
  // {
1578
- // "currentPrice":"82.91",
1579
- // "symbol":"LTC/USDT",
1580
- // "initialMargin":"5.00000000000000000000",
1581
- // "unrealizedProfit":"-0.26464500",
1582
- // "leverage":"20.000000000",
1583
- // "isolated":true,
1584
- // "entryPrice":"83.13",
1585
- // "positionSide":"LONG",
1586
- // "positionAmt":"1.20365912",
1590
+ // "currentPrice": "82.91",
1591
+ // "symbol": "LTC/USDT",
1592
+ // "initialMargin": "5.00000000000000000000",
1593
+ // "unrealizedProfit": "-0.26464500",
1594
+ // "leverage": "20.000000000",
1595
+ // "isolated": true,
1596
+ // "entryPrice": "83.13",
1597
+ // "positionSide": "LONG",
1598
+ // "positionAmt": "1.20365912",
1587
1599
  // }
1588
1600
  //
1589
- let marketId = this.safeString(position, 'symbol');
1601
+ let marketId = this.safeString(position, 'symbol', '');
1590
1602
  marketId = marketId.replace('/', '-'); // standard return different format
1591
1603
  const isolated = this.safeValue(position, 'isolated');
1592
- const marginMode = isolated ? 'isolated' : 'cross';
1604
+ let marginMode = undefined;
1605
+ if (isolated !== undefined) {
1606
+ marginMode = isolated ? 'isolated' : 'cross';
1607
+ }
1593
1608
  return this.safePosition({
1594
1609
  'info': position,
1595
1610
  'id': this.safeString(position, 'positionId'),
@@ -1621,6 +1636,46 @@ class bingx extends bingx$1 {
1621
1636
  'takeProfitPrice': undefined,
1622
1637
  });
1623
1638
  }
1639
+ async createMarketOrderWithCost(symbol, side, cost, params = {}) {
1640
+ /**
1641
+ * @method
1642
+ * @name bingx#createMarketOrderWithCost
1643
+ * @description create a market order by providing the symbol, side and cost
1644
+ * @param {string} symbol unified symbol of the market to create an order in
1645
+ * @param {string} side 'buy' or 'sell'
1646
+ * @param {float} cost how much you want to trade in units of the quote currency
1647
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1648
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1649
+ */
1650
+ params['quoteOrderQty'] = cost;
1651
+ return await this.createOrder(symbol, 'market', side, cost, undefined, params);
1652
+ }
1653
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1654
+ /**
1655
+ * @method
1656
+ * @name bingx#createMarketBuyOrderWithCost
1657
+ * @description create a market buy order by providing the symbol and cost
1658
+ * @param {string} symbol unified symbol of the market to create an order in
1659
+ * @param {float} cost how much you want to trade in units of the quote currency
1660
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1661
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1662
+ */
1663
+ params['quoteOrderQty'] = cost;
1664
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1665
+ }
1666
+ async createMarketSellOrderWithCost(symbol, cost, params = {}) {
1667
+ /**
1668
+ * @method
1669
+ * @name bingx#createMarketSellOrderWithCost
1670
+ * @description create a market sell order by providing the symbol and cost
1671
+ * @param {string} symbol unified symbol of the market to create an order in
1672
+ * @param {float} cost how much you want to trade in units of the quote currency
1673
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1674
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1675
+ */
1676
+ params['quoteOrderQty'] = cost;
1677
+ return await this.createOrder(symbol, 'market', 'sell', cost, undefined, params);
1678
+ }
1624
1679
  createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
1625
1680
  /**
1626
1681
  * @method
@@ -1656,26 +1711,21 @@ class bingx extends bingx$1 {
1656
1711
  if (postOnly || (timeInForce === 'POC')) {
1657
1712
  request['timeInForce'] = 'POC';
1658
1713
  }
1659
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
1660
- if (isMarketOrder && (side === 'buy')) {
1661
- if (createMarketBuyOrderRequiresPrice) {
1662
- if (price === undefined) {
1663
- throw new errors.InvalidOrder(this.id + ' createOrder() requires price argument for market buy orders on spot markets to calculate the total amount to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to false and pass in the cost to spend into the amount parameter');
1664
- }
1665
- else {
1666
- const amountString = this.numberToString(amount);
1667
- const priceString = this.numberToString(price);
1668
- const cost = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
1669
- request['quoteOrderQty'] = this.parseToNumeric(this.priceToPrecision(symbol, cost));
1670
- }
1714
+ const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1715
+ params = this.omit(params, 'cost');
1716
+ if (cost !== undefined) {
1717
+ request['quoteOrderQty'] = this.parseToNumeric(this.costToPrecision(symbol, cost));
1718
+ }
1719
+ else {
1720
+ if (market['spot'] && isMarketOrder && (price !== undefined)) {
1721
+ // keep the legacy behavior, to avoid breaking the old spot-market-buying code
1722
+ const calculatedCost = Precise["default"].stringMul(this.numberToString(amount), this.numberToString(price));
1723
+ request['quoteOrderQty'] = this.parseToNumeric(calculatedCost);
1671
1724
  }
1672
1725
  else {
1673
- request['quoteOrderQty'] = this.parseToNumeric(this.priceToPrecision(symbol, amount));
1726
+ request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1674
1727
  }
1675
1728
  }
1676
- else {
1677
- request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1678
- }
1679
1729
  if (!isMarketOrder) {
1680
1730
  request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
1681
1731
  }
@@ -1750,8 +1800,7 @@ class bingx extends bingx$1 {
1750
1800
  * @method
1751
1801
  * @name bingx#createOrder
1752
1802
  * @description create a trade order
1753
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Create%20an%20Order
1754
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Trade%20order
1803
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Trade%20order
1755
1804
  * @param {string} symbol unified symbol of the market to create an order in
1756
1805
  * @param {string} type 'market' or 'limit'
1757
1806
  * @param {string} side 'buy' or 'sell'
@@ -1764,6 +1813,7 @@ class bingx extends bingx$1 {
1764
1813
  * @param {float} [params.triggerPrice] *swap only* triggerPrice at which the attached take profit / stop loss order will be triggered
1765
1814
  * @param {float} [params.stopLossPrice] *swap only* stop loss trigger price
1766
1815
  * @param {float} [params.takeProfitPrice] *swap only* take profit trigger price
1816
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount
1767
1817
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1768
1818
  */
1769
1819
  await this.loadMarkets();
@@ -3370,6 +3420,50 @@ class bingx extends bingx$1 {
3370
3420
  'datetime': this.iso8601(timestamp),
3371
3421
  });
3372
3422
  }
3423
+ async closeAllPositions(params = {}) {
3424
+ /**
3425
+ * @method
3426
+ * @name bitget#closePositions
3427
+ * @description closes open positions for a market
3428
+ * @see https://bitgetlimited.github.io/apidoc/en/mix/#close-all-position
3429
+ * @param {object} [params] extra parameters specific to the okx api endpoint
3430
+ * @param {string} [params.recvWindow] request valid time window value
3431
+ * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
3432
+ */
3433
+ await this.loadMarkets();
3434
+ const defaultRecvWindow = this.safeInteger(this.options, 'recvWindow');
3435
+ const recvWindow = this.safeInteger(this.parseParams, 'recvWindow', defaultRecvWindow);
3436
+ let marketType = undefined;
3437
+ [marketType, params] = this.handleMarketTypeAndParams('closeAllPositions', undefined, params);
3438
+ if (marketType === 'margin') {
3439
+ throw new errors.BadRequest(this.id + ' closePositions () cannot be used for ' + marketType + ' markets');
3440
+ }
3441
+ const request = {
3442
+ 'recvWindow': recvWindow,
3443
+ };
3444
+ const response = await this.swapV2PrivatePostTradeCloseAllPositions(this.extend(request, params));
3445
+ //
3446
+ // {
3447
+ // "code": 0,
3448
+ // "msg": "",
3449
+ // "data": {
3450
+ // "success": [
3451
+ // 1727686766700486656,
3452
+ // 1727686767048613888
3453
+ // ],
3454
+ // "failed": null
3455
+ // }
3456
+ // }
3457
+ //
3458
+ const data = this.safeValue(response, 'data', {});
3459
+ const success = this.safeValue(data, 'success', []);
3460
+ const positions = [];
3461
+ for (let i = 0; i < success.length; i++) {
3462
+ const position = this.parsePosition({ 'positionId': success[i] });
3463
+ positions.push(position);
3464
+ }
3465
+ return positions;
3466
+ }
3373
3467
  sign(path, section = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
3374
3468
  const type = section[0];
3375
3469
  const version = section[1];
@@ -29,6 +29,8 @@ class bit2c extends bit2c$1 {
29
29
  'option': false,
30
30
  'addMargin': false,
31
31
  'cancelOrder': true,
32
+ 'closeAllPositions': false,
33
+ 'closePosition': false,
32
34
  'createOrder': true,
33
35
  'createReduceOnlyOrder': false,
34
36
  'fetchBalance': true,
@@ -27,6 +27,8 @@ class bitbank extends bitbank$1 {
27
27
  'option': false,
28
28
  'addMargin': false,
29
29
  'cancelOrder': true,
30
+ 'closeAllPositions': false,
31
+ 'closePosition': false,
30
32
  'createOrder': true,
31
33
  'createReduceOnlyOrder': false,
32
34
  'fetchBalance': true,
@@ -28,6 +28,8 @@ class bithumb extends bithumb$1 {
28
28
  'option': false,
29
29
  'addMargin': false,
30
30
  'cancelOrder': true,
31
+ 'closeAllPositions': false,
32
+ 'closePosition': false,
31
33
  'createMarketOrder': true,
32
34
  'createOrder': true,
33
35
  'createReduceOnlyOrder': false,
@@ -36,6 +36,9 @@ class bitmart extends bitmart$1 {
36
36
  'cancelAllOrders': true,
37
37
  'cancelOrder': true,
38
38
  'cancelOrders': false,
39
+ 'createMarketBuyOrderWithCost': true,
40
+ 'createMarketOrderWithCost': false,
41
+ 'createMarketSellOrderWithCost': false,
39
42
  'createOrder': true,
40
43
  'createPostOnlyOrder': true,
41
44
  'createStopLimitOrder': false,
@@ -2161,12 +2164,31 @@ class bitmart extends bitmart$1 {
2161
2164
  const statuses = this.safeValue(statusesByType, type, {});
2162
2165
  return this.safeString(statuses, status, status);
2163
2166
  }
2167
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
2168
+ /**
2169
+ * @method
2170
+ * @name bitmart#createMarketBuyOrderWithCost
2171
+ * @description create a market buy order by providing the symbol and cost
2172
+ * @see https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
2173
+ * @param {string} symbol unified symbol of the market to create an order in
2174
+ * @param {float} cost how much you want to trade in units of the quote currency
2175
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2176
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2177
+ */
2178
+ await this.loadMarkets();
2179
+ const market = this.market(symbol);
2180
+ if (!market['spot']) {
2181
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
2182
+ }
2183
+ params['createMarketBuyOrderRequiresPrice'] = false;
2184
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
2185
+ }
2164
2186
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
2165
2187
  /**
2166
2188
  * @method
2167
2189
  * @name bitmart#createOrder
2168
2190
  * @description create a trade order
2169
- * @see https://developer-pro.bitmart.com/en/spot/#place-spot-order
2191
+ * @see https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
2170
2192
  * @see https://developer-pro.bitmart.com/en/spot/#place-margin-order
2171
2193
  * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2172
2194
  * @param {string} symbol unified symbol of the market to create an order in
@@ -2343,18 +2365,18 @@ class bitmart extends bitmart$1 {
2343
2365
  else if (isMarketOrder) {
2344
2366
  // for market buy it requires the amount of quote currency to spend
2345
2367
  if (side === 'buy') {
2346
- let notional = this.safeNumber(params, 'notional');
2347
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
2368
+ let notional = this.safeNumber2(params, 'cost', 'notional');
2369
+ params = this.omit(params, 'cost');
2370
+ let createMarketBuyOrderRequiresPrice = true;
2371
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
2348
2372
  if (createMarketBuyOrderRequiresPrice) {
2349
- if (price !== undefined) {
2350
- if (notional === undefined) {
2351
- const amountString = this.numberToString(amount);
2352
- const priceString = this.numberToString(price);
2353
- notional = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
2354
- }
2373
+ if ((price === undefined) && (notional === undefined)) {
2374
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument or in the "notional" extra parameter (the exchange-specific behaviour)');
2355
2375
  }
2356
- else if (notional === undefined) {
2357
- throw new errors.InvalidOrder(this.id + " createOrder () requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = false and supply the total cost value in the 'amount' argument or in the 'notional' extra parameter (the exchange-specific behaviour)");
2376
+ else {
2377
+ const amountString = this.numberToString(amount);
2378
+ const priceString = this.numberToString(price);
2379
+ notional = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
2358
2380
  }
2359
2381
  }
2360
2382
  else {