ccxt 4.1.83 → 4.1.85

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.
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.83';
175
+ const version = '4.1.85';
176
176
  Exchange["default"].ccxtVersion = version;
177
177
  const exchanges = {
178
178
  'ace': ace,
@@ -3706,6 +3706,9 @@ class Exchange {
3706
3706
  async closeAllPositions(params = {}) {
3707
3707
  throw new errors.NotSupported(this.id + ' closeAllPositions() is not supported yet');
3708
3708
  }
3709
+ async fetchL3OrderBook(symbol, limit = undefined, params = {}) {
3710
+ throw new errors.BadRequest(this.id + ' fetchL3OrderBook() is not supported yet');
3711
+ }
3709
3712
  parseLastPrice(price, market = undefined) {
3710
3713
  throw new errors.NotSupported(this.id + ' parseLastPrice() is not supported yet');
3711
3714
  }
@@ -8604,7 +8604,7 @@ class binance extends binance$1 {
8604
8604
  extendedParams = this.omit(extendedParams, ['orderidlist', 'origclientorderidlist']);
8605
8605
  query = this.rawencode(extendedParams);
8606
8606
  const orderidlistLength = orderidlist.length;
8607
- const origclientorderidlistLength = orderidlist.length;
8607
+ const origclientorderidlistLength = origclientorderidlist.length;
8608
8608
  if (orderidlistLength > 0) {
8609
8609
  query = query + '&' + 'orderidlist=[' + orderidlist.join(',') + ']';
8610
8610
  }
@@ -2012,6 +2012,9 @@ class bingx extends bingx$1 {
2012
2012
  const positionSide = this.safeString2(order, 'positionSide', 'ps');
2013
2013
  const marketType = (positionSide === undefined) ? 'spot' : 'swap';
2014
2014
  const marketId = this.safeString2(order, 'symbol', 's');
2015
+ if (market === undefined) {
2016
+ market = this.safeMarket(marketId, undefined, undefined, marketType);
2017
+ }
2015
2018
  const symbol = this.safeSymbol(marketId, market, '-', marketType);
2016
2019
  const orderId = this.safeString2(order, 'orderId', 'i');
2017
2020
  const side = this.safeStringLower2(order, 'side', 'S');
@@ -2377,16 +2380,15 @@ class bingx extends bingx$1 {
2377
2380
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2378
2381
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2379
2382
  */
2380
- if (symbol === undefined) {
2381
- throw new errors.ArgumentsRequired(this.id + ' fetchOrders() requires a symbol argument');
2382
- }
2383
2383
  await this.loadMarkets();
2384
- const market = this.market(symbol);
2385
- const request = {
2386
- 'symbol': market['id'],
2387
- };
2384
+ let market = undefined;
2385
+ const request = {};
2386
+ if (symbol !== undefined) {
2387
+ market = this.market(symbol);
2388
+ request['symbol'] = market['id'];
2389
+ }
2388
2390
  let response = undefined;
2389
- const [marketType, query] = this.handleMarketTypeAndParams('fetchOrder', market, params);
2391
+ const [marketType, query] = this.handleMarketTypeAndParams('fetchOpenOrders', market, params);
2390
2392
  if (marketType === 'spot') {
2391
2393
  response = await this.spotV1PrivateGetTradeOpenOrders(this.extend(request, query));
2392
2394
  }
@@ -945,11 +945,11 @@ class bithumb extends bithumb$1 {
945
945
  };
946
946
  return await this.privatePostTradeCancel(this.extend(request, params));
947
947
  }
948
- cancelUnifiedOrder(order, params = {}) {
948
+ async cancelUnifiedOrder(order, params = {}) {
949
949
  const request = {
950
950
  'side': order['side'],
951
951
  };
952
- return this.cancelOrder(order['id'], order['symbol'], this.extend(request, params));
952
+ return await this.cancelOrder(order['id'], order['symbol'], this.extend(request, params));
953
953
  }
954
954
  async withdraw(code, amount, address, tag = undefined, params = {}) {
955
955
  /**
@@ -1334,48 +1334,58 @@ class bitmart extends bitmart$1 {
1334
1334
  //
1335
1335
  // public fetchTrades spot ( amount = count * price )
1336
1336
  //
1337
- // {
1338
- // "amount": "818.94",
1339
- // "order_time": "1637601839035", // ETH/USDT
1340
- // "price": "4221.99",
1341
- // "count": "0.19397",
1342
- // "type": "buy"
1343
- // }
1337
+ // {
1338
+ // "amount": "818.94",
1339
+ // "order_time": "1637601839035", // ETH/USDT
1340
+ // "price": "4221.99",
1341
+ // "count": "0.19397",
1342
+ // "type": "buy"
1343
+ // }
1344
1344
  //
1345
1345
  // spot: fetchMyTrades
1346
1346
  //
1347
- // {
1348
- // "tradeId":"182342999769370687",
1349
- // "orderId":"183270218784142990",
1350
- // "clientOrderId":"183270218784142990",
1351
- // "symbol":"ADA_USDT",
1352
- // "side":"buy",
1353
- // "orderMode":"spot",
1354
- // "type":"market",
1355
- // "price":"0.245948",
1356
- // "size":"20.71",
1357
- // "notional":"5.09358308",
1358
- // "fee":"0.00509358",
1359
- // "feeCoinName":"USDT",
1360
- // "tradeRole":"taker",
1361
- // "createTime":1695658457836,
1362
- // }
1347
+ // {
1348
+ // "tradeId":"182342999769370687",
1349
+ // "orderId":"183270218784142990",
1350
+ // "clientOrderId":"183270218784142990",
1351
+ // "symbol":"ADA_USDT",
1352
+ // "side":"buy",
1353
+ // "orderMode":"spot",
1354
+ // "type":"market",
1355
+ // "price":"0.245948",
1356
+ // "size":"20.71",
1357
+ // "notional":"5.09358308",
1358
+ // "fee":"0.00509358",
1359
+ // "feeCoinName":"USDT",
1360
+ // "tradeRole":"taker",
1361
+ // "createTime":1695658457836,
1362
+ // }
1363
1363
  //
1364
1364
  // swap: fetchMyTrades
1365
1365
  //
1366
- // {
1367
- // "order_id": "230930336848609",
1368
- // "trade_id": "6212604014",
1369
- // "symbol": "BTCUSDT",
1370
- // "side": 3,
1371
- // "price": "26910.4",
1372
- // "vol": "1",
1373
- // "exec_type": "Taker",
1374
- // "profit": false,
1375
- // "create_time": 1695961596692,
1376
- // "realised_profit": "-0.0003",
1377
- // "paid_fees": "0.01614624"
1378
- // }
1366
+ // {
1367
+ // "order_id": "230930336848609",
1368
+ // "trade_id": "6212604014",
1369
+ // "symbol": "BTCUSDT",
1370
+ // "side": 3,
1371
+ // "price": "26910.4",
1372
+ // "vol": "1",
1373
+ // "exec_type": "Taker",
1374
+ // "profit": false,
1375
+ // "create_time": 1695961596692,
1376
+ // "realised_profit": "-0.0003",
1377
+ // "paid_fees": "0.01614624"
1378
+ // }
1379
+ //
1380
+ // ws swap
1381
+ //
1382
+ // {
1383
+ // 'fee': '-0.000044502',
1384
+ // 'feeCcy': 'USDT',
1385
+ // 'fillPrice': '74.17',
1386
+ // 'fillQty': '1',
1387
+ // 'lastTradeID': 6802340762
1388
+ // }
1379
1389
  //
1380
1390
  const timestamp = this.safeIntegerN(trade, ['order_time', 'createTime', 'create_time']);
1381
1391
  const isPublicTrade = ('order_time' in trade);
@@ -1389,7 +1399,7 @@ class bitmart extends bitmart$1 {
1389
1399
  side = this.safeString(trade, 'type');
1390
1400
  }
1391
1401
  else {
1392
- amount = this.safeString2(trade, 'size', 'vol');
1402
+ amount = this.safeStringN(trade, ['size', 'vol', 'fillQty']);
1393
1403
  cost = this.safeString(trade, 'notional');
1394
1404
  type = this.safeString(trade, 'type');
1395
1405
  side = this.parseOrderSide(this.safeString(trade, 'side'));
@@ -1411,14 +1421,14 @@ class bitmart extends bitmart$1 {
1411
1421
  }
1412
1422
  return this.safeTrade({
1413
1423
  'info': trade,
1414
- 'id': this.safeString2(trade, 'tradeId', 'trade_id'),
1424
+ 'id': this.safeStringN(trade, ['tradeId', 'trade_id', 'lastTradeID']),
1415
1425
  'order': this.safeString2(trade, 'orderId', 'order_id'),
1416
1426
  'timestamp': timestamp,
1417
1427
  'datetime': this.iso8601(timestamp),
1418
1428
  'symbol': market['symbol'],
1419
1429
  'type': type,
1420
1430
  'side': side,
1421
- 'price': this.safeString(trade, 'price'),
1431
+ 'price': this.safeString2(trade, 'price', 'fillPrice'),
1422
1432
  'amount': amount,
1423
1433
  'cost': cost,
1424
1434
  'takerOrMaker': this.safeStringLower2(trade, 'tradeRole', 'exec_type'),
@@ -1472,38 +1482,45 @@ class bitmart extends bitmart$1 {
1472
1482
  parseOHLCV(ohlcv, market = undefined) {
1473
1483
  //
1474
1484
  // spot
1475
- //
1476
- // [
1477
- // "1699512060", // timestamp
1478
- // "36746.49", // open
1479
- // "36758.71", // high
1480
- // "36736.13", // low
1481
- // "36755.99", // close
1482
- // "2.83965", // base volume
1483
- // "104353.57" // quote volume
1484
- // ]
1485
+ // [
1486
+ // "1699512060", // timestamp
1487
+ // "36746.49", // open
1488
+ // "36758.71", // high
1489
+ // "36736.13", // low
1490
+ // "36755.99", // close
1491
+ // "2.83965", // base volume
1492
+ // "104353.57" // quote volume
1493
+ // ]
1485
1494
  //
1486
1495
  // swap
1487
- //
1488
- // {
1489
- // "low_price": "20090.3",
1490
- // "high_price": "20095.5",
1491
- // "open_price": "20092.6",
1492
- // "close_price": "20091.4",
1493
- // "volume": "8748",
1494
- // "timestamp": 1665002281
1495
- // }
1496
+ // {
1497
+ // "low_price": "20090.3",
1498
+ // "high_price": "20095.5",
1499
+ // "open_price": "20092.6",
1500
+ // "close_price": "20091.4",
1501
+ // "volume": "8748",
1502
+ // "timestamp": 1665002281
1503
+ // }
1496
1504
  //
1497
1505
  // ws
1498
- //
1499
- // [
1500
- // 1631056350, // timestamp
1501
- // "46532.83", // open
1502
- // "46555.71", // high
1503
- // "46511.41", // low
1504
- // "46555.71", // close
1505
- // "0.25", // volume
1506
- // ]
1506
+ // [
1507
+ // 1631056350, // timestamp
1508
+ // "46532.83", // open
1509
+ // "46555.71", // high
1510
+ // "46511.41", // low
1511
+ // "46555.71", // close
1512
+ // "0.25", // volume
1513
+ // ]
1514
+ //
1515
+ // ws swap
1516
+ // {
1517
+ // "symbol":"BTCUSDT",
1518
+ // "o":"146.24",
1519
+ // "h":"146.24",
1520
+ // "l":"146.24",
1521
+ // "c":"146.24",
1522
+ // "v":"146"
1523
+ // }
1507
1524
  //
1508
1525
  if (Array.isArray(ohlcv)) {
1509
1526
  return [
@@ -1517,12 +1534,12 @@ class bitmart extends bitmart$1 {
1517
1534
  }
1518
1535
  else {
1519
1536
  return [
1520
- this.safeTimestamp(ohlcv, 'timestamp'),
1521
- this.safeNumber(ohlcv, 'open_price'),
1522
- this.safeNumber(ohlcv, 'high_price'),
1523
- this.safeNumber(ohlcv, 'low_price'),
1524
- this.safeNumber(ohlcv, 'close_price'),
1525
- this.safeNumber(ohlcv, 'volume'),
1537
+ this.safeTimestamp2(ohlcv, 'timestamp', 'ts'),
1538
+ this.safeNumber2(ohlcv, 'open_price', 'o'),
1539
+ this.safeNumber2(ohlcv, 'high_price', 'h'),
1540
+ this.safeNumber2(ohlcv, 'low_price', 'l'),
1541
+ this.safeNumber2(ohlcv, 'close_price', 'c'),
1542
+ this.safeNumber2(ohlcv, 'volume', 'v'),
1526
1543
  ];
1527
1544
  }
1528
1545
  }
@@ -1253,11 +1253,11 @@ class bitopro extends bitopro$1 {
1253
1253
  //
1254
1254
  return this.parseOrders(orders, market, since, limit);
1255
1255
  }
1256
- fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1256
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1257
1257
  const request = {
1258
1258
  'statusKind': 'OPEN',
1259
1259
  };
1260
- return this.fetchOrders(symbol, since, limit, this.extend(request, params));
1260
+ return await this.fetchOrders(symbol, since, limit, this.extend(request, params));
1261
1261
  }
1262
1262
  async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1263
1263
  /**
@@ -5742,9 +5742,11 @@ class bybit extends bybit$1 {
5742
5742
  else if (symbolsLength === 1) {
5743
5743
  symbol = symbols[0];
5744
5744
  }
5745
+ symbols = this.marketSymbols(symbols);
5745
5746
  }
5746
5747
  else if (symbols !== undefined) {
5747
5748
  symbol = symbols;
5749
+ symbols = [this.symbol(symbol)];
5748
5750
  }
5749
5751
  await this.loadMarkets();
5750
5752
  const [enableUnifiedMargin, enableUnifiedAccount] = await this.isUnifiedEnabled();
@@ -5754,14 +5756,12 @@ class bybit extends bybit$1 {
5754
5756
  let isUsdcSettled = false;
5755
5757
  if (symbol !== undefined) {
5756
5758
  market = this.market(symbol);
5759
+ symbol = market['symbol'];
5757
5760
  request['symbol'] = market['id'];
5758
5761
  isUsdcSettled = market['settle'] === 'USDC';
5759
5762
  }
5760
5763
  let type = undefined;
5761
5764
  [type, params] = this.getBybitType('fetchPositions', market, params);
5762
- if (type === 'spot') {
5763
- throw new errors.NotSupported(this.id + ' fetchPositions() not support spot market');
5764
- }
5765
5765
  if (type === 'linear' || type === 'inverse') {
5766
5766
  const baseCoin = this.safeString(params, 'baseCoin');
5767
5767
  if (type === 'linear') {
@@ -30,6 +30,7 @@ class coinex extends coinex$1 {
30
30
  // 20 per 2 seconds => 10 per second => weight = 40
31
31
  'rateLimit': 2.5,
32
32
  'pro': true,
33
+ 'certified': true,
33
34
  'has': {
34
35
  'CORS': undefined,
35
36
  'spot': true,
@@ -35,6 +35,9 @@ class coinsph extends coinsph$1 {
35
35
  'closeAllPositions': false,
36
36
  'closePosition': false,
37
37
  'createDepositAddress': false,
38
+ 'createMarketBuyOrderWithCost': true,
39
+ 'createMarketOrderWithCost': false,
40
+ 'createMarketSellOrderWithCost': false,
38
41
  'createOrder': true,
39
42
  'createPostOnlyOrder': false,
40
43
  'createReduceOnlyOrder': false,
@@ -1062,12 +1065,14 @@ class coinsph extends coinsph$1 {
1062
1065
  * @method
1063
1066
  * @name coinsph#createOrder
1064
1067
  * @description create a trade order
1068
+ * @see https://coins-docs.github.io/rest-api/#new-order--trade
1065
1069
  * @param {string} symbol unified symbol of the market to create an order in
1066
1070
  * @param {string} type 'market', 'limit', 'stop_loss', 'take_profit', 'stop_loss_limit', 'take_profit_limit' or 'limit_maker'
1067
1071
  * @param {string} side 'buy' or 'sell'
1068
1072
  * @param {float} amount how much of currency you want to trade in units of base currency
1069
1073
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1070
1074
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1075
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
1071
1076
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1072
1077
  */
1073
1078
  // todo: add test order low priority
@@ -1103,24 +1108,29 @@ class coinsph extends coinsph$1 {
1103
1108
  request['quantity'] = this.amountToPrecision(symbol, amount);
1104
1109
  }
1105
1110
  else if (orderSide === 'BUY') {
1106
- const quoteOrderQty = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1107
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
1108
- if (quoteOrderQty !== undefined) {
1109
- amount = quoteOrderQty;
1111
+ let quoteAmount = undefined;
1112
+ let createMarketBuyOrderRequiresPrice = true;
1113
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1114
+ const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1115
+ params = this.omit(params, 'cost');
1116
+ if (cost !== undefined) {
1117
+ quoteAmount = this.costToPrecision(symbol, cost);
1110
1118
  }
1111
1119
  else if (createMarketBuyOrderRequiresPrice) {
1112
1120
  if (price === undefined) {
1113
- 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)");
1121
+ 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');
1114
1122
  }
1115
1123
  else {
1116
1124
  const amountString = this.numberToString(amount);
1117
1125
  const priceString = this.numberToString(price);
1118
- const quoteAmount = Precise["default"].stringMul(amountString, priceString);
1119
- amount = this.parseNumber(quoteAmount);
1126
+ const costRequest = Precise["default"].stringMul(amountString, priceString);
1127
+ quoteAmount = this.costToPrecision(symbol, costRequest);
1120
1128
  }
1121
1129
  }
1122
- request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
1123
- params = this.omit(params, 'cost', 'quoteOrderQty');
1130
+ else {
1131
+ quoteAmount = this.costToPrecision(symbol, amount);
1132
+ }
1133
+ request['quoteOrderQty'] = quoteAmount;
1124
1134
  }
1125
1135
  }
1126
1136
  if (orderType === 'STOP_LOSS' || orderType === 'STOP_LOSS_LIMIT' || orderType === 'TAKE_PROFIT' || orderType === 'TAKE_PROFIT_LIMIT') {
@@ -38,6 +38,9 @@ class htx extends htx$1 {
38
38
  'cancelOrder': true,
39
39
  'cancelOrders': true,
40
40
  'createDepositAddress': undefined,
41
+ 'createMarketBuyOrderWithCost': true,
42
+ 'createMarketOrderWithCost': false,
43
+ 'createMarketSellOrderWithCost': false,
41
44
  'createOrder': true,
42
45
  'createOrders': true,
43
46
  'createReduceOnlyOrder': false,
@@ -4840,6 +4843,25 @@ class htx extends htx$1 {
4840
4843
  'trades': trades,
4841
4844
  }, market);
4842
4845
  }
4846
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
4847
+ /**
4848
+ * @method
4849
+ * @name htx#createMarketBuyOrderWithCost
4850
+ * @description create a market buy order by providing the symbol and cost
4851
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec4ee16-7773-11ed-9966-0242ac110003
4852
+ * @param {string} symbol unified symbol of the market to create an order in
4853
+ * @param {float} cost how much you want to trade in units of the quote currency
4854
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4855
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4856
+ */
4857
+ await this.loadMarkets();
4858
+ const market = this.market(symbol);
4859
+ if (!market['spot']) {
4860
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
4861
+ }
4862
+ params['createMarketBuyOrderRequiresPrice'] = false;
4863
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
4864
+ }
4843
4865
  async createSpotOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
4844
4866
  /**
4845
4867
  * @method
@@ -4853,6 +4875,7 @@ class htx extends htx$1 {
4853
4875
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
4854
4876
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4855
4877
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
4878
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
4856
4879
  * @returns {object} request to be sent to the exchange
4857
4880
  */
4858
4881
  await this.loadMarkets();
@@ -4927,9 +4950,17 @@ class htx extends htx$1 {
4927
4950
  request['source'] = 'c2c-margin-api';
4928
4951
  }
4929
4952
  if ((orderType === 'market') && (side === 'buy')) {
4930
- if (this.options['createMarketBuyOrderRequiresPrice']) {
4953
+ let quoteAmount = undefined;
4954
+ let createMarketBuyOrderRequiresPrice = true;
4955
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
4956
+ const cost = this.safeNumber(params, 'cost');
4957
+ params = this.omit(params, 'cost');
4958
+ if (cost !== undefined) {
4959
+ quoteAmount = this.amountToPrecision(symbol, cost);
4960
+ }
4961
+ else if (createMarketBuyOrderRequiresPrice) {
4931
4962
  if (price === undefined) {
4932
- throw new errors.InvalidOrder(this.id + " market buy order requires price argument to calculate cost (total amount of quote currency to spend for buying, amount * price). To switch off this warning exception and specify cost in the amount argument, set .options['createMarketBuyOrderRequiresPrice'] = false. Make sure you know what you're doing.");
4963
+ 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');
4933
4964
  }
4934
4965
  else {
4935
4966
  // despite that cost = amount * price is in quote currency and should have quote precision
@@ -4940,12 +4971,13 @@ class htx extends htx$1 {
4940
4971
  // we use amountToPrecision here because the exchange requires cost in base precision
4941
4972
  const amountString = this.numberToString(amount);
4942
4973
  const priceString = this.numberToString(price);
4943
- request['amount'] = this.costToPrecision(symbol, Precise["default"].stringMul(amountString, priceString));
4974
+ quoteAmount = this.amountToPrecision(symbol, Precise["default"].stringMul(amountString, priceString));
4944
4975
  }
4945
4976
  }
4946
4977
  else {
4947
- request['amount'] = this.costToPrecision(symbol, amount);
4978
+ quoteAmount = this.amountToPrecision(symbol, amount);
4948
4979
  }
4980
+ request['amount'] = quoteAmount;
4949
4981
  }
4950
4982
  else {
4951
4983
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -5077,6 +5109,7 @@ class htx extends htx$1 {
5077
5109
  * @param {bool} [params.postOnly] *contract only* true or false
5078
5110
  * @param {int} [params.leverRate] *contract only* required for all contract orders except tpsl, leverage greater than 20x requires prior approval of high-leverage agreement
5079
5111
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
5112
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
5080
5113
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
5081
5114
  */
5082
5115
  await this.loadMarkets();
@@ -34,6 +34,9 @@ class huobijp extends huobijp$1 {
34
34
  'cancelAllOrders': true,
35
35
  'cancelOrder': true,
36
36
  'cancelOrders': true,
37
+ 'createMarketBuyOrderWithCost': true,
38
+ 'createMarketOrderWithCost': false,
39
+ 'createMarketSellOrderWithCost': false,
37
40
  'createOrder': true,
38
41
  'createStopLimitOrder': false,
39
42
  'createStopMarketOrder': false,
@@ -1358,6 +1361,24 @@ class huobijp extends huobijp$1 {
1358
1361
  'trades': undefined,
1359
1362
  }, market);
1360
1363
  }
1364
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1365
+ /**
1366
+ * @method
1367
+ * @name huobijp#createMarketBuyOrderWithCost
1368
+ * @description create a market buy order by providing the symbol and cost
1369
+ * @param {string} symbol unified symbol of the market to create an order in
1370
+ * @param {float} cost how much you want to trade in units of the quote currency
1371
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1372
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1373
+ */
1374
+ await this.loadMarkets();
1375
+ const market = this.market(symbol);
1376
+ if (!market['spot']) {
1377
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
1378
+ }
1379
+ params['createMarketBuyOrderRequiresPrice'] = false;
1380
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1381
+ }
1361
1382
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1362
1383
  /**
1363
1384
  * @method
@@ -1390,9 +1411,17 @@ class huobijp extends huobijp$1 {
1390
1411
  }
1391
1412
  params = this.omit(params, ['clientOrderId', 'client-order-id']);
1392
1413
  if ((type === 'market') && (side === 'buy')) {
1393
- if (this.options['createMarketBuyOrderRequiresPrice']) {
1414
+ let quoteAmount = undefined;
1415
+ let createMarketBuyOrderRequiresPrice = true;
1416
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1417
+ const cost = this.safeNumber(params, 'cost');
1418
+ params = this.omit(params, 'cost');
1419
+ if (cost !== undefined) {
1420
+ quoteAmount = this.amountToPrecision(symbol, cost);
1421
+ }
1422
+ else if (createMarketBuyOrderRequiresPrice) {
1394
1423
  if (price === undefined) {
1395
- throw new errors.InvalidOrder(this.id + " market buy order requires price argument to calculate cost (total amount of quote currency to spend for buying, amount * price). To switch off this warning exception and specify cost in the amount argument, set .options['createMarketBuyOrderRequiresPrice'] = false. Make sure you know what you're doing.");
1424
+ 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');
1396
1425
  }
1397
1426
  else {
1398
1427
  // despite that cost = amount * price is in quote currency and should have quote precision
@@ -1403,13 +1432,13 @@ class huobijp extends huobijp$1 {
1403
1432
  // we use amountToPrecision here because the exchange requires cost in base precision
1404
1433
  const amountString = this.numberToString(amount);
1405
1434
  const priceString = this.numberToString(price);
1406
- const baseAmount = Precise["default"].stringMul(amountString, priceString);
1407
- request['amount'] = this.costToPrecision(symbol, baseAmount);
1435
+ quoteAmount = this.amountToPrecision(symbol, Precise["default"].stringMul(amountString, priceString));
1408
1436
  }
1409
1437
  }
1410
1438
  else {
1411
- request['amount'] = this.costToPrecision(symbol, amount);
1439
+ quoteAmount = this.amountToPrecision(symbol, amount);
1412
1440
  }
1441
+ request['amount'] = quoteAmount;
1413
1442
  }
1414
1443
  else {
1415
1444
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -704,9 +704,6 @@ class kucoinfutures extends kucoinfutures$1 {
704
704
  orderbook['nonce'] = this.safeInteger(data, 'sequence');
705
705
  return orderbook;
706
706
  }
707
- async fetchL3OrderBook(symbol, limit = undefined, params = {}) {
708
- throw new errors.BadRequest(this.id + ' fetchL3OrderBook() is not supported yet');
709
- }
710
707
  async fetchTicker(symbol, params = {}) {
711
708
  /**
712
709
  * @method