ccxt 4.1.98 → 4.1.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +101 -100
  2. package/dist/ccxt.browser.js +3162 -542
  3. package/dist/ccxt.browser.min.js +7 -7
  4. package/dist/cjs/ccxt.js +4 -1
  5. package/dist/cjs/src/abstract/bitteam.js +9 -0
  6. package/dist/cjs/src/base/Exchange.js +29 -0
  7. package/dist/cjs/src/bequant.js +1 -1
  8. package/dist/cjs/src/binance.js +84 -59
  9. package/dist/cjs/src/bingx.js +24 -7
  10. package/dist/cjs/src/bitget.js +98 -38
  11. package/dist/cjs/src/bitmart.js +71 -17
  12. package/dist/cjs/src/bitteam.js +2309 -0
  13. package/dist/cjs/src/bitvavo.js +52 -14
  14. package/dist/cjs/src/coinex.js +58 -21
  15. package/dist/cjs/src/kraken.js +21 -16
  16. package/dist/cjs/src/mexc.js +3 -3
  17. package/dist/cjs/src/okx.js +5 -4
  18. package/dist/cjs/src/pro/binance.js +1 -1
  19. package/dist/cjs/src/pro/bitget.js +1 -1
  20. package/dist/cjs/src/pro/bybit.js +1 -1
  21. package/dist/cjs/src/pro/kucoin.js +10 -2
  22. package/dist/cjs/src/pro/kucoinfutures.js +10 -2
  23. package/js/ccxt.d.ts +5 -2
  24. package/js/ccxt.js +4 -2
  25. package/js/src/abstract/binance.d.ts +16 -0
  26. package/js/src/abstract/binancecoinm.d.ts +16 -0
  27. package/js/src/abstract/binanceus.d.ts +16 -0
  28. package/js/src/abstract/binanceusdm.d.ts +16 -0
  29. package/js/src/abstract/bitteam.d.ts +32 -0
  30. package/js/src/abstract/bitteam.js +11 -0
  31. package/js/src/abstract/coinex.d.ts +14 -1
  32. package/js/src/base/Exchange.d.ts +4 -0
  33. package/js/src/base/Exchange.js +29 -0
  34. package/js/src/base/types.d.ts +1 -0
  35. package/js/src/bequant.js +1 -1
  36. package/js/src/binance.js +84 -59
  37. package/js/src/bingx.js +24 -7
  38. package/js/src/bitget.js +98 -38
  39. package/js/src/bitmart.js +71 -17
  40. package/js/src/bitteam.d.ts +46 -0
  41. package/js/src/bitteam.js +2310 -0
  42. package/js/src/bitvavo.js +52 -14
  43. package/js/src/coinex.js +58 -21
  44. package/js/src/kraken.js +21 -16
  45. package/js/src/mexc.js +3 -3
  46. package/js/src/okx.js +5 -4
  47. package/js/src/pro/binance.js +1 -1
  48. package/js/src/pro/bitget.js +1 -1
  49. package/js/src/pro/bybit.js +1 -1
  50. package/js/src/pro/kucoin.js +10 -2
  51. package/js/src/pro/kucoinfutures.js +10 -2
  52. package/package.json +1 -1
  53. package/skip-tests.json +13 -0
@@ -4000,6 +4000,9 @@ class bitget extends bitget$1 {
4000
4000
  * @param {float} [params.takeProfit.price] *swap only* the execution price for a take profit attached to a trigger order
4001
4001
  * @param {string} [params.stopLoss.type] *swap only* the type for a stop loss attached to a trigger order, 'fill_price', 'index_price' or 'mark_price', default is 'mark_price'
4002
4002
  * @param {string} [params.takeProfit.type] *swap only* the type for a take profit attached to a trigger order, 'fill_price', 'index_price' or 'mark_price', default is 'mark_price'
4003
+ * @param {string} [params.trailingPercent] *swap and future only* the percent to trail away from the current market price, rate can not be greater than 10
4004
+ * @param {string} [params.trailingTriggerPrice] *swap and future only* the price to trigger a trailing stop order, default uses the price argument
4005
+ * @param {string} [params.triggerType] *swap and future only* 'fill_price', 'mark_price' or 'index_price'
4003
4006
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4004
4007
  */
4005
4008
  await this.loadMarkets();
@@ -4009,6 +4012,8 @@ class bitget extends bitget$1 {
4009
4012
  const triggerPrice = this.safeValue2(params, 'stopPrice', 'triggerPrice');
4010
4013
  const stopLossTriggerPrice = this.safeValue(params, 'stopLossPrice');
4011
4014
  const takeProfitTriggerPrice = this.safeValue(params, 'takeProfitPrice');
4015
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRatio');
4016
+ const isTrailingPercentOrder = trailingPercent !== undefined;
4012
4017
  const isTriggerOrder = triggerPrice !== undefined;
4013
4018
  const isStopLossTriggerOrder = stopLossTriggerPrice !== undefined;
4014
4019
  const isTakeProfitTriggerOrder = takeProfitTriggerPrice !== undefined;
@@ -4030,7 +4035,7 @@ class bitget extends bitget$1 {
4030
4035
  }
4031
4036
  }
4032
4037
  else {
4033
- if (isTriggerOrder) {
4038
+ if (isTriggerOrder || isTrailingPercentOrder) {
4034
4039
  response = await this.privateMixPostV2MixOrderPlacePlanOrder(request);
4035
4040
  }
4036
4041
  else if (isStopLossOrTakeProfitTrigger) {
@@ -4085,8 +4090,11 @@ class bitget extends bitget$1 {
4085
4090
  const isTakeProfit = takeProfit !== undefined;
4086
4091
  const isStopLossOrTakeProfitTrigger = isStopLossTriggerOrder || isTakeProfitTriggerOrder;
4087
4092
  const isStopLossOrTakeProfit = isStopLoss || isTakeProfit;
4088
- if (this.sum(isTriggerOrder, isStopLossTriggerOrder, isTakeProfitTriggerOrder) > 1) {
4089
- throw new errors.ExchangeError(this.id + ' createOrder() params can only contain one of triggerPrice, stopLossPrice, takeProfitPrice');
4093
+ const trailingTriggerPrice = this.safeString(params, 'trailingTriggerPrice', price);
4094
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRatio');
4095
+ const isTrailingPercentOrder = trailingPercent !== undefined;
4096
+ if (this.sum(isTriggerOrder, isStopLossTriggerOrder, isTakeProfitTriggerOrder, isTrailingPercentOrder) > 1) {
4097
+ throw new errors.ExchangeError(this.id + ' createOrder() params can only contain one of triggerPrice, stopLossPrice, takeProfitPrice, trailingPercent');
4090
4098
  }
4091
4099
  if (type === 'limit') {
4092
4100
  request['price'] = this.priceToPrecision(symbol, price);
@@ -4111,7 +4119,7 @@ class bitget extends bitget$1 {
4111
4119
  else if (timeInForce === 'IOC') {
4112
4120
  request['force'] = 'IOC';
4113
4121
  }
4114
- params = this.omit(params, ['stopPrice', 'triggerType', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit', 'postOnly', 'reduceOnly', 'clientOrderId']);
4122
+ params = this.omit(params, ['stopPrice', 'triggerType', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit', 'postOnly', 'reduceOnly', 'clientOrderId', 'trailingPercent', 'trailingTriggerPrice']);
4115
4123
  if ((marketType === 'swap') || (marketType === 'future')) {
4116
4124
  request['marginCoin'] = market['settleId'];
4117
4125
  request['size'] = this.amountToPrecision(symbol, amount);
@@ -4121,34 +4129,21 @@ class bitget extends bitget$1 {
4121
4129
  if (clientOrderId !== undefined) {
4122
4130
  request['clientOid'] = clientOrderId;
4123
4131
  }
4124
- if (isTriggerOrder || isStopLossOrTakeProfitTrigger) {
4132
+ if (isTriggerOrder || isStopLossOrTakeProfitTrigger || isTrailingPercentOrder) {
4125
4133
  request['triggerType'] = triggerType;
4126
4134
  }
4127
- if (isStopLossOrTakeProfitTrigger) {
4135
+ if (isTrailingPercentOrder) {
4128
4136
  if (!isMarketOrder) {
4129
- throw new errors.ExchangeError(this.id + ' createOrder() bitget stopLoss or takeProfit orders must be market orders');
4130
- }
4131
- request['holdSide'] = (side === 'buy') ? 'long' : 'short';
4132
- }
4133
- else {
4134
- if (marginMode === undefined) {
4135
- marginMode = 'cross';
4136
- }
4137
- const marginModeRequest = (marginMode === 'cross') ? 'crossed' : 'isolated';
4138
- request['marginMode'] = marginModeRequest;
4139
- let requestSide = side;
4140
- if (reduceOnly) {
4141
- request['reduceOnly'] = 'YES';
4142
- request['tradeSide'] = 'Close';
4143
- // on bitget if the position is long the side is always buy, and if the position is short the side is always sell
4144
- requestSide = (side === 'buy') ? 'sell' : 'buy';
4137
+ throw new errors.BadRequest(this.id + ' createOrder() bitget trailing orders must be market orders');
4145
4138
  }
4146
- else {
4147
- request['tradeSide'] = 'Open';
4139
+ if (trailingTriggerPrice === undefined) {
4140
+ throw new errors.ArgumentsRequired(this.id + ' createOrder() bitget trailing orders must have a trailingTriggerPrice param');
4148
4141
  }
4149
- request['side'] = requestSide;
4142
+ request['planType'] = 'track_plan';
4143
+ request['triggerPrice'] = this.priceToPrecision(symbol, trailingTriggerPrice);
4144
+ request['callbackRatio'] = trailingPercent;
4150
4145
  }
4151
- if (isTriggerOrder) {
4146
+ else if (isTriggerOrder) {
4152
4147
  request['planType'] = 'normal_plan';
4153
4148
  request['triggerPrice'] = this.priceToPrecision(symbol, triggerPrice);
4154
4149
  if (price !== undefined) {
@@ -4172,6 +4167,10 @@ class bitget extends bitget$1 {
4172
4167
  }
4173
4168
  }
4174
4169
  else if (isStopLossOrTakeProfitTrigger) {
4170
+ if (!isMarketOrder) {
4171
+ throw new errors.ExchangeError(this.id + ' createOrder() bitget stopLoss or takeProfit orders must be market orders');
4172
+ }
4173
+ request['holdSide'] = (side === 'buy') ? 'long' : 'short';
4175
4174
  if (isStopLossTriggerOrder) {
4176
4175
  request['triggerPrice'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
4177
4176
  request['planType'] = 'pos_loss';
@@ -4191,6 +4190,24 @@ class bitget extends bitget$1 {
4191
4190
  request['presetStopSurplusPrice'] = this.priceToPrecision(symbol, tpTriggerPrice);
4192
4191
  }
4193
4192
  }
4193
+ if (!isStopLossOrTakeProfitTrigger) {
4194
+ if (marginMode === undefined) {
4195
+ marginMode = 'cross';
4196
+ }
4197
+ const marginModeRequest = (marginMode === 'cross') ? 'crossed' : 'isolated';
4198
+ request['marginMode'] = marginModeRequest;
4199
+ let requestSide = side;
4200
+ if (reduceOnly) {
4201
+ request['reduceOnly'] = 'YES';
4202
+ request['tradeSide'] = 'Close';
4203
+ // on bitget if the position is long the side is always buy, and if the position is short the side is always sell
4204
+ requestSide = (side === 'buy') ? 'sell' : 'buy';
4205
+ }
4206
+ else {
4207
+ request['tradeSide'] = 'Open';
4208
+ }
4209
+ request['side'] = requestSide;
4210
+ }
4194
4211
  }
4195
4212
  else if (marketType === 'spot') {
4196
4213
  if (isStopLossOrTakeProfitTrigger || isStopLossOrTakeProfit) {
@@ -4397,6 +4414,9 @@ class bitget extends bitget$1 {
4397
4414
  * @param {float} [params.takeProfit.price] *swap only* the execution price for a take profit attached to a trigger order
4398
4415
  * @param {string} [params.stopLoss.type] *swap only* the type for a stop loss attached to a trigger order, 'fill_price', 'index_price' or 'mark_price', default is 'mark_price'
4399
4416
  * @param {string} [params.takeProfit.type] *swap only* the type for a take profit attached to a trigger order, 'fill_price', 'index_price' or 'mark_price', default is 'mark_price'
4417
+ * @param {string} [params.trailingPercent] *swap and future only* the percent to trail away from the current market price, rate can not be greater than 10
4418
+ * @param {string} [params.trailingTriggerPrice] *swap and future only* the price to trigger a trailing stop order, default uses the price argument
4419
+ * @param {string} [params.newTriggerType] *swap and future only* 'fill_price', 'mark_price' or 'index_price'
4400
4420
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4401
4421
  */
4402
4422
  await this.loadMarkets();
@@ -4423,14 +4443,17 @@ class bitget extends bitget$1 {
4423
4443
  const takeProfit = this.safeValue(params, 'takeProfit');
4424
4444
  const isStopLoss = stopLoss !== undefined;
4425
4445
  const isTakeProfit = takeProfit !== undefined;
4426
- if (this.sum(isTriggerOrder, isStopLossOrder, isTakeProfitOrder) > 1) {
4427
- throw new errors.ExchangeError(this.id + ' editOrder() params can only contain one of triggerPrice, stopLossPrice, takeProfitPrice');
4446
+ const trailingTriggerPrice = this.safeString(params, 'trailingTriggerPrice', price);
4447
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'newCallbackRatio');
4448
+ const isTrailingPercentOrder = trailingPercent !== undefined;
4449
+ if (this.sum(isTriggerOrder, isStopLossOrder, isTakeProfitOrder, isTrailingPercentOrder) > 1) {
4450
+ throw new errors.ExchangeError(this.id + ' editOrder() params can only contain one of triggerPrice, stopLossPrice, takeProfitPrice, trailingPercent');
4428
4451
  }
4429
4452
  const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
4430
4453
  if (clientOrderId !== undefined) {
4431
4454
  request['clientOid'] = clientOrderId;
4432
4455
  }
4433
- params = this.omit(params, ['stopPrice', 'triggerType', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit', 'clientOrderId']);
4456
+ params = this.omit(params, ['stopPrice', 'triggerType', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit', 'clientOrderId', 'trailingTriggerPrice', 'trailingPercent']);
4434
4457
  let response = undefined;
4435
4458
  if (market['spot']) {
4436
4459
  const editMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'editMarketBuyOrderRequiresPrice', true);
@@ -4463,11 +4486,21 @@ class bitget extends bitget$1 {
4463
4486
  request['productType'] = productType;
4464
4487
  if (!isTakeProfitOrder && !isStopLossOrder) {
4465
4488
  request['newSize'] = this.amountToPrecision(symbol, amount);
4466
- if (price !== undefined) {
4489
+ if ((price !== undefined) && !isTrailingPercentOrder) {
4467
4490
  request['newPrice'] = this.priceToPrecision(symbol, price);
4468
4491
  }
4469
4492
  }
4470
- if (isTakeProfitOrder || isStopLossOrder) {
4493
+ if (isTrailingPercentOrder) {
4494
+ if (!isMarketOrder) {
4495
+ throw new errors.BadRequest(this.id + ' editOrder() bitget trailing orders must be market orders');
4496
+ }
4497
+ if (trailingTriggerPrice !== undefined) {
4498
+ request['newTriggerPrice'] = this.priceToPrecision(symbol, trailingTriggerPrice);
4499
+ }
4500
+ request['newCallbackRatio'] = trailingPercent;
4501
+ response = await this.privateMixPostV2MixOrderModifyPlanOrder(this.extend(request, params));
4502
+ }
4503
+ else if (isTakeProfitOrder || isStopLossOrder) {
4471
4504
  request['marginCoin'] = market['settleId'];
4472
4505
  request['size'] = this.amountToPrecision(symbol, amount);
4473
4506
  request['executePrice'] = this.priceToPrecision(symbol, price);
@@ -4546,6 +4579,7 @@ class bitget extends bitget$1 {
4546
4579
  * @param {string} [params.marginMode] 'isolated' or 'cross' for spot margin trading
4547
4580
  * @param {boolean} [params.stop] set to true for canceling trigger orders
4548
4581
  * @param {string} [params.planType] *swap only* either profit_plan, loss_plan, normal_plan, pos_profit, pos_loss, moving_plan or track_plan
4582
+ * @param {boolean} [params.trailing] set to true if you want to cancel a trailing order
4549
4583
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4550
4584
  */
4551
4585
  if (symbol === undefined) {
@@ -4565,8 +4599,9 @@ class bitget extends bitget$1 {
4565
4599
  let response = undefined;
4566
4600
  [marginMode, params] = this.handleMarginModeAndParams('cancelOrder', params);
4567
4601
  const request = {};
4568
- const stop = this.safeValue(params, 'stop');
4569
- params = this.omit(params, 'stop');
4602
+ const trailing = this.safeValue(params, 'trailing');
4603
+ const stop = this.safeValue2(params, 'stop', 'trigger');
4604
+ params = this.omit(params, ['stop', 'trigger', 'trailing']);
4570
4605
  if (!(market['spot'] && stop)) {
4571
4606
  request['symbol'] = market['id'];
4572
4607
  }
@@ -4577,13 +4612,20 @@ class bitget extends bitget$1 {
4577
4612
  let productType = undefined;
4578
4613
  [productType, params] = this.handleProductTypeAndParams(market, params);
4579
4614
  request['productType'] = productType;
4580
- if (stop) {
4615
+ if (stop || trailing) {
4581
4616
  const orderIdList = [];
4582
4617
  const orderId = {
4583
4618
  'orderId': id,
4584
4619
  };
4585
4620
  orderIdList.push(orderId);
4586
4621
  request['orderIdList'] = orderIdList;
4622
+ }
4623
+ if (trailing) {
4624
+ const planType = this.safeString(params, 'planType', 'track_plan');
4625
+ request['planType'] = planType;
4626
+ response = await this.privateMixPostV2MixOrderCancelPlanOrder(this.extend(request, params));
4627
+ }
4628
+ else if (stop) {
4587
4629
  response = await this.privateMixPostV2MixOrderCancelPlanOrder(this.extend(request, params));
4588
4630
  }
4589
4631
  else {
@@ -4975,6 +5017,9 @@ class bitget extends bitget$1 {
4975
5017
  // }
4976
5018
  // }
4977
5019
  //
5020
+ if (typeof response === 'string') {
5021
+ response = JSON.parse(response);
5022
+ }
4978
5023
  const data = this.safeValue(response, 'data');
4979
5024
  const first = this.safeValue(data, 0, data);
4980
5025
  return this.parseOrder(first, market);
@@ -4999,6 +5044,7 @@ class bitget extends bitget$1 {
4999
5044
  * @param {boolean} [params.stop] set to true for fetching trigger orders
5000
5045
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
5001
5046
  * @param {string} [params.isPlan] *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
5047
+ * @param {boolean} [params.trailing] set to true if you want to fetch trailing orders
5002
5048
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5003
5049
  */
5004
5050
  await this.loadMarkets();
@@ -5040,8 +5086,9 @@ class bitget extends bitget$1 {
5040
5086
  return await this.fetchPaginatedCallCursor('fetchOpenOrders', symbol, since, limit, params, cursorReceived, 'idLessThan');
5041
5087
  }
5042
5088
  let response = undefined;
5089
+ const trailing = this.safeValue(params, 'trailing');
5043
5090
  const stop = this.safeValue2(params, 'stop', 'trigger');
5044
- params = this.omit(params, ['stop', 'trigger']);
5091
+ params = this.omit(params, ['stop', 'trigger', 'trailing']);
5045
5092
  [request, params] = this.handleUntilOption('endTime', request, params);
5046
5093
  if (since !== undefined) {
5047
5094
  request['startTime'] = since;
@@ -5084,7 +5131,12 @@ class bitget extends bitget$1 {
5084
5131
  let productType = undefined;
5085
5132
  [productType, query] = this.handleProductTypeAndParams(market, query);
5086
5133
  request['productType'] = productType;
5087
- if (stop) {
5134
+ if (trailing) {
5135
+ const planType = this.safeString(params, 'planType', 'track_plan');
5136
+ request['planType'] = planType;
5137
+ response = await this.privateMixGetV2MixOrderOrdersPlanPending(this.extend(request, query));
5138
+ }
5139
+ else if (stop) {
5088
5140
  const planType = this.safeString(query, 'planType', 'normal_plan');
5089
5141
  request['planType'] = planType;
5090
5142
  response = await this.privateMixGetV2MixOrderOrdersPlanPending(this.extend(request, query));
@@ -5300,6 +5352,7 @@ class bitget extends bitget$1 {
5300
5352
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
5301
5353
  * @param {string} [params.isPlan] *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
5302
5354
  * @param {string} [params.productType] *contract only* 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
5355
+ * @param {boolean} [params.trailing] set to true if you want to fetch trailing orders
5303
5356
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5304
5357
  */
5305
5358
  await this.loadMarkets();
@@ -5337,6 +5390,7 @@ class bitget extends bitget$1 {
5337
5390
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
5338
5391
  * @param {string} [params.isPlan] *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
5339
5392
  * @param {string} [params.productType] *contract only* 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
5393
+ * @param {boolean} [params.trailing] set to true if you want to fetch trailing orders
5340
5394
  * @returns {object} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5341
5395
  */
5342
5396
  await this.loadMarkets();
@@ -5389,8 +5443,9 @@ class bitget extends bitget$1 {
5389
5443
  return await this.fetchPaginatedCallCursor('fetchCanceledAndClosedOrders', symbol, since, limit, params, cursorReceived, 'idLessThan');
5390
5444
  }
5391
5445
  let response = undefined;
5446
+ const trailing = this.safeValue(params, 'trailing');
5392
5447
  const stop = this.safeValue2(params, 'stop', 'trigger');
5393
- params = this.omit(params, ['stop', 'trigger']);
5448
+ params = this.omit(params, ['stop', 'trigger', 'trailing']);
5394
5449
  [request, params] = this.handleUntilOption('endTime', request, params);
5395
5450
  if (since !== undefined) {
5396
5451
  request['startTime'] = since;
@@ -5444,7 +5499,12 @@ class bitget extends bitget$1 {
5444
5499
  let productType = undefined;
5445
5500
  [productType, params] = this.handleProductTypeAndParams(market, params);
5446
5501
  request['productType'] = productType;
5447
- if (stop) {
5502
+ if (trailing) {
5503
+ const planType = this.safeString(params, 'planType', 'track_plan');
5504
+ request['planType'] = planType;
5505
+ response = await this.privateMixGetV2MixOrderOrdersPlanHistory(this.extend(request, params));
5506
+ }
5507
+ else if (stop) {
5448
5508
  const planType = this.safeString(params, 'planType', 'normal_plan');
5449
5509
  request['planType'] = planType;
5450
5510
  response = await this.privateMixGetV2MixOrderOrdersPlanHistory(this.extend(request, params));
@@ -2125,7 +2125,7 @@ class bitmart extends bitmart$1 {
2125
2125
  if (priceString === 'market price') {
2126
2126
  priceString = undefined;
2127
2127
  }
2128
- const trailingStopActivationPrice = this.safeNumber(order, 'activation_price');
2128
+ const trailingActivationPrice = this.safeNumber(order, 'activation_price');
2129
2129
  return this.safeOrder({
2130
2130
  'id': id,
2131
2131
  'clientOrderId': this.safeString(order, 'client_order_id'),
@@ -2139,8 +2139,8 @@ class bitmart extends bitmart$1 {
2139
2139
  'postOnly': postOnly,
2140
2140
  'side': this.parseOrderSide(this.safeString(order, 'side')),
2141
2141
  'price': this.omitZero(priceString),
2142
- 'stopPrice': trailingStopActivationPrice,
2143
- 'triggerPrice': trailingStopActivationPrice,
2142
+ 'stopPrice': trailingActivationPrice,
2143
+ 'triggerPrice': trailingActivationPrice,
2144
2144
  'amount': this.omitZero(this.safeString(order, 'size')),
2145
2145
  'cost': this.safeString2(order, 'filled_notional', 'filledNotional'),
2146
2146
  'average': this.safeStringN(order, ['price_avg', 'priceAvg', 'deal_avg_price']),
@@ -2212,6 +2212,7 @@ class bitmart extends bitmart$1 {
2212
2212
  * @see https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
2213
2213
  * @see https://developer-pro.bitmart.com/en/spot/#place-margin-order
2214
2214
  * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2215
+ * @see https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2215
2216
  * @param {string} symbol unified symbol of the market to create an order in
2216
2217
  * @param {string} type 'market', 'limit' or 'trailing' for swap markets only
2217
2218
  * @param {string} side 'buy' or 'sell'
@@ -2223,12 +2224,20 @@ class bitmart extends bitmart$1 {
2223
2224
  * @param {string} [params.clientOrderId] client order id of the order
2224
2225
  * @param {boolean} [params.reduceOnly] *swap only* reduce only
2225
2226
  * @param {boolean} [params.postOnly] make sure the order is posted to the order book and not matched immediately
2227
+ * @param {string} [params.triggerPrice] *swap only* the price to trigger a stop order
2228
+ * @param {int} [params.price_type] *swap only* 1: last price, 2: fair price, default is 1
2229
+ * @param {int} [params.price_way] *swap only* 1: price way long, 2: price way short
2230
+ * @param {int} [params.activation_price_type] *swap trailing order only* 1: last price, 2: fair price, default is 1
2231
+ * @param {string} [params.trailingPercent] *swap only* the percent to trail away from the current market price, min 0.1 max 5
2232
+ * @param {string} [params.trailingTriggerPrice] *swap only* the price to trigger a trailing order, default uses the price argument
2226
2233
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2227
2234
  */
2228
2235
  await this.loadMarkets();
2229
2236
  const market = this.market(symbol);
2230
2237
  const result = this.handleMarginModeAndParams('createOrder', params);
2231
2238
  const marginMode = this.safeString(result, 0);
2239
+ const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
2240
+ const isTriggerOrder = triggerPrice !== undefined;
2232
2241
  let response = undefined;
2233
2242
  if (market['spot']) {
2234
2243
  const spotRequest = this.createSpotOrderRequest(symbol, type, side, amount, price, params);
@@ -2241,7 +2250,12 @@ class bitmart extends bitmart$1 {
2241
2250
  }
2242
2251
  else {
2243
2252
  const swapRequest = this.createSwapOrderRequest(symbol, type, side, amount, price, params);
2244
- response = await this.privatePostContractPrivateSubmitOrder(swapRequest);
2253
+ if (isTriggerOrder) {
2254
+ response = await this.privatePostContractPrivateSubmitPlanOrder(swapRequest);
2255
+ }
2256
+ else {
2257
+ response = await this.privatePostContractPrivateSubmitOrder(swapRequest);
2258
+ }
2245
2259
  }
2246
2260
  //
2247
2261
  // spot and margin
@@ -2273,6 +2287,7 @@ class bitmart extends bitmart$1 {
2273
2287
  * @ignore
2274
2288
  * @description create a trade order
2275
2289
  * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2290
+ * @see https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2276
2291
  * @param {string} symbol unified symbol of the market to create an order in
2277
2292
  * @param {string} type 'market', 'limit' or 'trailing'
2278
2293
  * @param {string} side 'buy' or 'sell'
@@ -2283,8 +2298,12 @@ class bitmart extends bitmart$1 {
2283
2298
  * @param {boolean} [params.reduceOnly] *swap only* reduce only
2284
2299
  * @param {string} [params.marginMode] 'cross' or 'isolated', default is 'cross'
2285
2300
  * @param {string} [params.clientOrderId] client order id of the order
2301
+ * @param {string} [params.triggerPrice] *swap only* the price to trigger a stop order
2302
+ * @param {int} [params.price_type] *swap only* 1: last price, 2: fair price, default is 1
2303
+ * @param {int} [params.price_way] *swap only* 1: price way long, 2: price way short
2286
2304
  * @param {int} [params.activation_price_type] *swap trailing order only* 1: last price, 2: fair price, default is 1
2287
- * @param {string} [params.callback_rate] *swap trailing order only* min 0.1, max 5 where 1 is 1%, default is "1"
2305
+ * @param {string} [params.trailingPercent] *swap only* the percent to trail away from the current market price, min 0.1 max 5
2306
+ * @param {string} [params.trailingTriggerPrice] *swap only* the price to trigger a trailing order, default uses the price argument
2288
2307
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2289
2308
  */
2290
2309
  const market = this.market(symbol);
@@ -2297,10 +2316,9 @@ class bitmart extends bitmart$1 {
2297
2316
  const mode = this.safeInteger(params, 'mode'); // only for swap
2298
2317
  const isMarketOrder = type === 'market';
2299
2318
  let postOnly = undefined;
2300
- let reduceOnly = this.safeValue(params, 'reduceOnly');
2319
+ const reduceOnly = this.safeValue(params, 'reduceOnly');
2301
2320
  const isExchangeSpecificPo = (mode === 4);
2302
2321
  [postOnly, params] = this.handlePostOnly(isMarketOrder, isExchangeSpecificPo, params);
2303
- params = this.omit(params, ['timeInForce', 'postOnly', 'reduceOnly']);
2304
2322
  const ioc = ((timeInForce === 'IOC') || (mode === 3));
2305
2323
  const isLimitOrder = (type === 'limit') || postOnly || ioc;
2306
2324
  if (timeInForce === 'GTC') {
@@ -2315,14 +2333,39 @@ class bitmart extends bitmart$1 {
2315
2333
  if (postOnly) {
2316
2334
  request['mode'] = 4;
2317
2335
  }
2336
+ const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
2337
+ const isTriggerOrder = triggerPrice !== undefined;
2338
+ const trailingTriggerPrice = this.safeString2(params, 'trailingTriggerPrice', 'activation_price', price);
2339
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callback_rate');
2340
+ const isTrailingPercentOrder = trailingPercent !== undefined;
2318
2341
  if (isLimitOrder) {
2319
2342
  request['price'] = this.priceToPrecision(symbol, price);
2320
2343
  }
2321
- else if (type === 'trailing') {
2322
- reduceOnly = true;
2323
- request['activation_price'] = this.priceToPrecision(symbol, price);
2344
+ else if (type === 'trailing' || isTrailingPercentOrder) {
2345
+ request['callback_rate'] = trailingPercent;
2346
+ request['activation_price'] = this.priceToPrecision(symbol, trailingTriggerPrice);
2324
2347
  request['activation_price_type'] = this.safeInteger(params, 'activation_price_type', 1);
2325
- request['callback_rate'] = this.safeString(params, 'callback_rate', '1');
2348
+ }
2349
+ if (isTriggerOrder) {
2350
+ request['executive_price'] = this.priceToPrecision(symbol, price);
2351
+ request['trigger_price'] = this.priceToPrecision(symbol, triggerPrice);
2352
+ request['price_type'] = this.safeInteger(params, 'price_type', 1);
2353
+ if (side === 'buy') {
2354
+ if (reduceOnly) {
2355
+ request['price_way'] = 2;
2356
+ }
2357
+ else {
2358
+ request['price_way'] = 1;
2359
+ }
2360
+ }
2361
+ else if (side === 'sell') {
2362
+ if (reduceOnly) {
2363
+ request['price_way'] = 1;
2364
+ }
2365
+ else {
2366
+ request['price_way'] = 2;
2367
+ }
2368
+ }
2326
2369
  }
2327
2370
  if (side === 'buy') {
2328
2371
  if (reduceOnly) {
@@ -2349,7 +2392,7 @@ class bitmart extends bitmart$1 {
2349
2392
  request['client_order_id'] = clientOrderId;
2350
2393
  }
2351
2394
  const leverage = this.safeInteger(params, 'leverage', 1);
2352
- params = this.omit(params, 'leverage');
2395
+ params = this.omit(params, ['timeInForce', 'postOnly', 'reduceOnly', 'leverage', 'trailingTriggerPrice', 'trailingPercent', 'triggerPrice', 'stopPrice']);
2353
2396
  request['leverage'] = this.numberToString(leverage);
2354
2397
  return this.extend(request, params);
2355
2398
  }
@@ -2431,10 +2474,11 @@ class bitmart extends bitmart$1 {
2431
2474
  /**
2432
2475
  * @method
2433
2476
  * @name bitmart#cancelOrder
2477
+ * @description cancels an open order
2434
2478
  * @see https://developer-pro.bitmart.com/en/futures/#cancel-order-signed
2435
2479
  * @see https://developer-pro.bitmart.com/en/spot/#cancel-order-v3-signed
2436
2480
  * @see https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2437
- * @description cancels an open order
2481
+ * @see https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2438
2482
  * @param {string} id order id
2439
2483
  * @param {string} symbol unified symbol of the market the order was made in
2440
2484
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2644,6 +2688,7 @@ class bitmart extends bitmart$1 {
2644
2688
  * @param {string} [params.type] *swap* order type, 'limit' or 'market'
2645
2689
  * @param {string} [params.order_state] *swap* the order state, 'all' or 'partially_filled', default is 'all'
2646
2690
  * @param {string} [params.orderType] *swap only* 'limit', 'market', or 'trailing'
2691
+ * @param {boolean} [params.trailing] *swap only* set to true if you want to fetch trailing orders
2647
2692
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2648
2693
  */
2649
2694
  await this.loadMarkets();
@@ -2676,8 +2721,12 @@ class bitmart extends bitmart$1 {
2676
2721
  response = await this.privatePostSpotV4QueryOpenOrders(this.extend(request, params));
2677
2722
  }
2678
2723
  else if (type === 'swap') {
2679
- const orderType = this.safeString(params, 'orderType');
2680
- params = this.omit(params, 'orderType');
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';
2729
+ }
2681
2730
  if (orderType !== undefined) {
2682
2731
  request['type'] = orderType;
2683
2732
  }
@@ -2823,6 +2872,7 @@ class bitmart extends bitmart$1 {
2823
2872
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2824
2873
  * @param {string} [params.clientOrderId] *spot* fetch the order by client order id instead of order id
2825
2874
  * @param {string} [params.orderType] *swap only* 'limit', 'market', 'liquidate', 'bankruptcy', 'adl' or 'trailing'
2875
+ * @param {boolean} [params.trailing] *swap only* set to true if you want to fetch a trailing order
2826
2876
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2827
2877
  */
2828
2878
  await this.loadMarkets();
@@ -2850,8 +2900,12 @@ class bitmart extends bitmart$1 {
2850
2900
  if (symbol === undefined) {
2851
2901
  throw new errors.ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
2852
2902
  }
2853
- const orderType = this.safeString(params, 'orderType');
2854
- params = this.omit(params, 'orderType');
2903
+ const trailing = this.safeValue(params, 'trailing', false);
2904
+ let orderType = this.safeString(params, 'orderType');
2905
+ params = this.omit(params, ['orderType', 'trailing']);
2906
+ if (trailing) {
2907
+ orderType = 'trailing';
2908
+ }
2855
2909
  if (orderType !== undefined) {
2856
2910
  request['type'] = orderType;
2857
2911
  }