ccxt 4.4.5 → 4.4.7

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 (45) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +21 -2
  5. package/dist/cjs/src/bingx.js +3 -0
  6. package/dist/cjs/src/bitflyer.js +2 -2
  7. package/dist/cjs/src/bitget.js +19 -7
  8. package/dist/cjs/src/bitmart.js +310 -128
  9. package/dist/cjs/src/bybit.js +25 -11
  10. package/dist/cjs/src/coinbase.js +6 -8
  11. package/dist/cjs/src/gate.js +3 -0
  12. package/dist/cjs/src/kraken.js +6 -1
  13. package/dist/cjs/src/kucoin.js +2 -2
  14. package/dist/cjs/src/mexc.js +127 -19
  15. package/dist/cjs/src/pro/bitget.js +66 -0
  16. package/dist/cjs/src/pro/htx.js +14 -0
  17. package/dist/cjs/src/pro/kraken.js +60 -0
  18. package/dist/cjs/src/pro/okx.js +11 -5
  19. package/examples/js/cli.js +2 -0
  20. package/js/ccxt.d.ts +1 -1
  21. package/js/ccxt.js +1 -1
  22. package/js/src/abstract/bitmart.d.ts +4 -0
  23. package/js/src/base/Exchange.d.ts +4 -0
  24. package/js/src/base/Exchange.js +21 -2
  25. package/js/src/bingx.js +3 -0
  26. package/js/src/bitflyer.js +2 -2
  27. package/js/src/bitget.d.ts +1 -0
  28. package/js/src/bitget.js +19 -7
  29. package/js/src/bitmart.d.ts +1 -0
  30. package/js/src/bitmart.js +310 -128
  31. package/js/src/bybit.js +25 -11
  32. package/js/src/coinbase.js +6 -8
  33. package/js/src/gate.js +3 -0
  34. package/js/src/kraken.js +6 -1
  35. package/js/src/kucoin.js +2 -2
  36. package/js/src/mexc.d.ts +3 -0
  37. package/js/src/mexc.js +127 -19
  38. package/js/src/pro/bitget.d.ts +3 -0
  39. package/js/src/pro/bitget.js +66 -0
  40. package/js/src/pro/htx.js +14 -0
  41. package/js/src/pro/kraken.d.ts +3 -0
  42. package/js/src/pro/kraken.js +60 -0
  43. package/js/src/pro/okx.d.ts +1 -0
  44. package/js/src/pro/okx.js +11 -5
  45. package/package.json +1 -1
@@ -249,6 +249,10 @@ class bitmart extends bitmart$1 {
249
249
  'contract/private/submit-plan-order': 2.5,
250
250
  'contract/private/cancel-plan-order': 1.5,
251
251
  'contract/private/submit-leverage': 2.5,
252
+ 'contract/private/submit-tp-sl-order': 2.5,
253
+ 'contract/private/modify-plan-order': 2.5,
254
+ 'contract/private/modify-preset-plan-order': 2.5,
255
+ 'contract/private/modify-tp-sl-order': 2.5,
252
256
  },
253
257
  },
254
258
  },
@@ -871,43 +875,43 @@ class bitmart extends bitmart$1 {
871
875
  async fetchContractMarkets(params = {}) {
872
876
  const response = await this.publicGetContractPublicDetails(params);
873
877
  //
874
- // {
875
- // "code": 1000,
876
- // "message": "Ok",
877
- // "trace": "9b92a999-9463-4c96-91a4-93ad1cad0d72",
878
- // "data": {
879
- // "symbols": [
880
- // {
881
- // "symbol": "BTCUSDT",
882
- // "product_type": 1,
883
- // "open_timestamp": 1594080000,
884
- // "expire_timestamp": 0,
885
- // "settle_timestamp": 0,
886
- // "base_currency": "BTC",
887
- // "quote_currency": "USDT",
888
- // "last_price": "23920",
889
- // "volume_24h": "18969368",
890
- // "turnover_24h": "458933659.7858",
891
- // "index_price": "23945.25191635",
892
- // "index_name": "BTCUSDT",
893
- // "contract_size": "0.001",
894
- // "min_leverage": "1",
895
- // "max_leverage": "100",
896
- // "price_precision": "0.1",
897
- // "vol_precision": "1",
898
- // "max_volume": "500000",
899
- // "min_volume": "1",
900
- // "funding_rate": "0.0001",
901
- // "expected_funding_rate": "0.00011",
902
- // "open_interest": "4134180870",
903
- // "open_interest_value": "94100888927.0433258",
904
- // "high_24h": "23900",
905
- // "low_24h": "23100",
906
- // "change_24h": "0.004"
907
- // },
908
- // ]
878
+ // {
879
+ // "code": 1000,
880
+ // "message": "Ok",
881
+ // "data": {
882
+ // "symbols": [
883
+ // {
884
+ // "symbol": "BTCUSDT",
885
+ // "product_type": 1,
886
+ // "open_timestamp": 1645977600000,
887
+ // "expire_timestamp": 0,
888
+ // "settle_timestamp": 0,
889
+ // "base_currency": "BTC",
890
+ // "quote_currency": "USDT",
891
+ // "last_price": "63547.4",
892
+ // "volume_24h": "110938430",
893
+ // "turnover_24h": "7004836342.6944",
894
+ // "index_price": "63587.85404255",
895
+ // "index_name": "BTCUSDT",
896
+ // "contract_size": "0.001",
897
+ // "min_leverage": "1",
898
+ // "max_leverage": "100",
899
+ // "price_precision": "0.1",
900
+ // "vol_precision": "1",
901
+ // "max_volume": "1000000",
902
+ // "min_volume": "1",
903
+ // "funding_rate": "0.0000801",
904
+ // "expected_funding_rate": "-0.0000035",
905
+ // "open_interest": "278214",
906
+ // "open_interest_value": "17555316.9355496",
907
+ // "high_24h": "64109.4",
908
+ // "low_24h": "61857.6",
909
+ // "change_24h": "0.0239264900886327",
910
+ // "funding_time": 1726819200000
911
+ // },
912
+ // ]
913
+ // }
909
914
  // }
910
- // }
911
915
  //
912
916
  const data = this.safeValue(response, 'data', {});
913
917
  const symbols = this.safeValue(data, 'symbols', []);
@@ -1193,33 +1197,34 @@ class bitmart extends bitmart$1 {
1193
1197
  // swap
1194
1198
  //
1195
1199
  // {
1196
- // "symbol": "BTCUSDT",
1197
- // "product_type": 1,
1198
- // "open_timestamp": 1594080000,
1199
- // "expire_timestamp": 0,
1200
- // "settle_timestamp": 0,
1201
- // "base_currency": "BTC",
1202
- // "quote_currency": "USDT",
1203
- // "last_price": "23920",
1204
- // "volume_24h": "18969368",
1205
- // "turnover_24h": "458933659.7858",
1206
- // "index_price": "23945.25191635",
1207
- // "index_name": "BTCUSDT",
1208
- // "contract_size": "0.001",
1209
- // "min_leverage": "1",
1210
- // "max_leverage": "100",
1211
- // "price_precision": "0.1",
1212
- // "vol_precision": "1",
1213
- // "max_volume": "500000",
1214
- // "min_volume": "1",
1215
- // "funding_rate": "0.0001",
1216
- // "expected_funding_rate": "0.00011",
1217
- // "open_interest": "4134180870",
1218
- // "open_interest_value": "94100888927.0433258",
1219
- // "high_24h": "23900",
1220
- // "low_24h": "23100",
1221
- // "change_24h": "0.004"
1222
- // }
1200
+ // "symbol": "BTCUSDT",
1201
+ // "product_type": 1,
1202
+ // "open_timestamp": 1645977600000,
1203
+ // "expire_timestamp": 0,
1204
+ // "settle_timestamp": 0,
1205
+ // "base_currency": "BTC",
1206
+ // "quote_currency": "USDT",
1207
+ // "last_price": "63547.4",
1208
+ // "volume_24h": "110938430",
1209
+ // "turnover_24h": "7004836342.6944",
1210
+ // "index_price": "63587.85404255",
1211
+ // "index_name": "BTCUSDT",
1212
+ // "contract_size": "0.001",
1213
+ // "min_leverage": "1",
1214
+ // "max_leverage": "100",
1215
+ // "price_precision": "0.1",
1216
+ // "vol_precision": "1",
1217
+ // "max_volume": "1000000",
1218
+ // "min_volume": "1",
1219
+ // "funding_rate": "0.0000801",
1220
+ // "expected_funding_rate": "-0.0000035",
1221
+ // "open_interest": "278214",
1222
+ // "open_interest_value": "17555316.9355496",
1223
+ // "high_24h": "64109.4",
1224
+ // "low_24h": "61857.6",
1225
+ // "change_24h": "0.0239264900886327",
1226
+ // "funding_time": 1726819200000
1227
+ // }
1223
1228
  //
1224
1229
  const result = this.safeList(ticker, 'result', []);
1225
1230
  const average = this.safeString2(ticker, 'avg_price', 'index_price');
@@ -1316,27 +1321,43 @@ class bitmart extends bitmart$1 {
1316
1321
  request['symbol'] = market['id'];
1317
1322
  response = await this.publicGetContractPublicDetails(this.extend(request, params));
1318
1323
  //
1319
- // {
1320
- // "message":"OK",
1321
- // "code":1000,
1322
- // "trace":"4a0ebceb-d3f7-45a3-8feb-f61e230e24cd",
1323
- // "data":{
1324
- // "tickers":[
1325
- // {
1326
- // "contract_symbol":"DOGEUSDT",
1327
- // "last_price":"0.130180",
1328
- // "index_price":"0.13028635",
1329
- // "last_funding_rate":"0.00002025",
1330
- // "price_change_percent_24h":"-2.326",
1331
- // "volume_24h":"116789313.01797258",
1332
- // "url":"https://futures.bitmart.com/en?symbol=DOGEUSDT",
1333
- // "high_price":"0.134520",
1334
- // "low_price":"0.128570",
1335
- // "legal_coin_price":"0.13017401"
1336
- // }
1337
- // ]
1338
- // }
1339
- // }
1324
+ // {
1325
+ // "code": 1000,
1326
+ // "message": "Ok",
1327
+ // "data": {
1328
+ // "symbols": [
1329
+ // {
1330
+ // "symbol": "BTCUSDT",
1331
+ // "product_type": 1,
1332
+ // "open_timestamp": 1645977600000,
1333
+ // "expire_timestamp": 0,
1334
+ // "settle_timestamp": 0,
1335
+ // "base_currency": "BTC",
1336
+ // "quote_currency": "USDT",
1337
+ // "last_price": "63547.4",
1338
+ // "volume_24h": "110938430",
1339
+ // "turnover_24h": "7004836342.6944",
1340
+ // "index_price": "63587.85404255",
1341
+ // "index_name": "BTCUSDT",
1342
+ // "contract_size": "0.001",
1343
+ // "min_leverage": "1",
1344
+ // "max_leverage": "100",
1345
+ // "price_precision": "0.1",
1346
+ // "vol_precision": "1",
1347
+ // "max_volume": "1000000",
1348
+ // "min_volume": "1",
1349
+ // "funding_rate": "0.0000801",
1350
+ // "expected_funding_rate": "-0.0000035",
1351
+ // "open_interest": "278214",
1352
+ // "open_interest_value": "17555316.9355496",
1353
+ // "high_24h": "64109.4",
1354
+ // "low_24h": "61857.6",
1355
+ // "change_24h": "0.0239264900886327",
1356
+ // "funding_time": 1726819200000
1357
+ // },
1358
+ // ]
1359
+ // }
1360
+ // }
1340
1361
  //
1341
1362
  }
1342
1363
  else if (market['spot']) {
@@ -1432,43 +1453,43 @@ class bitmart extends bitmart$1 {
1432
1453
  else if (type === 'swap') {
1433
1454
  response = await this.publicGetContractPublicDetails(params);
1434
1455
  //
1435
- // {
1436
- // "code": 1000,
1437
- // "message": "Ok",
1438
- // "trace": "9b92a999-9463-4c96-91a4-93ad1cad0d72",
1439
- // "data": {
1440
- // "symbols": [
1441
- // {
1442
- // "symbol": "BTCUSDT",
1443
- // "product_type": 1,
1444
- // "open_timestamp": 1594080000,
1445
- // "expire_timestamp": 0,
1446
- // "settle_timestamp": 0,
1447
- // "base_currency": "BTC",
1448
- // "quote_currency": "USDT",
1449
- // "last_price": "23920",
1450
- // "volume_24h": "18969368",
1451
- // "turnover_24h": "458933659.7858",
1452
- // "index_price": "23945.25191635",
1453
- // "index_name": "BTCUSDT",
1454
- // "contract_size": "0.001",
1455
- // "min_leverage": "1",
1456
- // "max_leverage": "100",
1457
- // "price_precision": "0.1",
1458
- // "vol_precision": "1",
1459
- // "max_volume": "500000",
1460
- // "min_volume": "1",
1461
- // "funding_rate": "0.0001",
1462
- // "expected_funding_rate": "0.00011",
1463
- // "open_interest": "4134180870",
1464
- // "open_interest_value": "94100888927.0433258",
1465
- // "high_24h": "23900",
1466
- // "low_24h": "23100",
1467
- // "change_24h": "0.004"
1468
- // },
1469
- // ]
1470
- // }
1471
- // }
1456
+ // {
1457
+ // "code": 1000,
1458
+ // "message": "Ok",
1459
+ // "data": {
1460
+ // "symbols": [
1461
+ // {
1462
+ // "symbol": "BTCUSDT",
1463
+ // "product_type": 1,
1464
+ // "open_timestamp": 1645977600000,
1465
+ // "expire_timestamp": 0,
1466
+ // "settle_timestamp": 0,
1467
+ // "base_currency": "BTC",
1468
+ // "quote_currency": "USDT",
1469
+ // "last_price": "63547.4",
1470
+ // "volume_24h": "110938430",
1471
+ // "turnover_24h": "7004836342.6944",
1472
+ // "index_price": "63587.85404255",
1473
+ // "index_name": "BTCUSDT",
1474
+ // "contract_size": "0.001",
1475
+ // "min_leverage": "1",
1476
+ // "max_leverage": "100",
1477
+ // "price_precision": "0.1",
1478
+ // "vol_precision": "1",
1479
+ // "max_volume": "1000000",
1480
+ // "min_volume": "1",
1481
+ // "funding_rate": "0.0000801",
1482
+ // "expected_funding_rate": "-0.0000035",
1483
+ // "open_interest": "278214",
1484
+ // "open_interest_value": "17555316.9355496",
1485
+ // "high_24h": "64109.4",
1486
+ // "low_24h": "61857.6",
1487
+ // "change_24h": "0.0239264900886327",
1488
+ // "funding_time": 1726819200000
1489
+ // },
1490
+ // ]
1491
+ // }
1492
+ // }
1472
1493
  //
1473
1494
  }
1474
1495
  else {
@@ -2273,7 +2294,7 @@ class bitmart extends bitmart$1 {
2273
2294
  }
2274
2295
  parseOrder(order, market = undefined) {
2275
2296
  //
2276
- // createOrder
2297
+ // createOrder, editOrder
2277
2298
  //
2278
2299
  // {
2279
2300
  // "order_id": 2707217580
@@ -2463,6 +2484,7 @@ class bitmart extends bitmart$1 {
2463
2484
  * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2464
2485
  * @see https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2465
2486
  * @see https://developer-pro.bitmart.com/en/futuresv2/#submit-plan-order-signed
2487
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#submit-tp-or-sl-order-signed
2466
2488
  * @param {string} symbol unified symbol of the market to create an order in
2467
2489
  * @param {string} type 'market', 'limit' or 'trailing' for swap markets only
2468
2490
  * @param {string} side 'buy' or 'sell'
@@ -2480,6 +2502,9 @@ class bitmart extends bitmart$1 {
2480
2502
  * @param {int} [params.activation_price_type] *swap trailing order only* 1: last price, 2: fair price, default is 1
2481
2503
  * @param {string} [params.trailingPercent] *swap only* the percent to trail away from the current market price, min 0.1 max 5
2482
2504
  * @param {string} [params.trailingTriggerPrice] *swap only* the price to trigger a trailing order, default uses the price argument
2505
+ * @param {string} [params.stopLossPrice] *swap only* the price to trigger a stop-loss order
2506
+ * @param {string} [params.takeProfitPrice] *swap only* the price to trigger a take-profit order
2507
+ * @param {int} [params.plan_category] *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
2483
2508
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2484
2509
  */
2485
2510
  await this.loadMarkets();
@@ -2487,6 +2512,10 @@ class bitmart extends bitmart$1 {
2487
2512
  const result = this.handleMarginModeAndParams('createOrder', params);
2488
2513
  const marginMode = this.safeString(result, 0);
2489
2514
  const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
2515
+ const stopLossPrice = this.safeString(params, 'stopLossPrice');
2516
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
2517
+ const isStopLoss = stopLossPrice !== undefined;
2518
+ const isTakeProfit = takeProfitPrice !== undefined;
2490
2519
  const isTriggerOrder = triggerPrice !== undefined;
2491
2520
  let response = undefined;
2492
2521
  if (market['spot']) {
@@ -2503,6 +2532,9 @@ class bitmart extends bitmart$1 {
2503
2532
  if (isTriggerOrder) {
2504
2533
  response = await this.privatePostContractPrivateSubmitPlanOrder(swapRequest);
2505
2534
  }
2535
+ else if (isStopLoss || isTakeProfit) {
2536
+ response = await this.privatePostContractPrivateSubmitTpSlOrder(swapRequest);
2537
+ }
2506
2538
  else {
2507
2539
  response = await this.privatePostContractPrivateSubmitOrder(swapRequest);
2508
2540
  }
@@ -2609,8 +2641,9 @@ class bitmart extends bitmart$1 {
2609
2641
  * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2610
2642
  * @see https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2611
2643
  * @see https://developer-pro.bitmart.com/en/futuresv2/#submit-plan-order-signed
2644
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#submit-tp-or-sl-order-signed
2612
2645
  * @param {string} symbol unified symbol of the market to create an order in
2613
- * @param {string} type 'market', 'limit' or 'trailing'
2646
+ * @param {string} type 'market', 'limit', 'trailing', 'stop_loss', or 'take_profit'
2614
2647
  * @param {string} side 'buy' or 'sell'
2615
2648
  * @param {float} amount how much of currency you want to trade in units of base currency
2616
2649
  * @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
@@ -2625,9 +2658,22 @@ class bitmart extends bitmart$1 {
2625
2658
  * @param {int} [params.activation_price_type] *swap trailing order only* 1: last price, 2: fair price, default is 1
2626
2659
  * @param {string} [params.trailingPercent] *swap only* the percent to trail away from the current market price, min 0.1 max 5
2627
2660
  * @param {string} [params.trailingTriggerPrice] *swap only* the price to trigger a trailing order, default uses the price argument
2661
+ * @param {string} [params.stopLossPrice] *swap only* the price to trigger a stop-loss order
2662
+ * @param {string} [params.takeProfitPrice] *swap only* the price to trigger a take-profit order
2663
+ * @param {int} [params.plan_category] *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
2628
2664
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2629
2665
  */
2630
2666
  const market = this.market(symbol);
2667
+ const stopLossPrice = this.safeString(params, 'stopLossPrice');
2668
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
2669
+ const isStopLoss = stopLossPrice !== undefined;
2670
+ const isTakeProfit = takeProfitPrice !== undefined;
2671
+ if (isStopLoss) {
2672
+ type = 'stop_loss';
2673
+ }
2674
+ else if (isTakeProfit) {
2675
+ type = 'take_profit';
2676
+ }
2631
2677
  const request = {
2632
2678
  'symbol': market['id'],
2633
2679
  'type': type,
@@ -2637,7 +2683,7 @@ class bitmart extends bitmart$1 {
2637
2683
  const mode = this.safeInteger(params, 'mode'); // only for swap
2638
2684
  const isMarketOrder = type === 'market';
2639
2685
  let postOnly = undefined;
2640
- const reduceOnly = this.safeValue(params, 'reduceOnly');
2686
+ let reduceOnly = this.safeBool(params, 'reduceOnly');
2641
2687
  const isExchangeSpecificPo = (mode === 4);
2642
2688
  [postOnly, params] = this.handlePostOnly(isMarketOrder, isExchangeSpecificPo, params);
2643
2689
  const ioc = ((timeInForce === 'IOC') || (mode === 3));
@@ -2690,6 +2736,22 @@ class bitmart extends bitmart$1 {
2690
2736
  }
2691
2737
  }
2692
2738
  }
2739
+ let marginMode = undefined;
2740
+ [marginMode, params] = this.handleMarginModeAndParams('createOrder', params, 'cross');
2741
+ if (isStopLoss || isTakeProfit) {
2742
+ reduceOnly = true;
2743
+ request['price_type'] = this.safeInteger(params, 'price_type', 1);
2744
+ request['executive_price'] = this.priceToPrecision(symbol, price);
2745
+ if (isStopLoss) {
2746
+ request['trigger_price'] = this.priceToPrecision(symbol, stopLossPrice);
2747
+ }
2748
+ else {
2749
+ request['trigger_price'] = this.priceToPrecision(symbol, takeProfitPrice);
2750
+ }
2751
+ }
2752
+ else {
2753
+ request['open_type'] = marginMode;
2754
+ }
2693
2755
  if (side === 'buy') {
2694
2756
  if (reduceOnly) {
2695
2757
  request['side'] = 2; // buy close short
@@ -2706,16 +2768,13 @@ class bitmart extends bitmart$1 {
2706
2768
  request['side'] = 4; // sell open short
2707
2769
  }
2708
2770
  }
2709
- let marginMode = undefined;
2710
- [marginMode, params] = this.handleMarginModeAndParams('createOrder', params, 'cross');
2711
- request['open_type'] = marginMode;
2712
2771
  const clientOrderId = this.safeString(params, 'clientOrderId');
2713
2772
  if (clientOrderId !== undefined) {
2714
2773
  params = this.omit(params, 'clientOrderId');
2715
2774
  request['client_order_id'] = clientOrderId;
2716
2775
  }
2717
2776
  const leverage = this.safeInteger(params, 'leverage');
2718
- params = this.omit(params, ['timeInForce', 'postOnly', 'reduceOnly', 'leverage', 'trailingTriggerPrice', 'trailingPercent', 'triggerPrice', 'stopPrice']);
2777
+ params = this.omit(params, ['timeInForce', 'postOnly', 'reduceOnly', 'leverage', 'trailingTriggerPrice', 'trailingPercent', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice']);
2719
2778
  if (leverage !== undefined) {
2720
2779
  request['leverage'] = this.numberToString(leverage);
2721
2780
  }
@@ -4718,6 +4777,129 @@ class bitmart extends bitmart$1 {
4718
4777
  'datetime': this.iso8601(timestamp),
4719
4778
  });
4720
4779
  }
4780
+ async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
4781
+ /**
4782
+ * @method
4783
+ * @name bitmart#editOrder
4784
+ * @description edits an open order
4785
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#modify-plan-order-signed
4786
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#modify-tp-sl-order-signed
4787
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#modify-preset-plan-order-signed
4788
+ * @param {string} id order id
4789
+ * @param {string} symbol unified symbol of the market to edit an order in
4790
+ * @param {string} type 'market' or 'limit'
4791
+ * @param {string} side 'buy' or 'sell'
4792
+ * @param {float} [amount] how much you want to trade in units of the base currency
4793
+ * @param {float} [price] the price to fulfill the order, in units of the quote currency, ignored in market orders
4794
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4795
+ * @param {string} [params.triggerPrice] *swap only* the price to trigger a stop order
4796
+ * @param {string} [params.stopLossPrice] *swap only* the price to trigger a stop-loss order
4797
+ * @param {string} [params.takeProfitPrice] *swap only* the price to trigger a take-profit order
4798
+ * @param {string} [params.stopLoss.triggerPrice] *swap only* the price to trigger a preset stop-loss order
4799
+ * @param {string} [params.takeProfit.triggerPrice] *swap only* the price to trigger a preset take-profit order
4800
+ * @param {string} [params.clientOrderId] client order id of the order
4801
+ * @param {int} [params.price_type] *swap only* 1: last price, 2: fair price, default is 1
4802
+ * @param {int} [params.plan_category] *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
4803
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4804
+ */
4805
+ await this.loadMarkets();
4806
+ const market = this.market(symbol);
4807
+ if (!market['swap']) {
4808
+ throw new errors.NotSupported(this.id + ' editOrder() does not support ' + market['type'] + ' markets, only swap markets are supported');
4809
+ }
4810
+ const stopLossPrice = this.safeString(params, 'stopLossPrice');
4811
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
4812
+ const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
4813
+ const stopLoss = this.safeDict(params, 'stopLoss', {});
4814
+ const takeProfit = this.safeDict(params, 'takeProfit', {});
4815
+ const presetStopLoss = this.safeString(stopLoss, 'triggerPrice');
4816
+ const presetTakeProfit = this.safeString(takeProfit, 'triggerPrice');
4817
+ const isTriggerOrder = triggerPrice !== undefined;
4818
+ const isStopLoss = stopLossPrice !== undefined;
4819
+ const isTakeProfit = takeProfitPrice !== undefined;
4820
+ const isPresetStopLoss = presetStopLoss !== undefined;
4821
+ const isPresetTakeProfit = presetTakeProfit !== undefined;
4822
+ const request = {
4823
+ 'symbol': market['id'],
4824
+ };
4825
+ const clientOrderId = this.safeString(params, 'clientOrderId');
4826
+ if (clientOrderId !== undefined) {
4827
+ params = this.omit(params, 'clientOrderId');
4828
+ request['client_order_id'] = clientOrderId;
4829
+ }
4830
+ if (id !== undefined) {
4831
+ request['order_id'] = id;
4832
+ }
4833
+ params = this.omit(params, ['triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit']);
4834
+ let response = undefined;
4835
+ if (isTriggerOrder || isStopLoss || isTakeProfit) {
4836
+ request['price_type'] = this.safeInteger(params, 'price_type', 1);
4837
+ if (price !== undefined) {
4838
+ request['executive_price'] = this.priceToPrecision(symbol, price);
4839
+ }
4840
+ }
4841
+ if (isTriggerOrder) {
4842
+ request['type'] = type;
4843
+ request['trigger_price'] = this.priceToPrecision(symbol, triggerPrice);
4844
+ response = await this.privatePostContractPrivateModifyPlanOrder(this.extend(request, params));
4845
+ //
4846
+ // {
4847
+ // "code": 1000,
4848
+ // "message": "Ok",
4849
+ // "data": {
4850
+ // "order_id": "3000023150003503"
4851
+ // },
4852
+ // "trace": "324523453245.108.1734567125596324575"
4853
+ // }
4854
+ //
4855
+ }
4856
+ else if (isStopLoss || isTakeProfit) {
4857
+ request['category'] = type;
4858
+ if (isStopLoss) {
4859
+ request['trigger_price'] = this.priceToPrecision(symbol, stopLossPrice);
4860
+ }
4861
+ else {
4862
+ request['trigger_price'] = this.priceToPrecision(symbol, takeProfitPrice);
4863
+ }
4864
+ response = await this.privatePostContractPrivateModifyTpSlOrder(this.extend(request, params));
4865
+ //
4866
+ // {
4867
+ // "code": 1000,
4868
+ // "message": "Ok",
4869
+ // "data": {
4870
+ // "order_id": "3000023150003480"
4871
+ // },
4872
+ // "trace": "23452345.104.1724536582682345459"
4873
+ // }
4874
+ //
4875
+ }
4876
+ else if (isPresetStopLoss || isPresetTakeProfit) {
4877
+ if (isPresetStopLoss) {
4878
+ request['preset_stop_loss_price_type'] = this.safeInteger(params, 'price_type', 1);
4879
+ request['preset_stop_loss_price'] = this.priceToPrecision(symbol, presetStopLoss);
4880
+ }
4881
+ else {
4882
+ request['preset_take_profit_price_type'] = this.safeInteger(params, 'price_type', 1);
4883
+ request['preset_take_profit_price'] = this.priceToPrecision(symbol, presetTakeProfit);
4884
+ }
4885
+ response = await this.privatePostContractPrivateModifyPresetPlanOrder(this.extend(request, params));
4886
+ //
4887
+ // {
4888
+ // "code": 1000,
4889
+ // "message": "Ok",
4890
+ // "data": {
4891
+ // "order_id": "3000023150003496"
4892
+ // },
4893
+ // "trace": "a5c3234534534a836bc476a203.123452.172716624359200197"
4894
+ // }
4895
+ //
4896
+ }
4897
+ else {
4898
+ throw new errors.NotSupported(this.id + ' editOrder() only supports trigger, stop loss and take profit orders');
4899
+ }
4900
+ const data = this.safeDict(response, 'data', {});
4901
+ return this.parseOrder(data, market);
4902
+ }
4721
4903
  nonce() {
4722
4904
  return this.milliseconds();
4723
4905
  }