ccxt 4.1.83 → 4.1.84

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.84';
176
176
  Exchange["default"].ccxtVersion = version;
177
177
  const exchanges = {
178
178
  'ace': ace,
@@ -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
  }
@@ -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') {
@@ -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);
package/js/ccxt.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
5
  import { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
7
- declare const version = "4.1.82";
7
+ declare const version = "4.1.83";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.1.83';
41
+ const version = '4.1.84';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
package/js/src/binance.js CHANGED
@@ -8607,7 +8607,7 @@ export default class binance extends Exchange {
8607
8607
  extendedParams = this.omit(extendedParams, ['orderidlist', 'origclientorderidlist']);
8608
8608
  query = this.rawencode(extendedParams);
8609
8609
  const orderidlistLength = orderidlist.length;
8610
- const origclientorderidlistLength = orderidlist.length;
8610
+ const origclientorderidlistLength = origclientorderidlist.length;
8611
8611
  if (orderidlistLength > 0) {
8612
8612
  query = query + '&' + 'orderidlist=[' + orderidlist.join(',') + ']';
8613
8613
  }
package/js/src/bybit.js CHANGED
@@ -5745,9 +5745,11 @@ export default class bybit extends Exchange {
5745
5745
  else if (symbolsLength === 1) {
5746
5746
  symbol = symbols[0];
5747
5747
  }
5748
+ symbols = this.marketSymbols(symbols);
5748
5749
  }
5749
5750
  else if (symbols !== undefined) {
5750
5751
  symbol = symbols;
5752
+ symbols = [this.symbol(symbol)];
5751
5753
  }
5752
5754
  await this.loadMarkets();
5753
5755
  const [enableUnifiedMargin, enableUnifiedAccount] = await this.isUnifiedEnabled();
@@ -5757,14 +5759,12 @@ export default class bybit extends Exchange {
5757
5759
  let isUsdcSettled = false;
5758
5760
  if (symbol !== undefined) {
5759
5761
  market = this.market(symbol);
5762
+ symbol = market['symbol'];
5760
5763
  request['symbol'] = market['id'];
5761
5764
  isUsdcSettled = market['settle'] === 'USDC';
5762
5765
  }
5763
5766
  let type = undefined;
5764
5767
  [type, params] = this.getBybitType('fetchPositions', market, params);
5765
- if (type === 'spot') {
5766
- throw new NotSupported(this.id + ' fetchPositions() not support spot market');
5767
- }
5768
5768
  if (type === 'linear' || type === 'inverse') {
5769
5769
  const baseCoin = this.safeString(params, 'baseCoin');
5770
5770
  if (type === 'linear') {
package/js/src/coinsph.js CHANGED
@@ -38,6 +38,9 @@ export default class coinsph extends Exchange {
38
38
  'closeAllPositions': false,
39
39
  'closePosition': false,
40
40
  'createDepositAddress': false,
41
+ 'createMarketBuyOrderWithCost': true,
42
+ 'createMarketOrderWithCost': false,
43
+ 'createMarketSellOrderWithCost': false,
41
44
  'createOrder': true,
42
45
  'createPostOnlyOrder': false,
43
46
  'createReduceOnlyOrder': false,
@@ -1065,12 +1068,14 @@ export default class coinsph extends Exchange {
1065
1068
  * @method
1066
1069
  * @name coinsph#createOrder
1067
1070
  * @description create a trade order
1071
+ * @see https://coins-docs.github.io/rest-api/#new-order--trade
1068
1072
  * @param {string} symbol unified symbol of the market to create an order in
1069
1073
  * @param {string} type 'market', 'limit', 'stop_loss', 'take_profit', 'stop_loss_limit', 'take_profit_limit' or 'limit_maker'
1070
1074
  * @param {string} side 'buy' or 'sell'
1071
1075
  * @param {float} amount how much of currency you want to trade in units of base currency
1072
1076
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1073
1077
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1078
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
1074
1079
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1075
1080
  */
1076
1081
  // todo: add test order low priority
@@ -1106,24 +1111,29 @@ export default class coinsph extends Exchange {
1106
1111
  request['quantity'] = this.amountToPrecision(symbol, amount);
1107
1112
  }
1108
1113
  else if (orderSide === 'BUY') {
1109
- const quoteOrderQty = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1110
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
1111
- if (quoteOrderQty !== undefined) {
1112
- amount = quoteOrderQty;
1114
+ let quoteAmount = undefined;
1115
+ let createMarketBuyOrderRequiresPrice = true;
1116
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1117
+ const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1118
+ params = this.omit(params, 'cost');
1119
+ if (cost !== undefined) {
1120
+ quoteAmount = this.costToPrecision(symbol, cost);
1113
1121
  }
1114
1122
  else if (createMarketBuyOrderRequiresPrice) {
1115
1123
  if (price === undefined) {
1116
- throw new 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)");
1124
+ throw new 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');
1117
1125
  }
1118
1126
  else {
1119
1127
  const amountString = this.numberToString(amount);
1120
1128
  const priceString = this.numberToString(price);
1121
- const quoteAmount = Precise.stringMul(amountString, priceString);
1122
- amount = this.parseNumber(quoteAmount);
1129
+ const costRequest = Precise.stringMul(amountString, priceString);
1130
+ quoteAmount = this.costToPrecision(symbol, costRequest);
1123
1131
  }
1124
1132
  }
1125
- request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
1126
- params = this.omit(params, 'cost', 'quoteOrderQty');
1133
+ else {
1134
+ quoteAmount = this.costToPrecision(symbol, amount);
1135
+ }
1136
+ request['quoteOrderQty'] = quoteAmount;
1127
1137
  }
1128
1138
  }
1129
1139
  if (orderType === 'STOP_LOSS' || orderType === 'STOP_LOSS_LIMIT' || orderType === 'TAKE_PROFIT' || orderType === 'TAKE_PROFIT_LIMIT') {
package/js/src/htx.d.ts CHANGED
@@ -83,6 +83,7 @@ export default class htx extends Exchange {
83
83
  fetchOpenOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
84
84
  parseOrderStatus(status: any): string;
85
85
  parseOrder(order: any, market?: Market): Order;
86
+ createMarketBuyOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
86
87
  createSpotOrderRequest(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<any>;
87
88
  createContractOrderRequest(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): any;
88
89
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
package/js/src/htx.js CHANGED
@@ -41,6 +41,9 @@ export default class htx extends Exchange {
41
41
  'cancelOrder': true,
42
42
  'cancelOrders': true,
43
43
  'createDepositAddress': undefined,
44
+ 'createMarketBuyOrderWithCost': true,
45
+ 'createMarketOrderWithCost': false,
46
+ 'createMarketSellOrderWithCost': false,
44
47
  'createOrder': true,
45
48
  'createOrders': true,
46
49
  'createReduceOnlyOrder': false,
@@ -4843,6 +4846,25 @@ export default class htx extends Exchange {
4843
4846
  'trades': trades,
4844
4847
  }, market);
4845
4848
  }
4849
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
4850
+ /**
4851
+ * @method
4852
+ * @name htx#createMarketBuyOrderWithCost
4853
+ * @description create a market buy order by providing the symbol and cost
4854
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec4ee16-7773-11ed-9966-0242ac110003
4855
+ * @param {string} symbol unified symbol of the market to create an order in
4856
+ * @param {float} cost how much you want to trade in units of the quote currency
4857
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4858
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4859
+ */
4860
+ await this.loadMarkets();
4861
+ const market = this.market(symbol);
4862
+ if (!market['spot']) {
4863
+ throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
4864
+ }
4865
+ params['createMarketBuyOrderRequiresPrice'] = false;
4866
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
4867
+ }
4846
4868
  async createSpotOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
4847
4869
  /**
4848
4870
  * @method
@@ -4856,6 +4878,7 @@ export default class htx extends Exchange {
4856
4878
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
4857
4879
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4858
4880
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
4881
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
4859
4882
  * @returns {object} request to be sent to the exchange
4860
4883
  */
4861
4884
  await this.loadMarkets();
@@ -4930,9 +4953,17 @@ export default class htx extends Exchange {
4930
4953
  request['source'] = 'c2c-margin-api';
4931
4954
  }
4932
4955
  if ((orderType === 'market') && (side === 'buy')) {
4933
- if (this.options['createMarketBuyOrderRequiresPrice']) {
4956
+ let quoteAmount = undefined;
4957
+ let createMarketBuyOrderRequiresPrice = true;
4958
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
4959
+ const cost = this.safeNumber(params, 'cost');
4960
+ params = this.omit(params, 'cost');
4961
+ if (cost !== undefined) {
4962
+ quoteAmount = this.amountToPrecision(symbol, cost);
4963
+ }
4964
+ else if (createMarketBuyOrderRequiresPrice) {
4934
4965
  if (price === undefined) {
4935
- throw new 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.");
4966
+ throw new 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');
4936
4967
  }
4937
4968
  else {
4938
4969
  // despite that cost = amount * price is in quote currency and should have quote precision
@@ -4943,12 +4974,13 @@ export default class htx extends Exchange {
4943
4974
  // we use amountToPrecision here because the exchange requires cost in base precision
4944
4975
  const amountString = this.numberToString(amount);
4945
4976
  const priceString = this.numberToString(price);
4946
- request['amount'] = this.costToPrecision(symbol, Precise.stringMul(amountString, priceString));
4977
+ quoteAmount = this.amountToPrecision(symbol, Precise.stringMul(amountString, priceString));
4947
4978
  }
4948
4979
  }
4949
4980
  else {
4950
- request['amount'] = this.costToPrecision(symbol, amount);
4981
+ quoteAmount = this.amountToPrecision(symbol, amount);
4951
4982
  }
4983
+ request['amount'] = quoteAmount;
4952
4984
  }
4953
4985
  else {
4954
4986
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -5080,6 +5112,7 @@ export default class htx extends Exchange {
5080
5112
  * @param {bool} [params.postOnly] *contract only* true or false
5081
5113
  * @param {int} [params.leverRate] *contract only* required for all contract orders except tpsl, leverage greater than 20x requires prior approval of high-leverage agreement
5082
5114
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
5115
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
5083
5116
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
5084
5117
  */
5085
5118
  await this.loadMarkets();
@@ -51,6 +51,7 @@ export default class huobijp extends Exchange {
51
51
  fetchOpenOrdersV2(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
52
52
  parseOrderStatus(status: any): string;
53
53
  parseOrder(order: any, market?: Market): Order;
54
+ createMarketBuyOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
54
55
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
55
56
  cancelOrder(id: string, symbol?: Str, params?: {}): Promise<any>;
56
57
  cancelOrders(ids: any, symbol?: Str, params?: {}): Promise<any>;
package/js/src/huobijp.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import Exchange from './abstract/huobijp.js';
9
- import { AuthenticationError, ExchangeError, PermissionDenied, ExchangeNotAvailable, OnMaintenance, InvalidOrder, OrderNotFound, InsufficientFunds, BadSymbol, BadRequest, RequestTimeout, NetworkError, ArgumentsRequired } from './base/errors.js';
9
+ import { AuthenticationError, ExchangeError, PermissionDenied, ExchangeNotAvailable, OnMaintenance, InvalidOrder, OrderNotFound, InsufficientFunds, BadSymbol, BadRequest, RequestTimeout, NetworkError, ArgumentsRequired, NotSupported } from './base/errors.js';
10
10
  import { Precise } from './base/Precise.js';
11
11
  import { TRUNCATE, TICK_SIZE } from './base/functions/number.js';
12
12
  import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
@@ -37,6 +37,9 @@ export default class huobijp extends Exchange {
37
37
  'cancelAllOrders': true,
38
38
  'cancelOrder': true,
39
39
  'cancelOrders': true,
40
+ 'createMarketBuyOrderWithCost': true,
41
+ 'createMarketOrderWithCost': false,
42
+ 'createMarketSellOrderWithCost': false,
40
43
  'createOrder': true,
41
44
  'createStopLimitOrder': false,
42
45
  'createStopMarketOrder': false,
@@ -1361,6 +1364,24 @@ export default class huobijp extends Exchange {
1361
1364
  'trades': undefined,
1362
1365
  }, market);
1363
1366
  }
1367
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1368
+ /**
1369
+ * @method
1370
+ * @name huobijp#createMarketBuyOrderWithCost
1371
+ * @description create a market buy order by providing the symbol and cost
1372
+ * @param {string} symbol unified symbol of the market to create an order in
1373
+ * @param {float} cost how much you want to trade in units of the quote currency
1374
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1375
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1376
+ */
1377
+ await this.loadMarkets();
1378
+ const market = this.market(symbol);
1379
+ if (!market['spot']) {
1380
+ throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
1381
+ }
1382
+ params['createMarketBuyOrderRequiresPrice'] = false;
1383
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1384
+ }
1364
1385
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1365
1386
  /**
1366
1387
  * @method
@@ -1393,9 +1414,17 @@ export default class huobijp extends Exchange {
1393
1414
  }
1394
1415
  params = this.omit(params, ['clientOrderId', 'client-order-id']);
1395
1416
  if ((type === 'market') && (side === 'buy')) {
1396
- if (this.options['createMarketBuyOrderRequiresPrice']) {
1417
+ let quoteAmount = undefined;
1418
+ let createMarketBuyOrderRequiresPrice = true;
1419
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1420
+ const cost = this.safeNumber(params, 'cost');
1421
+ params = this.omit(params, 'cost');
1422
+ if (cost !== undefined) {
1423
+ quoteAmount = this.amountToPrecision(symbol, cost);
1424
+ }
1425
+ else if (createMarketBuyOrderRequiresPrice) {
1397
1426
  if (price === undefined) {
1398
- throw new 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.");
1427
+ throw new 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');
1399
1428
  }
1400
1429
  else {
1401
1430
  // despite that cost = amount * price is in quote currency and should have quote precision
@@ -1406,13 +1435,13 @@ export default class huobijp extends Exchange {
1406
1435
  // we use amountToPrecision here because the exchange requires cost in base precision
1407
1436
  const amountString = this.numberToString(amount);
1408
1437
  const priceString = this.numberToString(price);
1409
- const baseAmount = Precise.stringMul(amountString, priceString);
1410
- request['amount'] = this.costToPrecision(symbol, baseAmount);
1438
+ quoteAmount = this.amountToPrecision(symbol, Precise.stringMul(amountString, priceString));
1411
1439
  }
1412
1440
  }
1413
1441
  else {
1414
- request['amount'] = this.costToPrecision(symbol, amount);
1442
+ quoteAmount = this.amountToPrecision(symbol, amount);
1415
1443
  }
1444
+ request['amount'] = quoteAmount;
1416
1445
  }
1417
1446
  else {
1418
1447
  request['amount'] = this.amountToPrecision(symbol, amount);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.1.83",
3
+ "version": "4.1.84",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 130+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",