ccxt 4.2.2 → 4.2.4

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
@@ -169,7 +169,7 @@ var woo$1 = require('./src/pro/woo.js');
169
169
 
170
170
  //-----------------------------------------------------------------------------
171
171
  // this is updated by vss.js when building
172
- const version = '4.2.2';
172
+ const version = '4.2.4';
173
173
  Exchange["default"].ccxtVersion = version;
174
174
  const exchanges = {
175
175
  'ace': ace,
@@ -50,7 +50,7 @@ class alpaca extends alpaca$1 {
50
50
  'closeAllPositions': false,
51
51
  'closePosition': false,
52
52
  'createOrder': true,
53
- 'fetchBalance': true,
53
+ 'fetchBalance': false,
54
54
  'fetchBidsAsks': false,
55
55
  'fetchClosedOrders': true,
56
56
  'fetchCurrencies': false,
@@ -757,8 +757,11 @@ class Exchange {
757
757
  // proxy agents
758
758
  const [httpProxy, httpsProxy, socksProxy] = this.checkProxySettings(url, method, headers, body);
759
759
  this.checkConflictingProxies(httpProxy || httpsProxy || socksProxy, proxyUrl);
760
- if (!this.proxyModulesLoaded) {
761
- await this.loadProxyModules(); // this is needed in JS, independently whether proxy properties were set or not, we have to load them because of necessity in WS, which would happen beyond 'fetch' method (WS/etc)
760
+ if (isNode) {
761
+ // skip this on the browser
762
+ if (!this.proxyModulesLoaded) {
763
+ await this.loadProxyModules(); // this is needed in JS, independently whether proxy properties were set or not, we have to load them because of necessity in WS, which would happen beyond 'fetch' method (WS/etc)
764
+ }
762
765
  }
763
766
  const chosenAgent = this.setProxyAgents(httpProxy, httpsProxy, socksProxy);
764
767
  // user-agent
@@ -277,6 +277,9 @@ class bingx extends bingx$1 {
277
277
  'post': {
278
278
  'userDataStream': 1,
279
279
  },
280
+ 'put': {
281
+ 'userDataStream': 1,
282
+ },
280
283
  },
281
284
  },
282
285
  },
@@ -1718,6 +1721,10 @@ class bingx extends bingx$1 {
1718
1721
  const isTrailingAmountOrder = trailingAmount !== undefined;
1719
1722
  const isTrailingPercentOrder = trailingPercent !== undefined;
1720
1723
  const isTrailing = isTrailingAmountOrder || isTrailingPercentOrder;
1724
+ const stopLoss = this.safeValue(params, 'stopLoss');
1725
+ const takeProfit = this.safeValue(params, 'takeProfit');
1726
+ const isStopLoss = stopLoss !== undefined;
1727
+ const isTakeProfit = takeProfit !== undefined;
1721
1728
  if (((type === 'LIMIT') || (type === 'TRIGGER_LIMIT') || (type === 'STOP') || (type === 'TAKE_PROFIT')) && !isTrailing) {
1722
1729
  request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
1723
1730
  }
@@ -1763,6 +1770,42 @@ class bingx extends bingx$1 {
1763
1770
  request['priceRate'] = this.parseToNumeric(requestTrailingPercent);
1764
1771
  }
1765
1772
  }
1773
+ if (isStopLoss || isTakeProfit) {
1774
+ if (isStopLoss) {
1775
+ const slTriggerPrice = this.safeString2(stopLoss, 'triggerPrice', 'stopPrice', stopLoss);
1776
+ const slWorkingType = this.safeString(stopLoss, 'workingType', 'MARK_PRICE');
1777
+ const slType = this.safeString(stopLoss, 'type', 'STOP_MARKET');
1778
+ const slRequest = {
1779
+ 'stopPrice': this.parseToNumeric(this.priceToPrecision(symbol, slTriggerPrice)),
1780
+ 'workingType': slWorkingType,
1781
+ 'type': slType,
1782
+ };
1783
+ const slPrice = this.safeString(stopLoss, 'price');
1784
+ if (slPrice !== undefined) {
1785
+ slRequest['price'] = this.parseToNumeric(this.priceToPrecision(symbol, slPrice));
1786
+ }
1787
+ const slQuantity = this.safeString(stopLoss, 'quantity', amount);
1788
+ slRequest['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, slQuantity));
1789
+ request['stopLoss'] = this.json(slRequest);
1790
+ }
1791
+ if (isTakeProfit) {
1792
+ const tkTriggerPrice = this.safeString2(takeProfit, 'triggerPrice', 'stopPrice', takeProfit);
1793
+ const tkWorkingType = this.safeString(takeProfit, 'workingType', 'MARK_PRICE');
1794
+ const tpType = this.safeString(takeProfit, 'type', 'TAKE_PROFIT_MARKET');
1795
+ const tpRequest = {
1796
+ 'stopPrice': this.parseToNumeric(this.priceToPrecision(symbol, tkTriggerPrice)),
1797
+ 'workingType': tkWorkingType,
1798
+ 'type': tpType,
1799
+ };
1800
+ const slPrice = this.safeString(takeProfit, 'price');
1801
+ if (slPrice !== undefined) {
1802
+ tpRequest['price'] = this.parseToNumeric(this.priceToPrecision(symbol, slPrice));
1803
+ }
1804
+ const tkQuantity = this.safeString(takeProfit, 'quantity', amount);
1805
+ tpRequest['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, tkQuantity));
1806
+ request['takeProfit'] = this.json(tpRequest);
1807
+ }
1808
+ }
1766
1809
  let positionSide = undefined;
1767
1810
  if (reduceOnly) {
1768
1811
  positionSide = (side === 'buy') ? 'SHORT' : 'LONG';
@@ -1772,7 +1815,7 @@ class bingx extends bingx$1 {
1772
1815
  }
1773
1816
  request['positionSide'] = positionSide;
1774
1817
  request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1775
- params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent']);
1818
+ params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent', 'takeProfit', 'stopLoss']);
1776
1819
  }
1777
1820
  return this.extend(request, params);
1778
1821
  }
@@ -1782,6 +1825,7 @@ class bingx extends bingx$1 {
1782
1825
  * @name bingx#createOrder
1783
1826
  * @description create a trade order
1784
1827
  * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Trade%20order
1828
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Create%20an%20Order
1785
1829
  * @param {string} symbol unified symbol of the market to create an order in
1786
1830
  * @param {string} type 'market' or 'limit'
1787
1831
  * @param {string} side 'buy' or 'sell'
@@ -1797,6 +1841,10 @@ class bingx extends bingx$1 {
1797
1841
  * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount
1798
1842
  * @param {float} [params.trailingAmount] *swap only* the quote amount to trail away from the current market price
1799
1843
  * @param {float} [params.trailingPercent] *swap only* the percent to trail away from the current market price
1844
+ * @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
1845
+ * @param {float} [params.takeProfit.triggerPrice] take profit trigger price
1846
+ * @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
1847
+ * @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
1800
1848
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1801
1849
  */
1802
1850
  await this.loadMarkets();
@@ -1847,6 +1895,9 @@ class bingx extends bingx$1 {
1847
1895
  // }
1848
1896
  // }
1849
1897
  //
1898
+ if (typeof response === 'string') {
1899
+ response = JSON.parse(response);
1900
+ }
1850
1901
  const data = this.safeValue(response, 'data', {});
1851
1902
  const order = this.safeValue(data, 'order', data);
1852
1903
  return this.parseOrder(order, market);
@@ -2051,6 +2102,24 @@ class bingx extends bingx$1 {
2051
2102
  // "orderType": "",
2052
2103
  // "workingType": "MARK_PRICE"
2053
2104
  // }
2105
+ // with tp and sl
2106
+ // {
2107
+ // orderId: 1741440894764281900,
2108
+ // symbol: 'LTC-USDT',
2109
+ // positionSide: 'LONG',
2110
+ // side: 'BUY',
2111
+ // type: 'MARKET',
2112
+ // price: 0,
2113
+ // quantity: 1,
2114
+ // stopPrice: 0,
2115
+ // workingType: 'MARK_PRICE',
2116
+ // clientOrderID: '',
2117
+ // timeInForce: 'GTC',
2118
+ // priceRate: 0,
2119
+ // stopLoss: '{"stopPrice":50,"workingType":"MARK_PRICE","type":"STOP_MARKET","quantity":1}',
2120
+ // takeProfit: '{"stopPrice":150,"workingType":"MARK_PRICE","type":"TAKE_PROFIT_MARKET","quantity":1}',
2121
+ // reduceOnly: false
2122
+ // }
2054
2123
  //
2055
2124
  const positionSide = this.safeString2(order, 'positionSide', 'ps');
2056
2125
  const marketType = (positionSide === undefined) ? 'spot' : 'swap';
@@ -2089,6 +2158,30 @@ class bingx extends bingx$1 {
2089
2158
  'cost': Precise["default"].stringAbs(feeCost),
2090
2159
  };
2091
2160
  const clientOrderId = this.safeString2(order, 'clientOrderId', 'c');
2161
+ let stopLoss = this.safeValue(order, 'stopLoss');
2162
+ let stopLossPrice = undefined;
2163
+ if (stopLoss !== undefined) {
2164
+ stopLossPrice = this.safeNumber(stopLoss, 'stopLoss');
2165
+ }
2166
+ if ((stopLoss !== undefined) && (typeof stopLoss !== 'number')) {
2167
+ // stopLoss: '{"stopPrice":50,"workingType":"MARK_PRICE","type":"STOP_MARKET","quantity":1}',
2168
+ if (typeof stopLoss === 'string') {
2169
+ stopLoss = JSON.parse(stopLoss);
2170
+ }
2171
+ stopLossPrice = this.safeNumber(stopLoss, 'stopPrice');
2172
+ }
2173
+ let takeProfit = this.safeValue(order, 'takeProfit');
2174
+ let takeProfitPrice = undefined;
2175
+ if (takeProfit !== undefined) {
2176
+ takeProfitPrice = this.safeNumber(takeProfit, 'takeProfit');
2177
+ }
2178
+ if ((takeProfit !== undefined) && (typeof takeProfit !== 'number')) {
2179
+ // takeProfit: '{"stopPrice":150,"workingType":"MARK_PRICE","type":"TAKE_PROFIT_MARKET","quantity":1}',
2180
+ if (typeof takeProfit === 'string') {
2181
+ takeProfit = JSON.parse(takeProfit);
2182
+ }
2183
+ takeProfitPrice = this.safeNumber(takeProfit, 'stopPrice');
2184
+ }
2092
2185
  return this.safeOrder({
2093
2186
  'info': order,
2094
2187
  'id': orderId,
@@ -2105,8 +2198,8 @@ class bingx extends bingx$1 {
2105
2198
  'price': price,
2106
2199
  'stopPrice': this.safeNumber(order, 'stopPrice'),
2107
2200
  'triggerPrice': this.safeNumber(order, 'stopPrice'),
2108
- 'stopLossPrice': this.safeNumber(order, 'stopLoss'),
2109
- 'takeProfitPrice': this.safeNumber(order, 'takeProfit'),
2201
+ 'stopLossPrice': stopLossPrice,
2202
+ 'takeProfitPrice': takeProfitPrice,
2110
2203
  'average': average,
2111
2204
  'cost': undefined,
2112
2205
  'amount': amount,
@@ -2300,6 +2393,7 @@ class bingx extends bingx$1 {
2300
2393
  * @param {string[]} ids order ids
2301
2394
  * @param {string} symbol unified market symbol, default is undefined
2302
2395
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2396
+ * @param {string[]} [params.clientOrderIds] client order ids
2303
2397
  * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2304
2398
  */
2305
2399
  if (symbol === undefined) {
@@ -2310,19 +2404,27 @@ class bingx extends bingx$1 {
2310
2404
  const request = {
2311
2405
  'symbol': market['id'],
2312
2406
  };
2407
+ const clientOrderIds = this.safeValue(params, 'clientOrderIds');
2408
+ let idsToParse = ids;
2409
+ const areClientOrderIds = (clientOrderIds !== undefined);
2410
+ if (areClientOrderIds) {
2411
+ idsToParse = clientOrderIds;
2412
+ }
2313
2413
  const parsedIds = [];
2314
- for (let i = 0; i < ids.length; i++) {
2315
- const id = ids[i];
2414
+ for (let i = 0; i < idsToParse.length; i++) {
2415
+ const id = idsToParse[i];
2316
2416
  const stringId = id.toString();
2317
2417
  parsedIds.push(stringId);
2318
2418
  }
2319
2419
  let response = undefined;
2320
2420
  if (market['spot']) {
2321
- request['orderIds'] = parsedIds.join(',');
2421
+ const spotReqKey = areClientOrderIds ? 'clientOrderIds' : 'orderIds';
2422
+ request[spotReqKey] = parsedIds.join(',');
2322
2423
  response = await this.spotV1PrivatePostTradeCancelOrders(this.extend(request, params));
2323
2424
  }
2324
2425
  else {
2325
- request['orderIdList'] = parsedIds;
2426
+ const swapReqKey = areClientOrderIds ? 'ClientOrderIDList' : 'orderIdList';
2427
+ request[swapReqKey] = parsedIds;
2326
2428
  response = await this.swapV2PrivateDeleteTradeBatchOrders(this.extend(request, params));
2327
2429
  }
2328
2430
  //
@@ -4742,8 +4742,8 @@ class bitget extends bitget$1 {
4742
4742
  }
4743
4743
  let marginMode = undefined;
4744
4744
  [marginMode, params] = this.handleMarginModeAndParams('cancelOrders', params);
4745
- const stop = this.safeValue(params, 'stop');
4746
- params = this.omit(params, 'stop');
4745
+ const stop = this.safeValue2(params, 'stop', 'trigger');
4746
+ params = this.omit(params, ['stop', 'trigger']);
4747
4747
  const orderIdList = [];
4748
4748
  for (let i = 0; i < ids.length; i++) {
4749
4749
  const individualId = ids[i];
@@ -4839,8 +4839,8 @@ class bitget extends bitget$1 {
4839
4839
  const request = {
4840
4840
  'symbol': market['id'],
4841
4841
  };
4842
- const stop = this.safeValue(params, 'stop');
4843
- params = this.omit(params, 'stop');
4842
+ const stop = this.safeValue2(params, 'stop', 'trigger');
4843
+ params = this.omit(params, ['stop', 'trigger']);
4844
4844
  let response = undefined;
4845
4845
  if (market['spot']) {
4846
4846
  if (marginMode !== undefined) {
@@ -196,6 +196,7 @@ class bitmart extends bitmart$1 {
196
196
  'contract/private/order-history': 10,
197
197
  'contract/private/position': 10,
198
198
  'contract/private/get-open-orders': 1.2,
199
+ 'contract/private/current-plan-order': 1.2,
199
200
  'contract/private/trades': 10,
200
201
  },
201
202
  'post': {
@@ -2507,8 +2508,8 @@ class bitmart extends bitmart$1 {
2507
2508
  response = await this.privatePostSpotV3CancelOrder(this.extend(request, params));
2508
2509
  }
2509
2510
  else {
2510
- const stop = this.safeValue(params, 'stop');
2511
- params = this.omit(params, ['stop']);
2511
+ const stop = this.safeValue2(params, 'stop', 'trigger');
2512
+ params = this.omit(params, ['stop', 'trigger']);
2512
2513
  if (!stop) {
2513
2514
  response = await this.privatePostContractPrivateCancelOrder(this.extend(request, params));
2514
2515
  }
@@ -2678,6 +2679,7 @@ class bitmart extends bitmart$1 {
2678
2679
  * @name bitmart#fetchOpenOrders
2679
2680
  * @see https://developer-pro.bitmart.com/en/spot/#current-open-orders-v4-signed
2680
2681
  * @see https://developer-pro.bitmart.com/en/futures/#get-all-open-orders-keyed
2682
+ * @see https://developer-pro.bitmart.com/en/futures/#get-all-current-plan-orders-keyed
2681
2683
  * @description fetch all unfilled currently open orders
2682
2684
  * @param {string} symbol unified market symbol
2683
2685
  * @param {int} [since] the earliest time in ms to fetch open orders for
@@ -2689,6 +2691,7 @@ class bitmart extends bitmart$1 {
2689
2691
  * @param {string} [params.order_state] *swap* the order state, 'all' or 'partially_filled', default is 'all'
2690
2692
  * @param {string} [params.orderType] *swap only* 'limit', 'market', or 'trailing'
2691
2693
  * @param {boolean} [params.trailing] *swap only* set to true if you want to fetch trailing orders
2694
+ * @param {boolean} [params.trigger] *swap only* set to true if you want to fetch trigger orders
2692
2695
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2693
2696
  */
2694
2697
  await this.loadMarkets();
@@ -2721,16 +2724,23 @@ class bitmart extends bitmart$1 {
2721
2724
  response = await this.privatePostSpotV4QueryOpenOrders(this.extend(request, params));
2722
2725
  }
2723
2726
  else if (type === 'swap') {
2724
- const trailing = this.safeValue(params, 'trailing', false);
2725
- let orderType = this.safeString(params, 'orderType');
2726
- params = this.omit(params, ['orderType', 'trailing']);
2727
- if (trailing) {
2728
- orderType = 'trailing';
2727
+ const isStop = this.safeValue2(params, 'stop', 'trigger');
2728
+ params = this.omit(params, ['stop', 'trigger']);
2729
+ if (isStop) {
2730
+ response = await this.privateGetContractPrivateCurrentPlanOrder(this.extend(request, params));
2729
2731
  }
2730
- if (orderType !== undefined) {
2731
- request['type'] = orderType;
2732
+ else {
2733
+ const trailing = this.safeValue(params, 'trailing', false);
2734
+ let orderType = this.safeString(params, 'orderType');
2735
+ params = this.omit(params, ['orderType', 'trailing']);
2736
+ if (trailing) {
2737
+ orderType = 'trailing';
2738
+ }
2739
+ if (orderType !== undefined) {
2740
+ request['type'] = orderType;
2741
+ }
2742
+ response = await this.privateGetContractPrivateGetOpenOrders(this.extend(request, params));
2732
2743
  }
2733
- response = await this.privateGetContractPrivateGetOpenOrders(this.extend(request, params));
2734
2744
  }
2735
2745
  else {
2736
2746
  throw new errors.NotSupported(this.id + ' fetchOpenOrders() does not support ' + type + ' orders, only spot and swap orders are accepted');
@@ -626,6 +626,8 @@ class bybit extends bybit$1 {
626
626
  '131215': errors.BadRequest,
627
627
  '131216': errors.ExchangeError,
628
628
  '131217': errors.ExchangeError,
629
+ '131231': errors.NotSupported,
630
+ '131232': errors.NotSupported,
629
631
  '131002': errors.BadRequest,
630
632
  '131003': errors.ExchangeError,
631
633
  '131004': errors.AuthenticationError,
@@ -628,7 +628,16 @@ class coinsph extends coinsph$1 {
628
628
  const defaultMethod = 'publicGetOpenapiQuoteV1Ticker24hr';
629
629
  const options = this.safeValue(this.options, 'fetchTickers', {});
630
630
  const method = this.safeString(options, 'method', defaultMethod);
631
- const tickers = await this[method](this.extend(request, params));
631
+ let tickers = undefined;
632
+ if (method === 'publicGetOpenapiQuoteV1TickerPrice') {
633
+ tickers = await this.publicGetOpenapiQuoteV1TickerPrice(this.extend(request, params));
634
+ }
635
+ else if (method === 'publicGetOpenapiQuoteV1TickerBookTicker') {
636
+ tickers = await this.publicGetOpenapiQuoteV1TickerBookTicker(this.extend(request, params));
637
+ }
638
+ else {
639
+ tickers = await this.publicGetOpenapiQuoteV1Ticker24hr(this.extend(request, params));
640
+ }
632
641
  return this.parseTickers(tickers, symbols, params);
633
642
  }
634
643
  async fetchTicker(symbol, params = {}) {
@@ -648,7 +657,16 @@ class coinsph extends coinsph$1 {
648
657
  const defaultMethod = 'publicGetOpenapiQuoteV1Ticker24hr';
649
658
  const options = this.safeValue(this.options, 'fetchTicker', {});
650
659
  const method = this.safeString(options, 'method', defaultMethod);
651
- const ticker = await this[method](this.extend(request, params));
660
+ let ticker = undefined;
661
+ if (method === 'publicGetOpenapiQuoteV1TickerPrice') {
662
+ ticker = await this.publicGetOpenapiQuoteV1TickerPrice(this.extend(request, params));
663
+ }
664
+ else if (method === 'publicGetOpenapiQuoteV1TickerBookTicker') {
665
+ ticker = await this.publicGetOpenapiQuoteV1TickerBookTicker(this.extend(request, params));
666
+ }
667
+ else {
668
+ ticker = await this.publicGetOpenapiQuoteV1Ticker24hr(this.extend(request, params));
669
+ }
652
670
  return this.parseTicker(ticker, market);
653
671
  }
654
672
  parseTicker(ticker, market = undefined) {
@@ -5014,6 +5014,8 @@ class htx extends htx$1 {
5014
5014
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
5015
5015
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5016
5016
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
5017
+ * @param {float} [params.trailingPercent] *contract only* the percent to trail away from the current market price
5018
+ * @param {float} [params.trailingTriggerPrice] *contract only* the price to trigger a trailing order, default uses the price argument
5017
5019
  * @returns {object} request to be sent to the exchange
5018
5020
  */
5019
5021
  const market = this.market(symbol);
@@ -5037,6 +5039,9 @@ class htx extends htx$1 {
5037
5039
  const triggerPrice = this.safeNumber2(params, 'stopPrice', 'trigger_price');
5038
5040
  const stopLossTriggerPrice = this.safeNumber2(params, 'stopLossPrice', 'sl_trigger_price');
5039
5041
  const takeProfitTriggerPrice = this.safeNumber2(params, 'takeProfitPrice', 'tp_trigger_price');
5042
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callback_rate');
5043
+ const trailingTriggerPrice = this.safeNumber(params, 'trailingTriggerPrice', price);
5044
+ const isTrailingPercentOrder = trailingPercent !== undefined;
5040
5045
  const isStop = triggerPrice !== undefined;
5041
5046
  const isStopLossTriggerOrder = stopLossTriggerPrice !== undefined;
5042
5047
  const isTakeProfitTriggerOrder = takeProfitTriggerPrice !== undefined;
@@ -5064,6 +5069,12 @@ class htx extends htx$1 {
5064
5069
  }
5065
5070
  }
5066
5071
  }
5072
+ else if (isTrailingPercentOrder) {
5073
+ const trailingPercentString = Precise["default"].stringDiv(trailingPercent, '100');
5074
+ request['callback_rate'] = this.parseToNumeric(trailingPercentString);
5075
+ request['active_price'] = trailingTriggerPrice;
5076
+ request['order_price_type'] = this.safeString(params, 'order_price_type', 'formula_price');
5077
+ }
5067
5078
  else {
5068
5079
  const clientOrderId = this.safeInteger2(params, 'client_order_id', 'clientOrderId');
5069
5080
  if (clientOrderId !== undefined) {
@@ -5075,7 +5086,7 @@ class htx extends htx$1 {
5075
5086
  }
5076
5087
  }
5077
5088
  if (!isStopLossTriggerOrder && !isTakeProfitTriggerOrder) {
5078
- const leverRate = this.safeInteger2(params, 'leverRate', 'lever_rate', 1);
5089
+ const leverRate = this.safeIntegerN(params, ['leverRate', 'lever_rate', 'leverage'], 1);
5079
5090
  const reduceOnly = this.safeValue2(params, 'reduceOnly', 'reduce_only', false);
5080
5091
  const openOrClose = (reduceOnly) ? 'close' : 'open';
5081
5092
  const offset = this.safeString(params, 'offset', openOrClose);
@@ -5084,12 +5095,14 @@ class htx extends htx$1 {
5084
5095
  request['reduce_only'] = 1;
5085
5096
  }
5086
5097
  request['lever_rate'] = leverRate;
5087
- request['order_price_type'] = type;
5098
+ if (!isTrailingPercentOrder) {
5099
+ request['order_price_type'] = type;
5100
+ }
5088
5101
  }
5089
5102
  const broker = this.safeValue(this.options, 'broker', {});
5090
5103
  const brokerId = this.safeString(broker, 'id');
5091
5104
  request['channel_code'] = brokerId;
5092
- params = this.omit(params, ['reduceOnly', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'triggerType', 'leverRate', 'timeInForce']);
5105
+ params = this.omit(params, ['reduceOnly', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'triggerType', 'leverRate', 'timeInForce', 'leverage', 'trailingPercent', 'trailingTriggerPrice']);
5093
5106
  return this.extend(request, params);
5094
5107
  }
5095
5108
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
@@ -5122,6 +5135,8 @@ class htx extends htx$1 {
5122
5135
  * @param {int} [params.leverRate] *contract only* required for all contract orders except tpsl, leverage greater than 20x requires prior approval of high-leverage agreement
5123
5136
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
5124
5137
  * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
5138
+ * @param {float} [params.trailingPercent] *contract only* the percent to trail away from the current market price
5139
+ * @param {float} [params.trailingTriggerPrice] *contract only* the price to trigger a trailing order, default uses the price argument
5125
5140
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
5126
5141
  */
5127
5142
  await this.loadMarkets();
@@ -5129,11 +5144,16 @@ class htx extends htx$1 {
5129
5144
  const triggerPrice = this.safeNumber2(params, 'stopPrice', 'trigger_price');
5130
5145
  const stopLossTriggerPrice = this.safeNumber2(params, 'stopLossPrice', 'sl_trigger_price');
5131
5146
  const takeProfitTriggerPrice = this.safeNumber2(params, 'takeProfitPrice', 'tp_trigger_price');
5147
+ const trailingPercent = this.safeNumber(params, 'trailingPercent');
5148
+ const isTrailingPercentOrder = trailingPercent !== undefined;
5132
5149
  const isStop = triggerPrice !== undefined;
5133
5150
  const isStopLossTriggerOrder = stopLossTriggerPrice !== undefined;
5134
5151
  const isTakeProfitTriggerOrder = takeProfitTriggerPrice !== undefined;
5135
5152
  let response = undefined;
5136
5153
  if (market['spot']) {
5154
+ if (isTrailingPercentOrder) {
5155
+ throw new errors.NotSupported(this.id + ' createOrder() does not support trailing orders for spot markets');
5156
+ }
5137
5157
  const spotRequest = await this.createSpotOrderRequest(symbol, type, side, amount, price, params);
5138
5158
  response = await this.spotPrivatePostV1OrderOrdersPlace(spotRequest);
5139
5159
  }
@@ -5150,6 +5170,9 @@ class htx extends htx$1 {
5150
5170
  else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
5151
5171
  response = await this.contractPrivatePostLinearSwapApiV1SwapTpslOrder(contractRequest);
5152
5172
  }
5173
+ else if (isTrailingPercentOrder) {
5174
+ response = await this.contractPrivatePostLinearSwapApiV1SwapTrackOrder(contractRequest);
5175
+ }
5153
5176
  else {
5154
5177
  response = await this.contractPrivatePostLinearSwapApiV1SwapOrder(contractRequest);
5155
5178
  }
@@ -5161,6 +5184,9 @@ class htx extends htx$1 {
5161
5184
  else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
5162
5185
  response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTpslOrder(contractRequest);
5163
5186
  }
5187
+ else if (isTrailingPercentOrder) {
5188
+ response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTrackOrder(contractRequest);
5189
+ }
5164
5190
  else {
5165
5191
  response = await this.contractPrivatePostLinearSwapApiV1SwapCrossOrder(contractRequest);
5166
5192
  }
@@ -5174,6 +5200,9 @@ class htx extends htx$1 {
5174
5200
  else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
5175
5201
  response = await this.contractPrivatePostSwapApiV1SwapTpslOrder(contractRequest);
5176
5202
  }
5203
+ else if (isTrailingPercentOrder) {
5204
+ response = await this.contractPrivatePostSwapApiV1SwapTrackOrder(contractRequest);
5205
+ }
5177
5206
  else {
5178
5207
  response = await this.contractPrivatePostSwapApiV1SwapOrder(contractRequest);
5179
5208
  }
@@ -5185,6 +5214,9 @@ class htx extends htx$1 {
5185
5214
  else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
5186
5215
  response = await this.contractPrivatePostApiV1ContractTpslOrder(contractRequest);
5187
5216
  }
5217
+ else if (isTrailingPercentOrder) {
5218
+ response = await this.contractPrivatePostApiV1ContractTrackOrder(contractRequest);
5219
+ }
5188
5220
  else {
5189
5221
  response = await this.contractPrivatePostApiV1ContractOrder(contractRequest);
5190
5222
  }
@@ -1278,7 +1278,7 @@ class kucoinfutures extends kucoinfutures$1 {
1278
1278
  * @see https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-multiple-futures-stop-orders
1279
1279
  * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1280
1280
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1281
- * @param {object} [params.stop] When true, all the trigger orders will be cancelled
1281
+ * @param {object} [params.trigger] When true, all the trigger orders will be cancelled
1282
1282
  * @returns Response from the exchange
1283
1283
  */
1284
1284
  await this.loadMarkets();
@@ -1286,8 +1286,8 @@ class kucoinfutures extends kucoinfutures$1 {
1286
1286
  if (symbol !== undefined) {
1287
1287
  request['symbol'] = this.marketId(symbol);
1288
1288
  }
1289
- const stop = this.safeValue(params, 'stop');
1290
- params = this.omit(params, 'stop');
1289
+ const stop = this.safeValue2(params, 'stop', 'trigger');
1290
+ params = this.omit(params, ['stop', 'trigger']);
1291
1291
  let response = undefined;
1292
1292
  if (stop) {
1293
1293
  response = await this.futuresPrivateDeleteStopOrders(this.extend(request, params));
@@ -1456,7 +1456,7 @@ class kucoinfutures extends kucoinfutures$1 {
1456
1456
  * @param {int} [since] timestamp in ms of the earliest order to retrieve
1457
1457
  * @param {int} [limit] The maximum number of orders to retrieve
1458
1458
  * @param {object} [params] exchange specific parameters
1459
- * @param {bool} [params.stop] set to true to retrieve untriggered stop orders
1459
+ * @param {bool} [params.trigger] set to true to retrieve untriggered stop orders
1460
1460
  * @param {int} [params.until] End time in ms
1461
1461
  * @param {string} [params.side] buy or sell
1462
1462
  * @param {string} [params.type] limit or market
@@ -1469,9 +1469,9 @@ class kucoinfutures extends kucoinfutures$1 {
1469
1469
  if (paginate) {
1470
1470
  return await this.fetchPaginatedCallDynamic('fetchOrdersByStatus', symbol, since, limit, params);
1471
1471
  }
1472
- const stop = this.safeValue(params, 'stop');
1472
+ const stop = this.safeValue2(params, 'stop', 'trigger');
1473
1473
  const until = this.safeInteger2(params, 'until', 'till');
1474
- params = this.omit(params, ['stop', 'until', 'till']);
1474
+ params = this.omit(params, ['stop', 'until', 'till', 'trigger']);
1475
1475
  if (status === 'closed') {
1476
1476
  status = 'done';
1477
1477
  }
@@ -1971,7 +1971,7 @@ class okcoin extends okcoin$1 {
1971
1971
  // 'ordId': id,
1972
1972
  };
1973
1973
  const clientOrderId = this.safeString2(params, 'clOrdId', 'clientOrderId');
1974
- const stop = this.safeValue(params, 'stop');
1974
+ const stop = this.safeValue2(params, 'stop', 'trigger');
1975
1975
  if (stop) {
1976
1976
  if (clientOrderId !== undefined) {
1977
1977
  request['algoClOrdId'] = clientOrderId;
@@ -1988,7 +1988,7 @@ class okcoin extends okcoin$1 {
1988
1988
  request['ordId'] = id;
1989
1989
  }
1990
1990
  }
1991
- const query = this.omit(params, ['clientOrderId', 'stop']);
1991
+ const query = this.omit(params, ['clientOrderId', 'stop', 'trigger']);
1992
1992
  let response = undefined;
1993
1993
  if (stop) {
1994
1994
  response = await this.privateGetTradeOrderAlgo(this.extend(request, query));