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