@okx_ai/okx-trade-cli 1.3.8-beta.6 → 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/LICENSE +21 -0
- package/dist/index.js +99 -30
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/scripts/postinstall-download.js +152 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OKX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -2277,10 +2277,60 @@ function buildAlgoConditionalCommonFields(args) {
|
|
|
2277
2277
|
slOrdPx: readString(args, "slOrdPx"),
|
|
2278
2278
|
slTriggerPxType: readString(args, "slTriggerPxType"),
|
|
2279
2279
|
slTriggerRatio: readString(args, "slTriggerRatio"),
|
|
2280
|
-
|
|
2280
|
+
// NOTE: closeFraction intentionally excluded - only valid for FUTURES/SWAP
|
|
2281
|
+
// conditional/oco ordTypes. Spot must not forward this field. The swap/futures
|
|
2282
|
+
// handlers manage closeFraction via resolveAlgoSzOrCloseFraction() (issue #200).
|
|
2281
2283
|
activePx: readString(args, "activePx")
|
|
2282
2284
|
};
|
|
2283
2285
|
}
|
|
2286
|
+
var CLOSE_FRACTION_VALID_ORD_TYPES = /* @__PURE__ */ new Set(["conditional", "oco"]);
|
|
2287
|
+
function isNonMarketOrdPx(px) {
|
|
2288
|
+
return px !== void 0 && px !== "-1";
|
|
2289
|
+
}
|
|
2290
|
+
function assertCloseFractionConstraints(args, ordType, sz, closeFraction) {
|
|
2291
|
+
if (!CLOSE_FRACTION_VALID_ORD_TYPES.has(ordType)) {
|
|
2292
|
+
throw new ValidationError(
|
|
2293
|
+
`closeFraction is only valid for ordType conditional or oco (got "${ordType}").`
|
|
2294
|
+
);
|
|
2295
|
+
}
|
|
2296
|
+
if (closeFraction !== "1") {
|
|
2297
|
+
throw new ValidationError(
|
|
2298
|
+
`closeFraction must be "1" (only full-position close is supported). Got "${closeFraction}".`
|
|
2299
|
+
);
|
|
2300
|
+
}
|
|
2301
|
+
if (sz !== void 0 && sz.length > 0) {
|
|
2302
|
+
throw new ValidationError(
|
|
2303
|
+
`Provide sz OR closeFraction, not both. sz="${sz}", closeFraction="${closeFraction}".`
|
|
2304
|
+
);
|
|
2305
|
+
}
|
|
2306
|
+
if (isNonMarketOrdPx(readString(args, "tpOrdPx")) || isNonMarketOrdPx(readString(args, "slOrdPx"))) {
|
|
2307
|
+
throw new ValidationError(
|
|
2308
|
+
`closeFraction only applies to market TP/SL orders - tpOrdPx/slOrdPx must be "-1" (market) when provided.`
|
|
2309
|
+
);
|
|
2310
|
+
}
|
|
2311
|
+
if (readString(args, "posSide") === "net" && args["reduceOnly"] !== true) {
|
|
2312
|
+
throw new ValidationError(
|
|
2313
|
+
`When closeFraction is used with posSide="net", reduceOnly must be true.`
|
|
2314
|
+
);
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
function resolveAlgoSzOrCloseFraction(args, ordType) {
|
|
2318
|
+
const sz = readString(args, "sz");
|
|
2319
|
+
const closeFraction = readString(args, "closeFraction");
|
|
2320
|
+
if (closeFraction !== void 0) {
|
|
2321
|
+
assertCloseFractionConstraints(args, ordType, sz, closeFraction);
|
|
2322
|
+
return { sz: void 0, closeFraction: "1" };
|
|
2323
|
+
}
|
|
2324
|
+
if (!sz || sz.length === 0) {
|
|
2325
|
+
if (CLOSE_FRACTION_VALID_ORD_TYPES.has(ordType)) {
|
|
2326
|
+
throw new ValidationError(
|
|
2327
|
+
`sz or closeFraction is required for ordType "${ordType}".`
|
|
2328
|
+
);
|
|
2329
|
+
}
|
|
2330
|
+
throw new ValidationError(`Missing required parameter "sz".`);
|
|
2331
|
+
}
|
|
2332
|
+
return { sz, closeFraction: void 0 };
|
|
2333
|
+
}
|
|
2284
2334
|
function buildAttachAlgoOrds(source) {
|
|
2285
2335
|
const tpLevels = source["tpLevels"];
|
|
2286
2336
|
if (Array.isArray(tpLevels) && tpLevels.length > 0) {
|
|
@@ -3714,7 +3764,12 @@ function registerAlgoTradeTools() {
|
|
|
3714
3764
|
},
|
|
3715
3765
|
sz: {
|
|
3716
3766
|
type: "string",
|
|
3717
|
-
description: "Number of contracts to close (NOT USDT amount). Use market_get_instruments to get ctVal for conversion."
|
|
3767
|
+
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)."
|
|
3768
|
+
},
|
|
3769
|
+
closeFraction: {
|
|
3770
|
+
type: "string",
|
|
3771
|
+
enum: ["1"],
|
|
3772
|
+
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.'
|
|
3718
3773
|
},
|
|
3719
3774
|
tpTriggerPx: {
|
|
3720
3775
|
type: "string",
|
|
@@ -3759,28 +3814,29 @@ function registerAlgoTradeTools() {
|
|
|
3759
3814
|
},
|
|
3760
3815
|
reduceOnly: {
|
|
3761
3816
|
type: "boolean",
|
|
3762
|
-
description: "Ensure order only reduces position"
|
|
3817
|
+
description: "Ensure order only reduces position. Required when closeFraction is used with posSide=net."
|
|
3763
3818
|
},
|
|
3764
|
-
|
|
3819
|
+
algoClOrdId: {
|
|
3765
3820
|
type: "string",
|
|
3766
|
-
description: "Client order ID (
|
|
3821
|
+
description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
|
|
3767
3822
|
}
|
|
3768
3823
|
},
|
|
3769
|
-
required: ["instId", "tdMode", "side", "ordType"
|
|
3824
|
+
required: ["instId", "tdMode", "side", "ordType"]
|
|
3770
3825
|
},
|
|
3771
3826
|
handler: async (rawArgs, context) => {
|
|
3772
3827
|
const args = asRecord(rawArgs);
|
|
3773
3828
|
const reduceOnly = args.reduceOnly;
|
|
3774
3829
|
const cxlOnClosePos = args.cxlOnClosePos;
|
|
3775
3830
|
const ordType = requireString(args, "ordType");
|
|
3776
|
-
const
|
|
3831
|
+
const szOrCf = resolveAlgoSzOrCloseFraction(args, ordType);
|
|
3832
|
+
const resolved = szOrCf.sz !== void 0 ? await resolveQuoteCcySz(
|
|
3777
3833
|
requireString(args, "instId"),
|
|
3778
|
-
|
|
3834
|
+
szOrCf.sz,
|
|
3779
3835
|
readString(args, "tgtCcy"),
|
|
3780
3836
|
"SWAP",
|
|
3781
3837
|
context.client,
|
|
3782
3838
|
readString(args, "tdMode")
|
|
3783
|
-
);
|
|
3839
|
+
) : { sz: void 0, tgtCcy: void 0, conversionNote: void 0 };
|
|
3784
3840
|
const base = compactObject({
|
|
3785
3841
|
instId: requireString(args, "instId"),
|
|
3786
3842
|
tdMode: requireString(args, "tdMode"),
|
|
@@ -3788,11 +3844,12 @@ function registerAlgoTradeTools() {
|
|
|
3788
3844
|
posSide: readString(args, "posSide"),
|
|
3789
3845
|
ordType,
|
|
3790
3846
|
sz: resolved.sz,
|
|
3847
|
+
closeFraction: szOrCf.closeFraction,
|
|
3791
3848
|
tgtCcy: resolved.tgtCcy,
|
|
3792
3849
|
stpMode: readString(args, "stpMode"),
|
|
3793
3850
|
cxlOnClosePos: typeof cxlOnClosePos === "boolean" ? String(cxlOnClosePos) : void 0,
|
|
3794
3851
|
reduceOnly: typeof reduceOnly === "boolean" ? String(reduceOnly) : void 0,
|
|
3795
|
-
|
|
3852
|
+
algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId"),
|
|
3796
3853
|
// Phase 3a+c CLI power-user flags (issue #182, CLI-only no MCP/skill exposure)
|
|
3797
3854
|
pxAmendType: readString(args, "pxAmendType"),
|
|
3798
3855
|
tag: context.config.sourceTag
|
|
@@ -3877,9 +3934,9 @@ function registerAlgoTradeTools() {
|
|
|
3877
3934
|
type: "boolean",
|
|
3878
3935
|
description: "Ensure order only reduces position"
|
|
3879
3936
|
},
|
|
3880
|
-
|
|
3937
|
+
algoClOrdId: {
|
|
3881
3938
|
type: "string",
|
|
3882
|
-
description: "Client order ID (
|
|
3939
|
+
description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
|
|
3883
3940
|
}
|
|
3884
3941
|
},
|
|
3885
3942
|
required: ["instId", "tdMode", "side", "sz"]
|
|
@@ -3900,7 +3957,7 @@ function registerAlgoTradeTools() {
|
|
|
3900
3957
|
callBackSpread: readString(args, "callbackSpread"),
|
|
3901
3958
|
activePx: readString(args, "activePx"),
|
|
3902
3959
|
reduceOnly: typeof reduceOnly === "boolean" ? String(reduceOnly) : void 0,
|
|
3903
|
-
|
|
3960
|
+
algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId")
|
|
3904
3961
|
}),
|
|
3905
3962
|
privateRateLimit("swap_place_move_stop_order", 20)
|
|
3906
3963
|
);
|
|
@@ -4081,7 +4138,12 @@ function registerFuturesAlgoTools() {
|
|
|
4081
4138
|
},
|
|
4082
4139
|
sz: {
|
|
4083
4140
|
type: "string",
|
|
4084
|
-
description: "Number of contracts (NOT USDT amount)."
|
|
4141
|
+
description: "Number of contracts (NOT USDT amount). Required unless closeFraction is provided (conditional/oco only)."
|
|
4142
|
+
},
|
|
4143
|
+
closeFraction: {
|
|
4144
|
+
type: "string",
|
|
4145
|
+
enum: ["1"],
|
|
4146
|
+
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.'
|
|
4085
4147
|
},
|
|
4086
4148
|
tpTriggerPx: {
|
|
4087
4149
|
type: "string",
|
|
@@ -4126,28 +4188,29 @@ function registerFuturesAlgoTools() {
|
|
|
4126
4188
|
},
|
|
4127
4189
|
reduceOnly: {
|
|
4128
4190
|
type: "boolean",
|
|
4129
|
-
description: "Ensure order only reduces position"
|
|
4191
|
+
description: "Ensure order only reduces position. Required when closeFraction is used with posSide=net."
|
|
4130
4192
|
},
|
|
4131
|
-
|
|
4193
|
+
algoClOrdId: {
|
|
4132
4194
|
type: "string",
|
|
4133
|
-
description: "Client order ID (
|
|
4195
|
+
description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
|
|
4134
4196
|
}
|
|
4135
4197
|
},
|
|
4136
|
-
required: ["instId", "tdMode", "side", "ordType"
|
|
4198
|
+
required: ["instId", "tdMode", "side", "ordType"]
|
|
4137
4199
|
},
|
|
4138
4200
|
handler: async (rawArgs, context) => {
|
|
4139
4201
|
const args = asRecord(rawArgs);
|
|
4140
4202
|
const reduceOnly = args.reduceOnly;
|
|
4141
4203
|
const cxlOnClosePos = args.cxlOnClosePos;
|
|
4142
4204
|
const ordType = requireString(args, "ordType");
|
|
4143
|
-
const
|
|
4205
|
+
const szOrCf = resolveAlgoSzOrCloseFraction(args, ordType);
|
|
4206
|
+
const resolved = szOrCf.sz !== void 0 ? await resolveQuoteCcySz(
|
|
4144
4207
|
requireString(args, "instId"),
|
|
4145
|
-
|
|
4208
|
+
szOrCf.sz,
|
|
4146
4209
|
readString(args, "tgtCcy"),
|
|
4147
4210
|
"FUTURES",
|
|
4148
4211
|
context.client,
|
|
4149
4212
|
readString(args, "tdMode")
|
|
4150
|
-
);
|
|
4213
|
+
) : { sz: void 0, tgtCcy: void 0, conversionNote: void 0 };
|
|
4151
4214
|
const base = compactObject({
|
|
4152
4215
|
instId: requireString(args, "instId"),
|
|
4153
4216
|
tdMode: requireString(args, "tdMode"),
|
|
@@ -4155,11 +4218,12 @@ function registerFuturesAlgoTools() {
|
|
|
4155
4218
|
posSide: readString(args, "posSide"),
|
|
4156
4219
|
ordType,
|
|
4157
4220
|
sz: resolved.sz,
|
|
4221
|
+
closeFraction: szOrCf.closeFraction,
|
|
4158
4222
|
tgtCcy: resolved.tgtCcy,
|
|
4159
4223
|
stpMode: readString(args, "stpMode"),
|
|
4160
4224
|
cxlOnClosePos: typeof cxlOnClosePos === "boolean" ? String(cxlOnClosePos) : void 0,
|
|
4161
4225
|
reduceOnly: typeof reduceOnly === "boolean" ? String(reduceOnly) : void 0,
|
|
4162
|
-
|
|
4226
|
+
algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId"),
|
|
4163
4227
|
// Phase 3a+c CLI power-user flags (issue #182, CLI-only no MCP/skill exposure)
|
|
4164
4228
|
pxAmendType: readString(args, "pxAmendType"),
|
|
4165
4229
|
tag: context.config.sourceTag
|
|
@@ -4244,9 +4308,9 @@ function registerFuturesAlgoTools() {
|
|
|
4244
4308
|
type: "boolean",
|
|
4245
4309
|
description: "Ensure order only reduces position"
|
|
4246
4310
|
},
|
|
4247
|
-
|
|
4311
|
+
algoClOrdId: {
|
|
4248
4312
|
type: "string",
|
|
4249
|
-
description: "Client order ID (
|
|
4313
|
+
description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
|
|
4250
4314
|
}
|
|
4251
4315
|
},
|
|
4252
4316
|
required: ["instId", "tdMode", "side", "sz"]
|
|
@@ -4267,7 +4331,7 @@ function registerFuturesAlgoTools() {
|
|
|
4267
4331
|
callBackSpread: readString(args, "callbackSpread"),
|
|
4268
4332
|
activePx: readString(args, "activePx"),
|
|
4269
4333
|
reduceOnly: typeof reduceOnly === "boolean" ? String(reduceOnly) : void 0,
|
|
4270
|
-
|
|
4334
|
+
algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId")
|
|
4271
4335
|
}),
|
|
4272
4336
|
privateRateLimit("futures_place_move_stop_order", 20)
|
|
4273
4337
|
);
|
|
@@ -11145,9 +11209,9 @@ function registerOptionAlgoTools() {
|
|
|
11145
11209
|
type: "boolean",
|
|
11146
11210
|
description: "Ensure order only reduces position"
|
|
11147
11211
|
},
|
|
11148
|
-
|
|
11212
|
+
algoClOrdId: {
|
|
11149
11213
|
type: "string",
|
|
11150
|
-
description: "Client order ID (
|
|
11214
|
+
description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
|
|
11151
11215
|
}
|
|
11152
11216
|
},
|
|
11153
11217
|
required: ["instId", "tdMode", "side", "ordType", "sz"]
|
|
@@ -11179,7 +11243,7 @@ function registerOptionAlgoTools() {
|
|
|
11179
11243
|
slOrdPx: readString(args, "slOrdPx"),
|
|
11180
11244
|
slTriggerPxType: readString(args, "slTriggerPxType"),
|
|
11181
11245
|
reduceOnly: reduceOnly !== void 0 ? String(reduceOnly) : void 0,
|
|
11182
|
-
|
|
11246
|
+
algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId"),
|
|
11183
11247
|
tag: context.config.sourceTag
|
|
11184
11248
|
}),
|
|
11185
11249
|
privateRateLimit("option_place_algo_order", 20)
|
|
@@ -12087,6 +12151,10 @@ function registerSpotTradeTools() {
|
|
|
12087
12151
|
},
|
|
12088
12152
|
slTriggerPxType: SL_TRIGGER_PX_TYPE_SCHEMA,
|
|
12089
12153
|
stpMode: STP_MODE_SCHEMA,
|
|
12154
|
+
algoClOrdId: {
|
|
12155
|
+
type: "string",
|
|
12156
|
+
description: "Client-assigned algo order ID (1-32 alphanumeric chars). Legacy alias clOrdId is also accepted."
|
|
12157
|
+
},
|
|
12090
12158
|
tgtCcy: {
|
|
12091
12159
|
type: "string",
|
|
12092
12160
|
enum: ["base_ccy", "quote_ccy"],
|
|
@@ -12121,6 +12189,7 @@ function registerSpotTradeTools() {
|
|
|
12121
12189
|
sz: requireString(args, "sz"),
|
|
12122
12190
|
tgtCcy: readString(args, "tgtCcy"),
|
|
12123
12191
|
stpMode: readString(args, "stpMode"),
|
|
12192
|
+
algoClOrdId: readString(args, "algoClOrdId") ?? readString(args, "clOrdId"),
|
|
12124
12193
|
// Phase 3a+c CLI power-user flags (issue #182, CLI-only no MCP/skill exposure)
|
|
12125
12194
|
pxAmendType: readString(args, "pxAmendType"),
|
|
12126
12195
|
tag: context.config.sourceTag
|
|
@@ -14849,7 +14918,7 @@ async function cmdDiagnoseMcp(options = {}) {
|
|
|
14849
14918
|
|
|
14850
14919
|
// src/commands/diagnose.ts
|
|
14851
14920
|
var CLI_VERSION = readCliVersion();
|
|
14852
|
-
var GIT_HASH = true ? "
|
|
14921
|
+
var GIT_HASH = true ? "d21e140e" : "dev";
|
|
14853
14922
|
function maskKey2(key) {
|
|
14854
14923
|
if (!key) return "(not set)";
|
|
14855
14924
|
if (key.length <= 8) return "****";
|
|
@@ -21738,7 +21807,7 @@ async function cmdEventCancel(run, opts) {
|
|
|
21738
21807
|
// src/index.ts
|
|
21739
21808
|
var _require3 = createRequire3(import.meta.url);
|
|
21740
21809
|
var CLI_VERSION2 = _require3("../package.json").version;
|
|
21741
|
-
var GIT_HASH2 = true ? "
|
|
21810
|
+
var GIT_HASH2 = true ? "d21e140e" : "dev";
|
|
21742
21811
|
function handlePilotCommand(action, json, force, binaryPath) {
|
|
21743
21812
|
if (action === "status") return cmdPilotStatus(json, binaryPath);
|
|
21744
21813
|
if (action === "install") return cmdPilotInstall(json, binaryPath);
|