ccxt 4.1.97 → 4.1.99

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 (46) hide show
  1. package/README.md +3 -3
  2. package/build.sh +1 -1
  3. package/dist/ccxt.browser.js +524 -230
  4. package/dist/ccxt.browser.min.js +2 -2
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/base/Exchange.js +29 -0
  7. package/dist/cjs/src/binance.js +113 -91
  8. package/dist/cjs/src/bingx.js +58 -9
  9. package/dist/cjs/src/bitget.js +108 -51
  10. package/dist/cjs/src/bitmart.js +71 -17
  11. package/dist/cjs/src/bitvavo.js +52 -14
  12. package/dist/cjs/src/coinex.js +58 -21
  13. package/dist/cjs/src/kraken.js +21 -16
  14. package/dist/cjs/src/phemex.js +3 -3
  15. package/dist/cjs/src/pro/binance.js +1 -1
  16. package/dist/cjs/src/pro/bingx.js +6 -3
  17. package/dist/cjs/src/pro/bitget.js +1 -1
  18. package/dist/cjs/src/pro/bitmart.js +1 -1
  19. package/dist/cjs/src/pro/bybit.js +1 -1
  20. package/js/ccxt.d.ts +1 -1
  21. package/js/ccxt.js +1 -1
  22. package/js/src/abstract/binance.d.ts +16 -0
  23. package/js/src/abstract/binancecoinm.d.ts +16 -0
  24. package/js/src/abstract/binanceus.d.ts +16 -0
  25. package/js/src/abstract/binanceusdm.d.ts +16 -0
  26. package/js/src/abstract/coinex.d.ts +14 -1
  27. package/js/src/base/Exchange.d.ts +4 -0
  28. package/js/src/base/Exchange.js +29 -0
  29. package/js/src/binance.js +113 -91
  30. package/js/src/bingx.d.ts +1 -0
  31. package/js/src/bingx.js +58 -9
  32. package/js/src/bitget.js +108 -51
  33. package/js/src/bitmart.js +71 -17
  34. package/js/src/bitvavo.js +52 -14
  35. package/js/src/coinex.js +58 -21
  36. package/js/src/kraken.js +21 -16
  37. package/js/src/phemex.js +3 -3
  38. package/js/src/pro/binance.js +1 -1
  39. package/js/src/pro/bingx.js +6 -3
  40. package/js/src/pro/bitget.js +1 -1
  41. package/js/src/pro/bitmart.js +1 -1
  42. package/js/src/pro/bybit.js +1 -1
  43. package/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.d.ts +1 -1
  44. package/package.json +13 -13
  45. package/skip-tests.json +119 -71
  46. package/run-tests-ws.js +0 -290
package/js/src/bitget.js CHANGED
@@ -1281,12 +1281,12 @@ export default class bitget extends Exchange {
1281
1281
  '30m': '30min',
1282
1282
  '1h': '1h',
1283
1283
  '4h': '4h',
1284
- '6h': '6h',
1285
- '12h': '12h',
1286
- '1d': '1day',
1287
- '3d': '3day',
1288
- '1w': '1week',
1289
- '1M': '1M',
1284
+ '6h': '6Hutc',
1285
+ '12h': '12Hutc',
1286
+ '1d': '1Dutc',
1287
+ '3d': '3Dutc',
1288
+ '1w': '1Wutc',
1289
+ '1M': '1Mutc',
1290
1290
  },
1291
1291
  'swap': {
1292
1292
  '1m': '1m',
@@ -1297,12 +1297,12 @@ export default class bitget extends Exchange {
1297
1297
  '1h': '1H',
1298
1298
  '2h': '2H',
1299
1299
  '4h': '4H',
1300
- '6h': '6H',
1301
- '12h': '12H',
1302
- '1d': '1D',
1303
- '3d': '3D',
1304
- '1w': '1W',
1305
- '1M': '1M',
1300
+ '6h': '6Hutc',
1301
+ '12h': '12Hutc',
1302
+ '1d': '1Dutc',
1303
+ '3d': '3Dutc',
1304
+ '1w': '1Wutc',
1305
+ '1M': '1Mutc',
1306
1306
  },
1307
1307
  },
1308
1308
  'fetchMarkets': [
@@ -2904,7 +2904,7 @@ export default class bitget extends Exchange {
2904
2904
  const currencyCode = this.safeCurrencyCode(this.safeString(feeStructure, 'feeCoin'));
2905
2905
  fee = {
2906
2906
  'currency': currencyCode,
2907
- 'cost': Precise.stringNeg(this.safeString(feeStructure, 'totalFee')),
2907
+ 'cost': Precise.stringAbs(this.safeString(feeStructure, 'totalFee')),
2908
2908
  };
2909
2909
  }
2910
2910
  return this.safeTrade({
@@ -4003,6 +4003,9 @@ export default class bitget extends Exchange {
4003
4003
  * @param {float} [params.takeProfit.price] *swap only* the execution price for a take profit attached to a trigger order
4004
4004
  * @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'
4005
4005
  * @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'
4006
+ * @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
4007
+ * @param {string} [params.trailingTriggerPrice] *swap and future only* the price to trigger a trailing stop order, default uses the price argument
4008
+ * @param {string} [params.triggerType] *swap and future only* 'fill_price', 'mark_price' or 'index_price'
4006
4009
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4007
4010
  */
4008
4011
  await this.loadMarkets();
@@ -4012,6 +4015,8 @@ export default class bitget extends Exchange {
4012
4015
  const triggerPrice = this.safeValue2(params, 'stopPrice', 'triggerPrice');
4013
4016
  const stopLossTriggerPrice = this.safeValue(params, 'stopLossPrice');
4014
4017
  const takeProfitTriggerPrice = this.safeValue(params, 'takeProfitPrice');
4018
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRatio');
4019
+ const isTrailingPercentOrder = trailingPercent !== undefined;
4015
4020
  const isTriggerOrder = triggerPrice !== undefined;
4016
4021
  const isStopLossTriggerOrder = stopLossTriggerPrice !== undefined;
4017
4022
  const isTakeProfitTriggerOrder = takeProfitTriggerPrice !== undefined;
@@ -4033,7 +4038,7 @@ export default class bitget extends Exchange {
4033
4038
  }
4034
4039
  }
4035
4040
  else {
4036
- if (isTriggerOrder) {
4041
+ if (isTriggerOrder || isTrailingPercentOrder) {
4037
4042
  response = await this.privateMixPostV2MixOrderPlacePlanOrder(request);
4038
4043
  }
4039
4044
  else if (isStopLossOrTakeProfitTrigger) {
@@ -4088,8 +4093,11 @@ export default class bitget extends Exchange {
4088
4093
  const isTakeProfit = takeProfit !== undefined;
4089
4094
  const isStopLossOrTakeProfitTrigger = isStopLossTriggerOrder || isTakeProfitTriggerOrder;
4090
4095
  const isStopLossOrTakeProfit = isStopLoss || isTakeProfit;
4091
- if (this.sum(isTriggerOrder, isStopLossTriggerOrder, isTakeProfitTriggerOrder) > 1) {
4092
- throw new ExchangeError(this.id + ' createOrder() params can only contain one of triggerPrice, stopLossPrice, takeProfitPrice');
4096
+ const trailingTriggerPrice = this.safeString(params, 'trailingTriggerPrice', price);
4097
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRatio');
4098
+ const isTrailingPercentOrder = trailingPercent !== undefined;
4099
+ if (this.sum(isTriggerOrder, isStopLossTriggerOrder, isTakeProfitTriggerOrder, isTrailingPercentOrder) > 1) {
4100
+ throw new ExchangeError(this.id + ' createOrder() params can only contain one of triggerPrice, stopLossPrice, takeProfitPrice, trailingPercent');
4093
4101
  }
4094
4102
  if (type === 'limit') {
4095
4103
  request['price'] = this.priceToPrecision(symbol, price);
@@ -4114,7 +4122,7 @@ export default class bitget extends Exchange {
4114
4122
  else if (timeInForce === 'IOC') {
4115
4123
  request['force'] = 'IOC';
4116
4124
  }
4117
- params = this.omit(params, ['stopPrice', 'triggerType', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit', 'postOnly', 'reduceOnly', 'clientOrderId']);
4125
+ params = this.omit(params, ['stopPrice', 'triggerType', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit', 'postOnly', 'reduceOnly', 'clientOrderId', 'trailingPercent', 'trailingTriggerPrice']);
4118
4126
  if ((marketType === 'swap') || (marketType === 'future')) {
4119
4127
  request['marginCoin'] = market['settleId'];
4120
4128
  request['size'] = this.amountToPrecision(symbol, amount);
@@ -4124,34 +4132,21 @@ export default class bitget extends Exchange {
4124
4132
  if (clientOrderId !== undefined) {
4125
4133
  request['clientOid'] = clientOrderId;
4126
4134
  }
4127
- if (isTriggerOrder || isStopLossOrTakeProfitTrigger) {
4135
+ if (isTriggerOrder || isStopLossOrTakeProfitTrigger || isTrailingPercentOrder) {
4128
4136
  request['triggerType'] = triggerType;
4129
4137
  }
4130
- if (isStopLossOrTakeProfitTrigger) {
4138
+ if (isTrailingPercentOrder) {
4131
4139
  if (!isMarketOrder) {
4132
- throw new ExchangeError(this.id + ' createOrder() bitget stopLoss or takeProfit orders must be market orders');
4140
+ throw new BadRequest(this.id + ' createOrder() bitget trailing orders must be market orders');
4133
4141
  }
4134
- request['holdSide'] = (side === 'buy') ? 'long' : 'short';
4135
- }
4136
- else {
4137
- if (marginMode === undefined) {
4138
- marginMode = 'cross';
4142
+ if (trailingTriggerPrice === undefined) {
4143
+ throw new ArgumentsRequired(this.id + ' createOrder() bitget trailing orders must have a trailingTriggerPrice param');
4139
4144
  }
4140
- const marginModeRequest = (marginMode === 'cross') ? 'crossed' : 'isolated';
4141
- request['marginMode'] = marginModeRequest;
4142
- let requestSide = side;
4143
- if (reduceOnly) {
4144
- request['reduceOnly'] = 'YES';
4145
- request['tradeSide'] = 'Close';
4146
- // on bitget if the position is long the side is always buy, and if the position is short the side is always sell
4147
- requestSide = (side === 'buy') ? 'sell' : 'buy';
4148
- }
4149
- else {
4150
- request['tradeSide'] = 'Open';
4151
- }
4152
- request['side'] = requestSide;
4145
+ request['planType'] = 'track_plan';
4146
+ request['triggerPrice'] = this.priceToPrecision(symbol, trailingTriggerPrice);
4147
+ request['callbackRatio'] = trailingPercent;
4153
4148
  }
4154
- if (isTriggerOrder) {
4149
+ else if (isTriggerOrder) {
4155
4150
  request['planType'] = 'normal_plan';
4156
4151
  request['triggerPrice'] = this.priceToPrecision(symbol, triggerPrice);
4157
4152
  if (price !== undefined) {
@@ -4175,6 +4170,10 @@ export default class bitget extends Exchange {
4175
4170
  }
4176
4171
  }
4177
4172
  else if (isStopLossOrTakeProfitTrigger) {
4173
+ if (!isMarketOrder) {
4174
+ throw new ExchangeError(this.id + ' createOrder() bitget stopLoss or takeProfit orders must be market orders');
4175
+ }
4176
+ request['holdSide'] = (side === 'buy') ? 'long' : 'short';
4178
4177
  if (isStopLossTriggerOrder) {
4179
4178
  request['triggerPrice'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
4180
4179
  request['planType'] = 'pos_loss';
@@ -4194,6 +4193,24 @@ export default class bitget extends Exchange {
4194
4193
  request['presetStopSurplusPrice'] = this.priceToPrecision(symbol, tpTriggerPrice);
4195
4194
  }
4196
4195
  }
4196
+ if (!isStopLossOrTakeProfitTrigger) {
4197
+ if (marginMode === undefined) {
4198
+ marginMode = 'cross';
4199
+ }
4200
+ const marginModeRequest = (marginMode === 'cross') ? 'crossed' : 'isolated';
4201
+ request['marginMode'] = marginModeRequest;
4202
+ let requestSide = side;
4203
+ if (reduceOnly) {
4204
+ request['reduceOnly'] = 'YES';
4205
+ request['tradeSide'] = 'Close';
4206
+ // on bitget if the position is long the side is always buy, and if the position is short the side is always sell
4207
+ requestSide = (side === 'buy') ? 'sell' : 'buy';
4208
+ }
4209
+ else {
4210
+ request['tradeSide'] = 'Open';
4211
+ }
4212
+ request['side'] = requestSide;
4213
+ }
4197
4214
  }
4198
4215
  else if (marketType === 'spot') {
4199
4216
  if (isStopLossOrTakeProfitTrigger || isStopLossOrTakeProfit) {
@@ -4400,6 +4417,9 @@ export default class bitget extends Exchange {
4400
4417
  * @param {float} [params.takeProfit.price] *swap only* the execution price for a take profit attached to a trigger order
4401
4418
  * @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'
4402
4419
  * @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'
4420
+ * @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
4421
+ * @param {string} [params.trailingTriggerPrice] *swap and future only* the price to trigger a trailing stop order, default uses the price argument
4422
+ * @param {string} [params.newTriggerType] *swap and future only* 'fill_price', 'mark_price' or 'index_price'
4403
4423
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4404
4424
  */
4405
4425
  await this.loadMarkets();
@@ -4426,14 +4446,17 @@ export default class bitget extends Exchange {
4426
4446
  const takeProfit = this.safeValue(params, 'takeProfit');
4427
4447
  const isStopLoss = stopLoss !== undefined;
4428
4448
  const isTakeProfit = takeProfit !== undefined;
4429
- if (this.sum(isTriggerOrder, isStopLossOrder, isTakeProfitOrder) > 1) {
4430
- throw new ExchangeError(this.id + ' editOrder() params can only contain one of triggerPrice, stopLossPrice, takeProfitPrice');
4449
+ const trailingTriggerPrice = this.safeString(params, 'trailingTriggerPrice', price);
4450
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'newCallbackRatio');
4451
+ const isTrailingPercentOrder = trailingPercent !== undefined;
4452
+ if (this.sum(isTriggerOrder, isStopLossOrder, isTakeProfitOrder, isTrailingPercentOrder) > 1) {
4453
+ throw new ExchangeError(this.id + ' editOrder() params can only contain one of triggerPrice, stopLossPrice, takeProfitPrice, trailingPercent');
4431
4454
  }
4432
4455
  const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
4433
4456
  if (clientOrderId !== undefined) {
4434
4457
  request['clientOid'] = clientOrderId;
4435
4458
  }
4436
- params = this.omit(params, ['stopPrice', 'triggerType', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit', 'clientOrderId']);
4459
+ params = this.omit(params, ['stopPrice', 'triggerType', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit', 'clientOrderId', 'trailingTriggerPrice', 'trailingPercent']);
4437
4460
  let response = undefined;
4438
4461
  if (market['spot']) {
4439
4462
  const editMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'editMarketBuyOrderRequiresPrice', true);
@@ -4466,11 +4489,21 @@ export default class bitget extends Exchange {
4466
4489
  request['productType'] = productType;
4467
4490
  if (!isTakeProfitOrder && !isStopLossOrder) {
4468
4491
  request['newSize'] = this.amountToPrecision(symbol, amount);
4469
- if (price !== undefined) {
4492
+ if ((price !== undefined) && !isTrailingPercentOrder) {
4470
4493
  request['newPrice'] = this.priceToPrecision(symbol, price);
4471
4494
  }
4472
4495
  }
4473
- if (isTakeProfitOrder || isStopLossOrder) {
4496
+ if (isTrailingPercentOrder) {
4497
+ if (!isMarketOrder) {
4498
+ throw new BadRequest(this.id + ' editOrder() bitget trailing orders must be market orders');
4499
+ }
4500
+ if (trailingTriggerPrice !== undefined) {
4501
+ request['newTriggerPrice'] = this.priceToPrecision(symbol, trailingTriggerPrice);
4502
+ }
4503
+ request['newCallbackRatio'] = trailingPercent;
4504
+ response = await this.privateMixPostV2MixOrderModifyPlanOrder(this.extend(request, params));
4505
+ }
4506
+ else if (isTakeProfitOrder || isStopLossOrder) {
4474
4507
  request['marginCoin'] = market['settleId'];
4475
4508
  request['size'] = this.amountToPrecision(symbol, amount);
4476
4509
  request['executePrice'] = this.priceToPrecision(symbol, price);
@@ -4549,6 +4582,7 @@ export default class bitget extends Exchange {
4549
4582
  * @param {string} [params.marginMode] 'isolated' or 'cross' for spot margin trading
4550
4583
  * @param {boolean} [params.stop] set to true for canceling trigger orders
4551
4584
  * @param {string} [params.planType] *swap only* either profit_plan, loss_plan, normal_plan, pos_profit, pos_loss, moving_plan or track_plan
4585
+ * @param {boolean} [params.trailing] set to true if you want to cancel a trailing order
4552
4586
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4553
4587
  */
4554
4588
  if (symbol === undefined) {
@@ -4568,8 +4602,9 @@ export default class bitget extends Exchange {
4568
4602
  let response = undefined;
4569
4603
  [marginMode, params] = this.handleMarginModeAndParams('cancelOrder', params);
4570
4604
  const request = {};
4571
- const stop = this.safeValue(params, 'stop');
4572
- params = this.omit(params, 'stop');
4605
+ const trailing = this.safeValue(params, 'trailing');
4606
+ const stop = this.safeValue2(params, 'stop', 'trigger');
4607
+ params = this.omit(params, ['stop', 'trigger', 'trailing']);
4573
4608
  if (!(market['spot'] && stop)) {
4574
4609
  request['symbol'] = market['id'];
4575
4610
  }
@@ -4580,13 +4615,20 @@ export default class bitget extends Exchange {
4580
4615
  let productType = undefined;
4581
4616
  [productType, params] = this.handleProductTypeAndParams(market, params);
4582
4617
  request['productType'] = productType;
4583
- if (stop) {
4618
+ if (stop || trailing) {
4584
4619
  const orderIdList = [];
4585
4620
  const orderId = {
4586
4621
  'orderId': id,
4587
4622
  };
4588
4623
  orderIdList.push(orderId);
4589
4624
  request['orderIdList'] = orderIdList;
4625
+ }
4626
+ if (trailing) {
4627
+ const planType = this.safeString(params, 'planType', 'track_plan');
4628
+ request['planType'] = planType;
4629
+ response = await this.privateMixPostV2MixOrderCancelPlanOrder(this.extend(request, params));
4630
+ }
4631
+ else if (stop) {
4590
4632
  response = await this.privateMixPostV2MixOrderCancelPlanOrder(this.extend(request, params));
4591
4633
  }
4592
4634
  else {
@@ -5002,6 +5044,7 @@ export default class bitget extends Exchange {
5002
5044
  * @param {boolean} [params.stop] set to true for fetching trigger orders
5003
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)
5004
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
5005
5048
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5006
5049
  */
5007
5050
  await this.loadMarkets();
@@ -5043,8 +5086,9 @@ export default class bitget extends Exchange {
5043
5086
  return await this.fetchPaginatedCallCursor('fetchOpenOrders', symbol, since, limit, params, cursorReceived, 'idLessThan');
5044
5087
  }
5045
5088
  let response = undefined;
5089
+ const trailing = this.safeValue(params, 'trailing');
5046
5090
  const stop = this.safeValue2(params, 'stop', 'trigger');
5047
- params = this.omit(params, ['stop', 'trigger']);
5091
+ params = this.omit(params, ['stop', 'trigger', 'trailing']);
5048
5092
  [request, params] = this.handleUntilOption('endTime', request, params);
5049
5093
  if (since !== undefined) {
5050
5094
  request['startTime'] = since;
@@ -5087,7 +5131,12 @@ export default class bitget extends Exchange {
5087
5131
  let productType = undefined;
5088
5132
  [productType, query] = this.handleProductTypeAndParams(market, query);
5089
5133
  request['productType'] = productType;
5090
- 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) {
5091
5140
  const planType = this.safeString(query, 'planType', 'normal_plan');
5092
5141
  request['planType'] = planType;
5093
5142
  response = await this.privateMixGetV2MixOrderOrdersPlanPending(this.extend(request, query));
@@ -5303,6 +5352,7 @@ export default class bitget extends Exchange {
5303
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)
5304
5353
  * @param {string} [params.isPlan] *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
5305
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
5306
5356
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5307
5357
  */
5308
5358
  await this.loadMarkets();
@@ -5340,6 +5390,7 @@ export default class bitget extends Exchange {
5340
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)
5341
5391
  * @param {string} [params.isPlan] *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
5342
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
5343
5394
  * @returns {object} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5344
5395
  */
5345
5396
  await this.loadMarkets();
@@ -5392,8 +5443,9 @@ export default class bitget extends Exchange {
5392
5443
  return await this.fetchPaginatedCallCursor('fetchCanceledAndClosedOrders', symbol, since, limit, params, cursorReceived, 'idLessThan');
5393
5444
  }
5394
5445
  let response = undefined;
5446
+ const trailing = this.safeValue(params, 'trailing');
5395
5447
  const stop = this.safeValue2(params, 'stop', 'trigger');
5396
- params = this.omit(params, ['stop', 'trigger']);
5448
+ params = this.omit(params, ['stop', 'trigger', 'trailing']);
5397
5449
  [request, params] = this.handleUntilOption('endTime', request, params);
5398
5450
  if (since !== undefined) {
5399
5451
  request['startTime'] = since;
@@ -5447,7 +5499,12 @@ export default class bitget extends Exchange {
5447
5499
  let productType = undefined;
5448
5500
  [productType, params] = this.handleProductTypeAndParams(market, params);
5449
5501
  request['productType'] = productType;
5450
- 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) {
5451
5508
  const planType = this.safeString(params, 'planType', 'normal_plan');
5452
5509
  request['planType'] = planType;
5453
5510
  response = await this.privateMixGetV2MixOrderOrdersPlanHistory(this.extend(request, params));
package/js/src/bitmart.js CHANGED
@@ -2128,7 +2128,7 @@ export default class bitmart extends Exchange {
2128
2128
  if (priceString === 'market price') {
2129
2129
  priceString = undefined;
2130
2130
  }
2131
- const trailingStopActivationPrice = this.safeNumber(order, 'activation_price');
2131
+ const trailingActivationPrice = this.safeNumber(order, 'activation_price');
2132
2132
  return this.safeOrder({
2133
2133
  'id': id,
2134
2134
  'clientOrderId': this.safeString(order, 'client_order_id'),
@@ -2142,8 +2142,8 @@ export default class bitmart extends Exchange {
2142
2142
  'postOnly': postOnly,
2143
2143
  'side': this.parseOrderSide(this.safeString(order, 'side')),
2144
2144
  'price': this.omitZero(priceString),
2145
- 'stopPrice': trailingStopActivationPrice,
2146
- 'triggerPrice': trailingStopActivationPrice,
2145
+ 'stopPrice': trailingActivationPrice,
2146
+ 'triggerPrice': trailingActivationPrice,
2147
2147
  'amount': this.omitZero(this.safeString(order, 'size')),
2148
2148
  'cost': this.safeString2(order, 'filled_notional', 'filledNotional'),
2149
2149
  'average': this.safeStringN(order, ['price_avg', 'priceAvg', 'deal_avg_price']),
@@ -2215,6 +2215,7 @@ export default class bitmart extends Exchange {
2215
2215
  * @see https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
2216
2216
  * @see https://developer-pro.bitmart.com/en/spot/#place-margin-order
2217
2217
  * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2218
+ * @see https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2218
2219
  * @param {string} symbol unified symbol of the market to create an order in
2219
2220
  * @param {string} type 'market', 'limit' or 'trailing' for swap markets only
2220
2221
  * @param {string} side 'buy' or 'sell'
@@ -2226,12 +2227,20 @@ export default class bitmart extends Exchange {
2226
2227
  * @param {string} [params.clientOrderId] client order id of the order
2227
2228
  * @param {boolean} [params.reduceOnly] *swap only* reduce only
2228
2229
  * @param {boolean} [params.postOnly] make sure the order is posted to the order book and not matched immediately
2230
+ * @param {string} [params.triggerPrice] *swap only* the price to trigger a stop order
2231
+ * @param {int} [params.price_type] *swap only* 1: last price, 2: fair price, default is 1
2232
+ * @param {int} [params.price_way] *swap only* 1: price way long, 2: price way short
2233
+ * @param {int} [params.activation_price_type] *swap trailing order only* 1: last price, 2: fair price, default is 1
2234
+ * @param {string} [params.trailingPercent] *swap only* the percent to trail away from the current market price, min 0.1 max 5
2235
+ * @param {string} [params.trailingTriggerPrice] *swap only* the price to trigger a trailing order, default uses the price argument
2229
2236
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2230
2237
  */
2231
2238
  await this.loadMarkets();
2232
2239
  const market = this.market(symbol);
2233
2240
  const result = this.handleMarginModeAndParams('createOrder', params);
2234
2241
  const marginMode = this.safeString(result, 0);
2242
+ const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
2243
+ const isTriggerOrder = triggerPrice !== undefined;
2235
2244
  let response = undefined;
2236
2245
  if (market['spot']) {
2237
2246
  const spotRequest = this.createSpotOrderRequest(symbol, type, side, amount, price, params);
@@ -2244,7 +2253,12 @@ export default class bitmart extends Exchange {
2244
2253
  }
2245
2254
  else {
2246
2255
  const swapRequest = this.createSwapOrderRequest(symbol, type, side, amount, price, params);
2247
- response = await this.privatePostContractPrivateSubmitOrder(swapRequest);
2256
+ if (isTriggerOrder) {
2257
+ response = await this.privatePostContractPrivateSubmitPlanOrder(swapRequest);
2258
+ }
2259
+ else {
2260
+ response = await this.privatePostContractPrivateSubmitOrder(swapRequest);
2261
+ }
2248
2262
  }
2249
2263
  //
2250
2264
  // spot and margin
@@ -2276,6 +2290,7 @@ export default class bitmart extends Exchange {
2276
2290
  * @ignore
2277
2291
  * @description create a trade order
2278
2292
  * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2293
+ * @see https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2279
2294
  * @param {string} symbol unified symbol of the market to create an order in
2280
2295
  * @param {string} type 'market', 'limit' or 'trailing'
2281
2296
  * @param {string} side 'buy' or 'sell'
@@ -2286,8 +2301,12 @@ export default class bitmart extends Exchange {
2286
2301
  * @param {boolean} [params.reduceOnly] *swap only* reduce only
2287
2302
  * @param {string} [params.marginMode] 'cross' or 'isolated', default is 'cross'
2288
2303
  * @param {string} [params.clientOrderId] client order id of the order
2304
+ * @param {string} [params.triggerPrice] *swap only* the price to trigger a stop order
2305
+ * @param {int} [params.price_type] *swap only* 1: last price, 2: fair price, default is 1
2306
+ * @param {int} [params.price_way] *swap only* 1: price way long, 2: price way short
2289
2307
  * @param {int} [params.activation_price_type] *swap trailing order only* 1: last price, 2: fair price, default is 1
2290
- * @param {string} [params.callback_rate] *swap trailing order only* min 0.1, max 5 where 1 is 1%, default is "1"
2308
+ * @param {string} [params.trailingPercent] *swap only* the percent to trail away from the current market price, min 0.1 max 5
2309
+ * @param {string} [params.trailingTriggerPrice] *swap only* the price to trigger a trailing order, default uses the price argument
2291
2310
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2292
2311
  */
2293
2312
  const market = this.market(symbol);
@@ -2300,10 +2319,9 @@ export default class bitmart extends Exchange {
2300
2319
  const mode = this.safeInteger(params, 'mode'); // only for swap
2301
2320
  const isMarketOrder = type === 'market';
2302
2321
  let postOnly = undefined;
2303
- let reduceOnly = this.safeValue(params, 'reduceOnly');
2322
+ const reduceOnly = this.safeValue(params, 'reduceOnly');
2304
2323
  const isExchangeSpecificPo = (mode === 4);
2305
2324
  [postOnly, params] = this.handlePostOnly(isMarketOrder, isExchangeSpecificPo, params);
2306
- params = this.omit(params, ['timeInForce', 'postOnly', 'reduceOnly']);
2307
2325
  const ioc = ((timeInForce === 'IOC') || (mode === 3));
2308
2326
  const isLimitOrder = (type === 'limit') || postOnly || ioc;
2309
2327
  if (timeInForce === 'GTC') {
@@ -2318,14 +2336,39 @@ export default class bitmart extends Exchange {
2318
2336
  if (postOnly) {
2319
2337
  request['mode'] = 4;
2320
2338
  }
2339
+ const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
2340
+ const isTriggerOrder = triggerPrice !== undefined;
2341
+ const trailingTriggerPrice = this.safeString2(params, 'trailingTriggerPrice', 'activation_price', price);
2342
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callback_rate');
2343
+ const isTrailingPercentOrder = trailingPercent !== undefined;
2321
2344
  if (isLimitOrder) {
2322
2345
  request['price'] = this.priceToPrecision(symbol, price);
2323
2346
  }
2324
- else if (type === 'trailing') {
2325
- reduceOnly = true;
2326
- request['activation_price'] = this.priceToPrecision(symbol, price);
2347
+ else if (type === 'trailing' || isTrailingPercentOrder) {
2348
+ request['callback_rate'] = trailingPercent;
2349
+ request['activation_price'] = this.priceToPrecision(symbol, trailingTriggerPrice);
2327
2350
  request['activation_price_type'] = this.safeInteger(params, 'activation_price_type', 1);
2328
- request['callback_rate'] = this.safeString(params, 'callback_rate', '1');
2351
+ }
2352
+ if (isTriggerOrder) {
2353
+ request['executive_price'] = this.priceToPrecision(symbol, price);
2354
+ request['trigger_price'] = this.priceToPrecision(symbol, triggerPrice);
2355
+ request['price_type'] = this.safeInteger(params, 'price_type', 1);
2356
+ if (side === 'buy') {
2357
+ if (reduceOnly) {
2358
+ request['price_way'] = 2;
2359
+ }
2360
+ else {
2361
+ request['price_way'] = 1;
2362
+ }
2363
+ }
2364
+ else if (side === 'sell') {
2365
+ if (reduceOnly) {
2366
+ request['price_way'] = 1;
2367
+ }
2368
+ else {
2369
+ request['price_way'] = 2;
2370
+ }
2371
+ }
2329
2372
  }
2330
2373
  if (side === 'buy') {
2331
2374
  if (reduceOnly) {
@@ -2352,7 +2395,7 @@ export default class bitmart extends Exchange {
2352
2395
  request['client_order_id'] = clientOrderId;
2353
2396
  }
2354
2397
  const leverage = this.safeInteger(params, 'leverage', 1);
2355
- params = this.omit(params, 'leverage');
2398
+ params = this.omit(params, ['timeInForce', 'postOnly', 'reduceOnly', 'leverage', 'trailingTriggerPrice', 'trailingPercent', 'triggerPrice', 'stopPrice']);
2356
2399
  request['leverage'] = this.numberToString(leverage);
2357
2400
  return this.extend(request, params);
2358
2401
  }
@@ -2434,10 +2477,11 @@ export default class bitmart extends Exchange {
2434
2477
  /**
2435
2478
  * @method
2436
2479
  * @name bitmart#cancelOrder
2480
+ * @description cancels an open order
2437
2481
  * @see https://developer-pro.bitmart.com/en/futures/#cancel-order-signed
2438
2482
  * @see https://developer-pro.bitmart.com/en/spot/#cancel-order-v3-signed
2439
2483
  * @see https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2440
- * @description cancels an open order
2484
+ * @see https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2441
2485
  * @param {string} id order id
2442
2486
  * @param {string} symbol unified symbol of the market the order was made in
2443
2487
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2647,6 +2691,7 @@ export default class bitmart extends Exchange {
2647
2691
  * @param {string} [params.type] *swap* order type, 'limit' or 'market'
2648
2692
  * @param {string} [params.order_state] *swap* the order state, 'all' or 'partially_filled', default is 'all'
2649
2693
  * @param {string} [params.orderType] *swap only* 'limit', 'market', or 'trailing'
2694
+ * @param {boolean} [params.trailing] *swap only* set to true if you want to fetch trailing orders
2650
2695
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2651
2696
  */
2652
2697
  await this.loadMarkets();
@@ -2679,8 +2724,12 @@ export default class bitmart extends Exchange {
2679
2724
  response = await this.privatePostSpotV4QueryOpenOrders(this.extend(request, params));
2680
2725
  }
2681
2726
  else if (type === 'swap') {
2682
- const orderType = this.safeString(params, 'orderType');
2683
- params = this.omit(params, 'orderType');
2727
+ const trailing = this.safeValue(params, 'trailing', false);
2728
+ let orderType = this.safeString(params, 'orderType');
2729
+ params = this.omit(params, ['orderType', 'trailing']);
2730
+ if (trailing) {
2731
+ orderType = 'trailing';
2732
+ }
2684
2733
  if (orderType !== undefined) {
2685
2734
  request['type'] = orderType;
2686
2735
  }
@@ -2826,6 +2875,7 @@ export default class bitmart extends Exchange {
2826
2875
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2827
2876
  * @param {string} [params.clientOrderId] *spot* fetch the order by client order id instead of order id
2828
2877
  * @param {string} [params.orderType] *swap only* 'limit', 'market', 'liquidate', 'bankruptcy', 'adl' or 'trailing'
2878
+ * @param {boolean} [params.trailing] *swap only* set to true if you want to fetch a trailing order
2829
2879
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2830
2880
  */
2831
2881
  await this.loadMarkets();
@@ -2853,8 +2903,12 @@ export default class bitmart extends Exchange {
2853
2903
  if (symbol === undefined) {
2854
2904
  throw new ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
2855
2905
  }
2856
- const orderType = this.safeString(params, 'orderType');
2857
- params = this.omit(params, 'orderType');
2906
+ const trailing = this.safeValue(params, 'trailing', false);
2907
+ let orderType = this.safeString(params, 'orderType');
2908
+ params = this.omit(params, ['orderType', 'trailing']);
2909
+ if (trailing) {
2910
+ orderType = 'trailing';
2911
+ }
2858
2912
  if (orderType !== undefined) {
2859
2913
  request['type'] = orderType;
2860
2914
  }