ccxt 4.1.73 → 4.1.75

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 (53) hide show
  1. package/README.md +6 -8
  2. package/dist/ccxt.browser.js +1108 -1455
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +1 -4
  5. package/dist/cjs/src/base/Exchange.js +31 -4
  6. package/dist/cjs/src/base/ws/Client.js +11 -14
  7. package/dist/cjs/src/bigone.js +38 -9
  8. package/dist/cjs/src/bingx.js +57 -18
  9. package/dist/cjs/src/bitmart.js +33 -11
  10. package/dist/cjs/src/bybit.js +30 -7
  11. package/dist/cjs/src/cex.js +61 -3
  12. package/dist/cjs/src/exmo.js +34 -31
  13. package/dist/cjs/src/gate.js +1 -0
  14. package/dist/cjs/src/gemini.js +21 -19
  15. package/dist/cjs/src/kraken.js +156 -11
  16. package/dist/cjs/src/okx.js +45 -2
  17. package/dist/cjs/src/poloniex.js +27 -25
  18. package/dist/cjs/src/pro/binance.js +60 -8
  19. package/dist/cjs/src/pro/cex.js +317 -10
  20. package/dist/cjs/src/pro/coinbasepro.js +1 -1
  21. package/js/ccxt.d.ts +2 -5
  22. package/js/ccxt.js +2 -4
  23. package/js/src/abstract/kraken.d.ts +2 -0
  24. package/js/src/base/Exchange.d.ts +2 -0
  25. package/js/src/base/Exchange.js +31 -4
  26. package/js/src/base/ws/Client.js +11 -14
  27. package/js/src/bigone.d.ts +1 -0
  28. package/js/src/bigone.js +38 -9
  29. package/js/src/bingx.d.ts +3 -0
  30. package/js/src/bingx.js +58 -19
  31. package/js/src/bitmart.d.ts +1 -0
  32. package/js/src/bitmart.js +33 -11
  33. package/js/src/bybit.d.ts +1 -0
  34. package/js/src/bybit.js +30 -7
  35. package/js/src/cex.d.ts +1 -0
  36. package/js/src/cex.js +61 -3
  37. package/js/src/exmo.d.ts +1 -1
  38. package/js/src/exmo.js +34 -31
  39. package/js/src/gate.js +1 -0
  40. package/js/src/gemini.js +21 -19
  41. package/js/src/kraken.d.ts +2 -0
  42. package/js/src/kraken.js +156 -11
  43. package/js/src/okx.d.ts +2 -0
  44. package/js/src/okx.js +45 -2
  45. package/js/src/poloniex.js +27 -25
  46. package/js/src/pro/binance.d.ts +1 -0
  47. package/js/src/pro/binance.js +61 -9
  48. package/js/src/pro/cex.d.ts +11 -2
  49. package/js/src/pro/cex.js +318 -11
  50. package/js/src/pro/coinbasepro.js +1 -1
  51. package/package.json +1 -1
  52. package/js/src/abstract/tidex.d.ts +0 -28
  53. package/js/src/abstract/tidex.js +0 -11
package/dist/cjs/ccxt.js CHANGED
@@ -101,7 +101,6 @@ var phemex = require('./src/phemex.js');
101
101
  var poloniex = require('./src/poloniex.js');
102
102
  var poloniexfutures = require('./src/poloniexfutures.js');
103
103
  var probit = require('./src/probit.js');
104
- var tidex = require('./src/tidex.js');
105
104
  var timex = require('./src/timex.js');
106
105
  var tokocrypto = require('./src/tokocrypto.js');
107
106
  var upbit = require('./src/upbit.js');
@@ -173,7 +172,7 @@ var woo$1 = require('./src/pro/woo.js');
173
172
 
174
173
  //-----------------------------------------------------------------------------
175
174
  // this is updated by vss.js when building
176
- const version = '4.1.73';
175
+ const version = '4.1.75';
177
176
  Exchange["default"].ccxtVersion = version;
178
177
  const exchanges = {
179
178
  'ace': ace,
@@ -265,7 +264,6 @@ const exchanges = {
265
264
  'poloniex': poloniex,
266
265
  'poloniexfutures': poloniexfutures,
267
266
  'probit': probit,
268
- 'tidex': tidex,
269
267
  'timex': timex,
270
268
  'tokocrypto': tokocrypto,
271
269
  'upbit': upbit,
@@ -467,7 +465,6 @@ exports.phemex = phemex;
467
465
  exports.poloniex = poloniex;
468
466
  exports.poloniexfutures = poloniexfutures;
469
467
  exports.probit = probit;
470
- exports.tidex = tidex;
471
468
  exports.timex = timex;
472
469
  exports.tokocrypto = tokocrypto;
473
470
  exports.upbit = upbit;
@@ -360,6 +360,7 @@ class Exchange {
360
360
  'createMarketOrder': true,
361
361
  'createOrder': true,
362
362
  'createMarketBuyOrderWithCost': undefined,
363
+ 'createMarketOrderWithCost': undefined,
363
364
  'createMarketSellOrderWithCost': undefined,
364
365
  'createOrders': undefined,
365
366
  'createPostOnlyOrder': undefined,
@@ -3560,28 +3561,50 @@ class Exchange {
3560
3561
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
3561
3562
  throw new errors.NotSupported(this.id + ' createOrder() is not supported yet');
3562
3563
  }
3564
+ async createMarketOrderWithCost(symbol, side, cost, params = {}) {
3565
+ /**
3566
+ * @method
3567
+ * @name createMarketOrderWithCost
3568
+ * @description create a market order by providing the symbol, side and cost
3569
+ * @param {string} symbol unified symbol of the market to create an order in
3570
+ * @param {string} side 'buy' or 'sell'
3571
+ * @param {float} cost how much you want to trade in units of the quote currency
3572
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3573
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3574
+ */
3575
+ if (this.options['createMarketOrderWithCost'] || (this.options['createMarketBuyOrderWithCost'] && this.options['createMarketSellOrderWithCost'])) {
3576
+ return await this.createOrder(symbol, 'market', side, cost, 1, params);
3577
+ }
3578
+ throw new errors.NotSupported(this.id + ' createMarketOrderWithCost() is not supported yet');
3579
+ }
3563
3580
  async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
3564
3581
  /**
3565
3582
  * @method
3566
- * @name createMarketBuyWithCost
3583
+ * @name createMarketBuyOrderWithCost
3567
3584
  * @description create a market buy order by providing the symbol and cost
3568
3585
  * @param {string} symbol unified symbol of the market to create an order in
3569
3586
  * @param {float} cost how much you want to trade in units of the quote currency
3570
3587
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3571
3588
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3572
3589
  */
3590
+ if (this.options['createMarketBuyOrderRequiresPrice'] || this.options['createMarketBuyOrderWithCost']) {
3591
+ return await this.createOrder(symbol, 'market', 'buy', cost, 1, params);
3592
+ }
3573
3593
  throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() is not supported yet');
3574
3594
  }
3575
3595
  async createMarketSellOrderWithCost(symbol, cost, params = {}) {
3576
3596
  /**
3577
3597
  * @method
3578
3598
  * @name createMarketSellOrderWithCost
3579
- * @description create a market buy order by providing the symbol and cost
3599
+ * @description create a market sell order by providing the symbol and cost
3580
3600
  * @param {string} symbol unified symbol of the market to create an order in
3581
3601
  * @param {float} cost how much you want to trade in units of the quote currency
3582
3602
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3583
3603
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3584
3604
  */
3605
+ if (this.options['createMarketSellOrderRequiresPrice'] || this.options['createMarketSellOrderWithCost']) {
3606
+ return await this.createOrder(symbol, 'market', 'sell', cost, 1, params);
3607
+ }
3585
3608
  throw new errors.NotSupported(this.id + ' createMarketSellOrderWithCost() is not supported yet');
3586
3609
  }
3587
3610
  async createOrders(orders, params = {}) {
@@ -4666,6 +4689,10 @@ class Exchange {
4666
4689
  if (cursorValue === undefined) {
4667
4690
  break;
4668
4691
  }
4692
+ const lastTimestamp = this.safeInteger(last, 'timestamp');
4693
+ if (lastTimestamp !== undefined && lastTimestamp < since) {
4694
+ break;
4695
+ }
4669
4696
  }
4670
4697
  catch (e) {
4671
4698
  errors += 1;
@@ -4718,10 +4745,10 @@ class Exchange {
4718
4745
  const first = this.safeValue(result, 0);
4719
4746
  if (first !== undefined) {
4720
4747
  if ('timestamp' in first) {
4721
- return this.sortBy(result, 'timestamp');
4748
+ return this.sortBy(result, 'timestamp', true);
4722
4749
  }
4723
4750
  if ('id' in first) {
4724
- return this.sortBy(result, 'id');
4751
+ return this.sortBy(result, 'id', true);
4725
4752
  }
4726
4753
  }
4727
4754
  return result;
@@ -251,23 +251,20 @@ class Client {
251
251
  // 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
252
  let message = messageEvent.data;
253
253
  let arrayBuffer;
254
- if (this.gunzip || this.inflate) {
255
- if (typeof message === 'string') {
256
- arrayBuffer = index.utf8.decode(message);
257
- }
258
- else {
254
+ if (typeof message !== 'string') {
255
+ if (this.gunzip || this.inflate) {
259
256
  arrayBuffer = new Uint8Array(message.buffer.slice(message.byteOffset, message.byteOffset + message.byteLength));
257
+ if (this.gunzip) {
258
+ arrayBuffer = browser.gunzipSync(arrayBuffer);
259
+ }
260
+ else if (this.inflate) {
261
+ arrayBuffer = browser.inflateSync(arrayBuffer);
262
+ }
263
+ message = index.utf8.encode(arrayBuffer);
260
264
  }
261
- if (this.gunzip) {
262
- arrayBuffer = browser.gunzipSync(arrayBuffer);
263
- }
264
- else if (this.inflate) {
265
- arrayBuffer = browser.inflateSync(arrayBuffer);
265
+ else {
266
+ message = message.toString();
266
267
  }
267
- message = index.utf8.encode(arrayBuffer);
268
- }
269
- if (typeof message !== 'string') {
270
- message = message.toString();
271
268
  }
272
269
  try {
273
270
  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';
@@ -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,
@@ -1621,6 +1624,46 @@ class bingx extends bingx$1 {
1621
1624
  'takeProfitPrice': undefined,
1622
1625
  });
1623
1626
  }
1627
+ async createMarketOrderWithCost(symbol, side, cost, params = {}) {
1628
+ /**
1629
+ * @method
1630
+ * @name bingx#createMarketOrderWithCost
1631
+ * @description create a market order by providing the symbol, side and cost
1632
+ * @param {string} symbol unified symbol of the market to create an order in
1633
+ * @param {string} side 'buy' or 'sell'
1634
+ * @param {float} cost how much you want to trade in units of the quote currency
1635
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1636
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1637
+ */
1638
+ params['quoteOrderQty'] = cost;
1639
+ return await this.createOrder(symbol, 'market', side, cost, undefined, params);
1640
+ }
1641
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1642
+ /**
1643
+ * @method
1644
+ * @name bingx#createMarketBuyOrderWithCost
1645
+ * @description create a market buy order by providing the symbol and cost
1646
+ * @param {string} symbol unified symbol of the market to create an order in
1647
+ * @param {float} cost how much you want to trade in units of the quote currency
1648
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1649
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1650
+ */
1651
+ params['quoteOrderQty'] = cost;
1652
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1653
+ }
1654
+ async createMarketSellOrderWithCost(symbol, cost, params = {}) {
1655
+ /**
1656
+ * @method
1657
+ * @name bingx#createMarketSellOrderWithCost
1658
+ * @description create a market sell order by providing the symbol and cost
1659
+ * @param {string} symbol unified symbol of the market to create an order in
1660
+ * @param {float} cost how much you want to trade in units of the quote currency
1661
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1662
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1663
+ */
1664
+ params['quoteOrderQty'] = cost;
1665
+ return await this.createOrder(symbol, 'market', 'sell', cost, undefined, params);
1666
+ }
1624
1667
  createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
1625
1668
  /**
1626
1669
  * @method
@@ -1656,26 +1699,21 @@ class bingx extends bingx$1 {
1656
1699
  if (postOnly || (timeInForce === 'POC')) {
1657
1700
  request['timeInForce'] = 'POC';
1658
1701
  }
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
- }
1702
+ const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1703
+ params = this.omit(params, 'cost');
1704
+ if (cost !== undefined) {
1705
+ request['quoteOrderQty'] = this.parseToNumeric(this.costToPrecision(symbol, cost));
1706
+ }
1707
+ else {
1708
+ if (market['spot'] && isMarketOrder && (price !== undefined)) {
1709
+ // keep the legacy behavior, to avoid breaking the old spot-market-buying code
1710
+ const calculatedCost = Precise["default"].stringMul(this.numberToString(amount), this.numberToString(price));
1711
+ request['quoteOrderQty'] = this.parseToNumeric(calculatedCost);
1671
1712
  }
1672
1713
  else {
1673
- request['quoteOrderQty'] = this.parseToNumeric(this.priceToPrecision(symbol, amount));
1714
+ request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1674
1715
  }
1675
1716
  }
1676
- else {
1677
- request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1678
- }
1679
1717
  if (!isMarketOrder) {
1680
1718
  request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
1681
1719
  }
@@ -1750,8 +1788,8 @@ class bingx extends bingx$1 {
1750
1788
  * @method
1751
1789
  * @name bingx#createOrder
1752
1790
  * @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
1791
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Create%20an%20Order
1792
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Trade%20order
1755
1793
  * @param {string} symbol unified symbol of the market to create an order in
1756
1794
  * @param {string} type 'market' or 'limit'
1757
1795
  * @param {string} side 'buy' or 'sell'
@@ -1764,6 +1802,7 @@ class bingx extends bingx$1 {
1764
1802
  * @param {float} [params.triggerPrice] *swap only* triggerPrice at which the attached take profit / stop loss order will be triggered
1765
1803
  * @param {float} [params.stopLossPrice] *swap only* stop loss trigger price
1766
1804
  * @param {float} [params.takeProfitPrice] *swap only* take profit trigger price
1805
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount
1767
1806
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1768
1807
  */
1769
1808
  await this.loadMarkets();
@@ -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 {
@@ -35,6 +35,8 @@ class bybit extends bybit$1 {
35
35
  'borrowCrossMargin': true,
36
36
  'cancelAllOrders': true,
37
37
  'cancelOrder': true,
38
+ 'createMarketBuyOrderWithCost': true,
39
+ 'createMarketSellOrderWithCost': false,
38
40
  'createOrder': true,
39
41
  'createOrders': true,
40
42
  'createPostOnlyOrder': true,
@@ -3446,6 +3448,25 @@ class bybit extends bybit$1 {
3446
3448
  }
3447
3449
  return this.safeValue(result, 0);
3448
3450
  }
3451
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
3452
+ /**
3453
+ * @method
3454
+ * @name bybit#createMarketBuyOrderWithCost
3455
+ * @see https://bybit-exchange.github.io/docs/v5/order/create-order
3456
+ * @description create a market buy order by providing the symbol and cost
3457
+ * @param {string} symbol unified symbol of the market to create an order in
3458
+ * @param {float} cost how much you want to trade in units of the quote currency
3459
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3460
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3461
+ */
3462
+ await this.loadMarkets();
3463
+ const market = this.market(symbol);
3464
+ if (!market['spot']) {
3465
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
3466
+ }
3467
+ params['createMarketBuyOrderRequiresPrice'] = false;
3468
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
3469
+ }
3449
3470
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
3450
3471
  /**
3451
3472
  * @method
@@ -3546,18 +3567,20 @@ class bybit extends bybit$1 {
3546
3567
  }
3547
3568
  if (market['spot'] && (type === 'market') && (side === 'buy')) {
3548
3569
  // for market buy it requires the amount of quote currency to spend
3549
- if (this.options['createMarketBuyOrderRequiresPrice']) {
3550
- const cost = this.safeNumber(params, 'cost');
3551
- params = this.omit(params, 'cost');
3552
- if (price === undefined && cost === undefined) {
3553
- 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 to supply the cost in the amount argument (the exchange-specific behaviour)');
3570
+ let createMarketBuyOrderRequiresPrice = true;
3571
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
3572
+ const cost = this.safeNumber(params, 'cost');
3573
+ params = this.omit(params, 'cost');
3574
+ if (createMarketBuyOrderRequiresPrice) {
3575
+ if ((price === undefined) && (cost === undefined)) {
3576
+ 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');
3554
3577
  }
3555
3578
  else {
3556
3579
  const amountString = this.numberToString(amount);
3557
3580
  const priceString = this.numberToString(price);
3558
3581
  const quoteAmount = Precise["default"].stringMul(amountString, priceString);
3559
- amount = (cost !== undefined) ? cost : this.parseNumber(quoteAmount);
3560
- request['qty'] = this.costToPrecision(symbol, amount);
3582
+ const costRequest = (cost !== undefined) ? cost : quoteAmount;
3583
+ request['qty'] = this.costToPrecision(symbol, costRequest);
3561
3584
  }
3562
3585
  }
3563
3586
  else {