@okx_ai/okx-trade-mcp 1.3.8-beta.5 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2102,10 +2102,60 @@ function buildAlgoConditionalCommonFields(args) {
2102
2102
  slOrdPx: readString(args, "slOrdPx"),
2103
2103
  slTriggerPxType: readString(args, "slTriggerPxType"),
2104
2104
  slTriggerRatio: readString(args, "slTriggerRatio"),
2105
- closeFraction: readString(args, "closeFraction"),
2105
+ // NOTE: closeFraction intentionally excluded - only valid for FUTURES/SWAP
2106
+ // conditional/oco ordTypes. Spot must not forward this field. The swap/futures
2107
+ // handlers manage closeFraction via resolveAlgoSzOrCloseFraction() (issue #200).
2106
2108
  activePx: readString(args, "activePx")
2107
2109
  };
2108
2110
  }
2111
+ var CLOSE_FRACTION_VALID_ORD_TYPES = /* @__PURE__ */ new Set(["conditional", "oco"]);
2112
+ function isNonMarketOrdPx(px) {
2113
+ return px !== void 0 && px !== "-1";
2114
+ }
2115
+ function assertCloseFractionConstraints(args, ordType, sz, closeFraction) {
2116
+ if (!CLOSE_FRACTION_VALID_ORD_TYPES.has(ordType)) {
2117
+ throw new ValidationError(
2118
+ `closeFraction is only valid for ordType conditional or oco (got "${ordType}").`
2119
+ );
2120
+ }
2121
+ if (closeFraction !== "1") {
2122
+ throw new ValidationError(
2123
+ `closeFraction must be "1" (only full-position close is supported). Got "${closeFraction}".`
2124
+ );
2125
+ }
2126
+ if (sz !== void 0 && sz.length > 0) {
2127
+ throw new ValidationError(
2128
+ `Provide sz OR closeFraction, not both. sz="${sz}", closeFraction="${closeFraction}".`
2129
+ );
2130
+ }
2131
+ if (isNonMarketOrdPx(readString(args, "tpOrdPx")) || isNonMarketOrdPx(readString(args, "slOrdPx"))) {
2132
+ throw new ValidationError(
2133
+ `closeFraction only applies to market TP/SL orders - tpOrdPx/slOrdPx must be "-1" (market) when provided.`
2134
+ );
2135
+ }
2136
+ if (readString(args, "posSide") === "net" && args["reduceOnly"] !== true) {
2137
+ throw new ValidationError(
2138
+ `When closeFraction is used with posSide="net", reduceOnly must be true.`
2139
+ );
2140
+ }
2141
+ }
2142
+ function resolveAlgoSzOrCloseFraction(args, ordType) {
2143
+ const sz = readString(args, "sz");
2144
+ const closeFraction = readString(args, "closeFraction");
2145
+ if (closeFraction !== void 0) {
2146
+ assertCloseFractionConstraints(args, ordType, sz, closeFraction);
2147
+ return { sz: void 0, closeFraction: "1" };
2148
+ }
2149
+ if (!sz || sz.length === 0) {
2150
+ if (CLOSE_FRACTION_VALID_ORD_TYPES.has(ordType)) {
2151
+ throw new ValidationError(
2152
+ `sz or closeFraction is required for ordType "${ordType}".`
2153
+ );
2154
+ }
2155
+ throw new ValidationError(`Missing required parameter "sz".`);
2156
+ }
2157
+ return { sz, closeFraction: void 0 };
2158
+ }
2109
2159
  function buildAttachAlgoOrds(source) {
2110
2160
  const tpLevels = source["tpLevels"];
2111
2161
  if (Array.isArray(tpLevels) && tpLevels.length > 0) {
@@ -3461,7 +3511,12 @@ function registerAlgoTradeTools() {
3461
3511
  },
3462
3512
  sz: {
3463
3513
  type: "string",
3464
- description: "Number of contracts to close (NOT USDT amount). Use market_get_instruments to get ctVal for conversion."
3514
+ description: "Number of contracts to close (NOT USDT amount). Use market_get_instruments to get ctVal for conversion. Required unless closeFraction is provided (conditional/oco only)."
3515
+ },
3516
+ closeFraction: {
3517
+ type: "string",
3518
+ enum: ["1"],
3519
+ description: 'Close 100% of position (full close). Use instead of sz for conditional/oco ordTypes only. Must be "1" (only full-position close is supported). When posSide=net, reduceOnly must also be true.'
3465
3520
  },
3466
3521
  tpTriggerPx: {
3467
3522
  type: "string",
@@ -3506,28 +3561,29 @@ function registerAlgoTradeTools() {
3506
3561
  },
3507
3562
  reduceOnly: {
3508
3563
  type: "boolean",
3509
- description: "Ensure order only reduces position"
3564
+ description: "Ensure order only reduces position. Required when closeFraction is used with posSide=net."
3510
3565
  },
3511
- clOrdId: {
3566
+ algoClOrdId: {
3512
3567
  type: "string",
3513
- description: "Client order ID (max 32 chars)"
3568
+ description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
3514
3569
  }
3515
3570
  },
3516
- required: ["instId", "tdMode", "side", "ordType", "sz"]
3571
+ required: ["instId", "tdMode", "side", "ordType"]
3517
3572
  },
3518
3573
  handler: async (rawArgs, context) => {
3519
3574
  const args = asRecord(rawArgs);
3520
3575
  const reduceOnly = args.reduceOnly;
3521
3576
  const cxlOnClosePos = args.cxlOnClosePos;
3522
3577
  const ordType = requireString(args, "ordType");
3523
- const resolved = await resolveQuoteCcySz(
3578
+ const szOrCf = resolveAlgoSzOrCloseFraction(args, ordType);
3579
+ const resolved = szOrCf.sz !== void 0 ? await resolveQuoteCcySz(
3524
3580
  requireString(args, "instId"),
3525
- requireString(args, "sz"),
3581
+ szOrCf.sz,
3526
3582
  readString(args, "tgtCcy"),
3527
3583
  "SWAP",
3528
3584
  context.client,
3529
3585
  readString(args, "tdMode")
3530
- );
3586
+ ) : { sz: void 0, tgtCcy: void 0, conversionNote: void 0 };
3531
3587
  const base = compactObject({
3532
3588
  instId: requireString(args, "instId"),
3533
3589
  tdMode: requireString(args, "tdMode"),
@@ -3535,11 +3591,12 @@ function registerAlgoTradeTools() {
3535
3591
  posSide: readString(args, "posSide"),
3536
3592
  ordType,
3537
3593
  sz: resolved.sz,
3594
+ closeFraction: szOrCf.closeFraction,
3538
3595
  tgtCcy: resolved.tgtCcy,
3539
3596
  stpMode: readString(args, "stpMode"),
3540
3597
  cxlOnClosePos: typeof cxlOnClosePos === "boolean" ? String(cxlOnClosePos) : void 0,
3541
3598
  reduceOnly: typeof reduceOnly === "boolean" ? String(reduceOnly) : void 0,
3542
- clOrdId: readString(args, "clOrdId"),
3599
+ algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId"),
3543
3600
  // Phase 3a+c CLI power-user flags (issue #182, CLI-only no MCP/skill exposure)
3544
3601
  pxAmendType: readString(args, "pxAmendType"),
3545
3602
  tag: context.config.sourceTag
@@ -3624,9 +3681,9 @@ function registerAlgoTradeTools() {
3624
3681
  type: "boolean",
3625
3682
  description: "Ensure order only reduces position"
3626
3683
  },
3627
- clOrdId: {
3684
+ algoClOrdId: {
3628
3685
  type: "string",
3629
- description: "Client order ID (max 32 chars)"
3686
+ description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
3630
3687
  }
3631
3688
  },
3632
3689
  required: ["instId", "tdMode", "side", "sz"]
@@ -3647,7 +3704,7 @@ function registerAlgoTradeTools() {
3647
3704
  callBackSpread: readString(args, "callbackSpread"),
3648
3705
  activePx: readString(args, "activePx"),
3649
3706
  reduceOnly: typeof reduceOnly === "boolean" ? String(reduceOnly) : void 0,
3650
- clOrdId: readString(args, "clOrdId")
3707
+ algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId")
3651
3708
  }),
3652
3709
  privateRateLimit("swap_place_move_stop_order", 20)
3653
3710
  );
@@ -3828,7 +3885,12 @@ function registerFuturesAlgoTools() {
3828
3885
  },
3829
3886
  sz: {
3830
3887
  type: "string",
3831
- description: "Number of contracts (NOT USDT amount)."
3888
+ description: "Number of contracts (NOT USDT amount). Required unless closeFraction is provided (conditional/oco only)."
3889
+ },
3890
+ closeFraction: {
3891
+ type: "string",
3892
+ enum: ["1"],
3893
+ description: 'Close 100% of position (full close). Use instead of sz for conditional/oco ordTypes only. Must be "1" (only full-position close is supported). When posSide=net, reduceOnly must also be true.'
3832
3894
  },
3833
3895
  tpTriggerPx: {
3834
3896
  type: "string",
@@ -3873,28 +3935,29 @@ function registerFuturesAlgoTools() {
3873
3935
  },
3874
3936
  reduceOnly: {
3875
3937
  type: "boolean",
3876
- description: "Ensure order only reduces position"
3938
+ description: "Ensure order only reduces position. Required when closeFraction is used with posSide=net."
3877
3939
  },
3878
- clOrdId: {
3940
+ algoClOrdId: {
3879
3941
  type: "string",
3880
- description: "Client order ID (max 32 chars)"
3942
+ description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
3881
3943
  }
3882
3944
  },
3883
- required: ["instId", "tdMode", "side", "ordType", "sz"]
3945
+ required: ["instId", "tdMode", "side", "ordType"]
3884
3946
  },
3885
3947
  handler: async (rawArgs, context) => {
3886
3948
  const args = asRecord(rawArgs);
3887
3949
  const reduceOnly = args.reduceOnly;
3888
3950
  const cxlOnClosePos = args.cxlOnClosePos;
3889
3951
  const ordType = requireString(args, "ordType");
3890
- const resolved = await resolveQuoteCcySz(
3952
+ const szOrCf = resolveAlgoSzOrCloseFraction(args, ordType);
3953
+ const resolved = szOrCf.sz !== void 0 ? await resolveQuoteCcySz(
3891
3954
  requireString(args, "instId"),
3892
- requireString(args, "sz"),
3955
+ szOrCf.sz,
3893
3956
  readString(args, "tgtCcy"),
3894
3957
  "FUTURES",
3895
3958
  context.client,
3896
3959
  readString(args, "tdMode")
3897
- );
3960
+ ) : { sz: void 0, tgtCcy: void 0, conversionNote: void 0 };
3898
3961
  const base = compactObject({
3899
3962
  instId: requireString(args, "instId"),
3900
3963
  tdMode: requireString(args, "tdMode"),
@@ -3902,11 +3965,12 @@ function registerFuturesAlgoTools() {
3902
3965
  posSide: readString(args, "posSide"),
3903
3966
  ordType,
3904
3967
  sz: resolved.sz,
3968
+ closeFraction: szOrCf.closeFraction,
3905
3969
  tgtCcy: resolved.tgtCcy,
3906
3970
  stpMode: readString(args, "stpMode"),
3907
3971
  cxlOnClosePos: typeof cxlOnClosePos === "boolean" ? String(cxlOnClosePos) : void 0,
3908
3972
  reduceOnly: typeof reduceOnly === "boolean" ? String(reduceOnly) : void 0,
3909
- clOrdId: readString(args, "clOrdId"),
3973
+ algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId"),
3910
3974
  // Phase 3a+c CLI power-user flags (issue #182, CLI-only no MCP/skill exposure)
3911
3975
  pxAmendType: readString(args, "pxAmendType"),
3912
3976
  tag: context.config.sourceTag
@@ -3991,9 +4055,9 @@ function registerFuturesAlgoTools() {
3991
4055
  type: "boolean",
3992
4056
  description: "Ensure order only reduces position"
3993
4057
  },
3994
- clOrdId: {
4058
+ algoClOrdId: {
3995
4059
  type: "string",
3996
- description: "Client order ID (max 32 chars)"
4060
+ description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
3997
4061
  }
3998
4062
  },
3999
4063
  required: ["instId", "tdMode", "side", "sz"]
@@ -4014,7 +4078,7 @@ function registerFuturesAlgoTools() {
4014
4078
  callBackSpread: readString(args, "callbackSpread"),
4015
4079
  activePx: readString(args, "activePx"),
4016
4080
  reduceOnly: typeof reduceOnly === "boolean" ? String(reduceOnly) : void 0,
4017
- clOrdId: readString(args, "clOrdId")
4081
+ algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId")
4018
4082
  }),
4019
4083
  privateRateLimit("futures_place_move_stop_order", 20)
4020
4084
  );
@@ -10492,9 +10556,9 @@ function registerOptionAlgoTools() {
10492
10556
  type: "boolean",
10493
10557
  description: "Ensure order only reduces position"
10494
10558
  },
10495
- clOrdId: {
10559
+ algoClOrdId: {
10496
10560
  type: "string",
10497
- description: "Client order ID (max 32 chars)"
10561
+ description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
10498
10562
  }
10499
10563
  },
10500
10564
  required: ["instId", "tdMode", "side", "ordType", "sz"]
@@ -10526,7 +10590,7 @@ function registerOptionAlgoTools() {
10526
10590
  slOrdPx: readString(args, "slOrdPx"),
10527
10591
  slTriggerPxType: readString(args, "slTriggerPxType"),
10528
10592
  reduceOnly: reduceOnly !== void 0 ? String(reduceOnly) : void 0,
10529
- clOrdId: readString(args, "clOrdId"),
10593
+ algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId"),
10530
10594
  tag: context.config.sourceTag
10531
10595
  }),
10532
10596
  privateRateLimit("option_place_algo_order", 20)
@@ -11434,6 +11498,10 @@ function registerSpotTradeTools() {
11434
11498
  },
11435
11499
  slTriggerPxType: SL_TRIGGER_PX_TYPE_SCHEMA,
11436
11500
  stpMode: STP_MODE_SCHEMA,
11501
+ algoClOrdId: {
11502
+ type: "string",
11503
+ description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
11504
+ },
11437
11505
  tgtCcy: {
11438
11506
  type: "string",
11439
11507
  enum: ["base_ccy", "quote_ccy"],
@@ -11468,6 +11536,7 @@ function registerSpotTradeTools() {
11468
11536
  sz: requireString(args, "sz"),
11469
11537
  tgtCcy: readString(args, "tgtCcy"),
11470
11538
  stpMode: readString(args, "stpMode"),
11539
+ algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId"),
11471
11540
  // Phase 3a+c CLI power-user flags (issue #182, CLI-only no MCP/skill exposure)
11472
11541
  pxAmendType: readString(args, "pxAmendType"),
11473
11542
  tag: context.config.sourceTag
@@ -12646,7 +12715,7 @@ var _require = createRequire(import.meta.url);
12646
12715
  var pkg = _require("../package.json");
12647
12716
  var SERVER_NAME = "okx-trade-mcp";
12648
12717
  var SERVER_VERSION = pkg.version;
12649
- var GIT_HASH = true ? "884b3632" : "dev";
12718
+ var GIT_HASH = true ? "d21e140e" : "dev";
12650
12719
 
12651
12720
  // src/server.ts
12652
12721
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";