@okx_ai/okx-trade-cli 1.2.5-beta.3 → 1.2.5-beta.4

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
@@ -1104,15 +1104,6 @@ var OkxRestClient = class {
1104
1104
  rateLimit
1105
1105
  });
1106
1106
  }
1107
- async publicPost(path42, body, rateLimit) {
1108
- return this.request({
1109
- method: "POST",
1110
- path: path42,
1111
- auth: "public",
1112
- body,
1113
- rateLimit
1114
- });
1115
- }
1116
1107
  async privatePost(path42, body, rateLimit) {
1117
1108
  return this.request({
1118
1109
  method: "POST",
@@ -2156,32 +2147,41 @@ function registerAlgoTradeTools() {
2156
2147
  {
2157
2148
  name: "swap_cancel_algo_orders",
2158
2149
  module: "swap",
2159
- description: "Cancel one or more pending SWAP/FUTURES algo orders (TP/SL). Accepts a list of {algoId, instId} objects. Private endpoint. Rate limit: 20 req/s per UID.",
2150
+ description: "Cancel one or more pending SWAP/FUTURES algo orders (TP/SL). Accepts a list of {algoId, instId} objects.",
2160
2151
  isWrite: true,
2161
2152
  inputSchema: {
2162
2153
  type: "object",
2163
2154
  properties: {
2164
- instId: {
2165
- type: "string",
2166
- description: "e.g. BTC-USDT-SWAP"
2167
- },
2168
- algoId: {
2169
- type: "string",
2170
- description: "Algo order ID"
2155
+ orders: {
2156
+ type: "array",
2157
+ description: "List of algo orders to cancel. Each item: {algoId, instId}.",
2158
+ items: {
2159
+ type: "object",
2160
+ properties: {
2161
+ algoId: {
2162
+ type: "string",
2163
+ description: "Algo order ID"
2164
+ },
2165
+ instId: {
2166
+ type: "string",
2167
+ description: "e.g. BTC-USDT-SWAP"
2168
+ }
2169
+ },
2170
+ required: ["algoId", "instId"]
2171
+ }
2171
2172
  }
2172
2173
  },
2173
- required: ["instId", "algoId"]
2174
+ required: ["orders"]
2174
2175
  },
2175
2176
  handler: async (rawArgs, context) => {
2176
2177
  const args = asRecord(rawArgs);
2178
+ const orders = args.orders;
2179
+ if (!Array.isArray(orders) || orders.length === 0) {
2180
+ throw new Error("orders must be a non-empty array.");
2181
+ }
2177
2182
  const response = await context.client.privatePost(
2178
2183
  "/api/v5/trade/cancel-algos",
2179
- [
2180
- {
2181
- instId: requireString(args, "instId"),
2182
- algoId: requireString(args, "algoId")
2183
- }
2184
- ],
2184
+ orders,
2185
2185
  privateRateLimit("swap_cancel_algo_orders", 20)
2186
2186
  );
2187
2187
  return normalizeResponse(response);
@@ -2891,13 +2891,7 @@ function registerGridTools() {
2891
2891
  },
2892
2892
  lever: { type: "string", description: "Leverage. Contract only" },
2893
2893
  sz: { type: "string", description: "Margin amount. Contract only" },
2894
- basePos: { type: "boolean", description: "Open base position for contract. Default: true" },
2895
- tpTriggerPx: { type: "string", description: "Take-profit trigger price. Spot + contract" },
2896
- slTriggerPx: { type: "string", description: "Stop-loss trigger price. Spot + contract" },
2897
- algoClOrdId: { type: "string", description: "User-defined algo order ID, 1-32 chars" },
2898
- tradeQuoteCcy: { type: "string", description: "Spot grid only. Quote currency for trading" },
2899
- tpRatio: { type: "string", description: "Contract grid only. TP ratio, e.g. '0.1' = 10%" },
2900
- slRatio: { type: "string", description: "Contract grid only. SL ratio, e.g. '0.1' = 10%" }
2894
+ basePos: { type: "boolean", description: "Open base position for contract. Default: true" }
2901
2895
  },
2902
2896
  required: ["instId", "algoOrdType", "maxPx", "minPx", "gridNum"]
2903
2897
  },
@@ -2911,9 +2905,6 @@ function registerGridTools() {
2911
2905
  minPx: requireString(args, "minPx"),
2912
2906
  gridNum: requireString(args, "gridNum"),
2913
2907
  runType: readString(args, "runType"),
2914
- tpTriggerPx: readString(args, "tpTriggerPx"),
2915
- slTriggerPx: readString(args, "slTriggerPx"),
2916
- algoClOrdId: readString(args, "algoClOrdId"),
2917
2908
  quoteSz: readString(args, "quoteSz"),
2918
2909
  baseSz: readString(args, "baseSz"),
2919
2910
  direction: readString(args, "direction"),
@@ -2921,19 +2912,9 @@ function registerGridTools() {
2921
2912
  sz: readString(args, "sz"),
2922
2913
  tag: context.config.sourceTag
2923
2914
  });
2924
- if (algoOrdType === "grid") {
2925
- const tradeQuoteCcy = readString(args, "tradeQuoteCcy");
2926
- if (tradeQuoteCcy) body.tradeQuoteCcy = tradeQuoteCcy;
2927
- }
2928
2915
  if (algoOrdType === "contract_grid") {
2929
- if (!body.triggerParams) {
2930
- body.triggerParams = [{ triggerAction: "start", triggerStrategy: "instant" }];
2931
- }
2916
+ body.triggerParams = [{ triggerAction: "start", triggerStrategy: "instant" }];
2932
2917
  body.basePos = readBoolean(args, "basePos") ?? true;
2933
- const tpRatio = readString(args, "tpRatio");
2934
- const slRatio = readString(args, "slRatio");
2935
- if (tpRatio) body.tpRatio = tpRatio;
2936
- if (slRatio) body.slRatio = slRatio;
2937
2918
  }
2938
2919
  const response = await context.client.privatePost(
2939
2920
  "/api/v5/tradingBot/grid/order-algo",
@@ -3011,7 +2992,7 @@ function registerDcaTools() {
3011
2992
  {
3012
2993
  name: "dca_create_order",
3013
2994
  module: "bot.dca",
3014
- description: "Create Contract DCA (Martingale) bot. [CAUTION] Real trades. When maxSafetyOrds > 0: also need safetyOrdAmt, pxSteps. When maxSafetyOrds > 1: also need pxStepsMult, volMult.",
2995
+ description: "Create Contract DCA (Martingale) bot. [CAUTION] Real trades. When maxSafetyOrds > 0: also need safetyOrdAmt, pxSteps, pxStepsMult, volMult.",
3015
2996
  isWrite: true,
3016
2997
  inputSchema: {
3017
2998
  type: "object",
@@ -3024,58 +3005,19 @@ function registerDcaTools() {
3024
3005
  tpPct: { type: "string", description: "Take-profit ratio, e.g. '0.03' = 3%" },
3025
3006
  safetyOrdAmt: { type: "string", description: "Safety order amount (USDT). Need when maxSafetyOrds > 0" },
3026
3007
  pxSteps: { type: "string", description: "Price drop % per safety order, e.g. '0.03'. Need when maxSafetyOrds > 0" },
3027
- pxStepsMult: { type: "string", description: "Price step multiplier, e.g. '1.2'. Need when maxSafetyOrds > 1" },
3028
- volMult: { type: "string", description: "Safety order size multiplier, e.g. '1.5'. Need when maxSafetyOrds > 1" },
3008
+ pxStepsMult: { type: "string", description: "Price step multiplier, e.g. '1.2'. Need when maxSafetyOrds > 0" },
3009
+ volMult: { type: "string", description: "Safety order size multiplier, e.g. '1.5'. Need when maxSafetyOrds > 0" },
3029
3010
  slPct: { type: "string", description: "Stop-loss ratio, e.g. '0.05' = 5%" },
3030
3011
  slMode: { type: "string", enum: ["limit", "market"], description: "Stop-loss type. Default: market" },
3031
3012
  allowReinvest: { type: "string", enum: ["true", "false"], description: "Reinvest profit. Default: 'true'" },
3032
3013
  triggerStrategy: { type: "string", enum: ["instant", "price", "rsi"], default: "instant", description: "How bot starts. Default: instant" },
3033
- triggerPx: { type: "string", description: "Required when triggerStrategy='price'" },
3034
- triggerCond: { type: "string", enum: ["cross_up", "cross_down"], description: "RSI trigger condition. Required when triggerStrategy='rsi'" },
3035
- thold: { type: "string", description: "RSI threshold, e.g. '30'. Required when triggerStrategy='rsi'" },
3036
- timePeriod: { type: "string", description: "RSI period. Default: '14'" },
3037
- timeframe: { type: "string", enum: ["3m", "5m", "15m", "30m", "1H", "4H", "1D"], description: "RSI K-line timeframe. Required when triggerStrategy='rsi'" },
3038
- trackingMode: { type: "string", enum: ["sync", "async"], description: "Copy-trading tracking mode" },
3039
- profitSharingRatio: { type: "string", enum: ["0", "0.1", "0.2", "0.3"], description: "Copy-trading profit sharing ratio" }
3014
+ triggerPx: { type: "string", description: "Required when triggerStrategy='price'" }
3040
3015
  },
3041
3016
  required: ["instId", "lever", "direction", "initOrdAmt", "maxSafetyOrds", "tpPct"]
3042
3017
  },
3043
3018
  handler: async (rawArgs, context) => {
3044
3019
  const args = asRecord(rawArgs);
3045
3020
  const instId = requireString(args, "instId");
3046
- const maxSafetyOrds = Number(requireString(args, "maxSafetyOrds"));
3047
- if (maxSafetyOrds > 0) {
3048
- const missing = [];
3049
- if (!readString(args, "safetyOrdAmt")) missing.push("safetyOrdAmt");
3050
- if (!readString(args, "pxSteps")) missing.push("pxSteps");
3051
- if (missing.length > 0) {
3052
- throw new Error(
3053
- `When maxSafetyOrds > 0, the following parameters are required: ${missing.join(", ")}`
3054
- );
3055
- }
3056
- }
3057
- if (maxSafetyOrds > 1) {
3058
- const missing = [];
3059
- if (!readString(args, "pxStepsMult")) missing.push("pxStepsMult");
3060
- if (!readString(args, "volMult")) missing.push("volMult");
3061
- if (missing.length > 0) {
3062
- throw new Error(
3063
- `When maxSafetyOrds > 1, the following parameters are required: ${missing.join(", ")}`
3064
- );
3065
- }
3066
- }
3067
- const slPct = readString(args, "slPct");
3068
- const slMode = readString(args, "slMode");
3069
- if (slPct && !slMode) {
3070
- throw new Error(
3071
- "slMode is required when slPct is set. Use 'market' (market price stop-loss) or 'limit' (limit price stop-loss)."
3072
- );
3073
- }
3074
- if (slMode && !slPct) {
3075
- throw new Error(
3076
- "slPct is required when slMode is set. e.g. '0.05' = 5% stop-loss."
3077
- );
3078
- }
3079
3021
  const triggerStrategy = readString(args, "triggerStrategy") ?? "instant";
3080
3022
  const triggerParam = {
3081
3023
  triggerAction: "start",
@@ -3084,25 +3026,6 @@ function registerDcaTools() {
3084
3026
  if (triggerStrategy === "price") {
3085
3027
  triggerParam["triggerPx"] = requireString(args, "triggerPx");
3086
3028
  }
3087
- if (triggerStrategy === "rsi") {
3088
- const rsiMissing = [];
3089
- const triggerCond = readString(args, "triggerCond");
3090
- const thold = readString(args, "thold");
3091
- const timeframe = readString(args, "timeframe");
3092
- if (!triggerCond) rsiMissing.push("triggerCond");
3093
- if (!thold) rsiMissing.push("thold");
3094
- if (!timeframe) rsiMissing.push("timeframe");
3095
- if (rsiMissing.length > 0) {
3096
- throw new Error(
3097
- `When triggerStrategy='rsi', the following parameters are required: ${rsiMissing.join(", ")}`
3098
- );
3099
- }
3100
- triggerParam["triggerCond"] = triggerCond;
3101
- triggerParam["thold"] = thold;
3102
- triggerParam["timePeriod"] = readString(args, "timePeriod") ?? "14";
3103
- triggerParam["timeframe"] = timeframe;
3104
- }
3105
- const triggerParams = [triggerParam];
3106
3029
  const response = await context.client.privatePost(
3107
3030
  `${BASE}/create`,
3108
3031
  compactObject({
@@ -3120,10 +3043,7 @@ function registerDcaTools() {
3120
3043
  slPct: readString(args, "slPct"),
3121
3044
  slMode: readString(args, "slMode"),
3122
3045
  allowReinvest: readString(args, "allowReinvest"),
3123
- trackingMode: readString(args, "trackingMode"),
3124
- profitSharingRatio: readString(args, "profitSharingRatio"),
3125
- tag: context.config.sourceTag,
3126
- triggerParams
3046
+ triggerParams: [triggerParam]
3127
3047
  }),
3128
3048
  privateRateLimit("dca_create_order", 20)
3129
3049
  );
@@ -3243,8 +3163,6 @@ function registerDcaTools() {
3243
3163
  algoId,
3244
3164
  algoOrdType: "contract_dca",
3245
3165
  cycleId,
3246
- after: readString(args, "after"),
3247
- before: readString(args, "before"),
3248
3166
  limit: readNumber(args, "limit")
3249
3167
  }),
3250
3168
  privateRateLimit("dca_get_sub_orders", 20)
@@ -7409,7 +7327,7 @@ async function cmdDiagnoseMcp(options = {}) {
7409
7327
 
7410
7328
  // src/commands/diagnose.ts
7411
7329
  var CLI_VERSION = readCliVersion();
7412
- var GIT_HASH = true ? "a8b36d0" : "dev";
7330
+ var GIT_HASH = true ? "50eb95e" : "dev";
7413
7331
  function maskKey2(key) {
7414
7332
  if (!key) return "(not set)";
7415
7333
  if (key.length <= 8) return "****";
@@ -8181,7 +8099,7 @@ var HELP_TREE = {
8181
8099
  }
8182
8100
  },
8183
8101
  bot: {
8184
- description: "Trading bot strategies (grid, dca, twap [CLI-only], recurring)",
8102
+ description: "Trading bot strategies (grid, dca)",
8185
8103
  subgroups: {
8186
8104
  grid: {
8187
8105
  description: "Grid trading bot \u2014 create, monitor, and stop grid orders",
@@ -8199,68 +8117,12 @@ var HELP_TREE = {
8199
8117
  description: "List sub-orders of a grid bot (filled or live)"
8200
8118
  },
8201
8119
  create: {
8202
- usage: "okx bot grid create --instId <id> --algoOrdType <grid|contract_grid> --maxPx <px> --minPx <px> --gridNum <n>\n [--runType <1|2>] [--quoteSz <n>] [--baseSz <n>]\n [--direction <long|short|neutral>] [--lever <n>] [--sz <n>] [--basePos] [--no-basePos]\n [--tpTriggerPx <px>] [--slTriggerPx <px>] [--algoClOrdId <id>]\n [--tpRatio <ratio>] [--slRatio <ratio>] [--tradeQuoteCcy <ccy>]",
8120
+ usage: "okx bot grid create --instId <id> --algoOrdType <grid|contract_grid> --maxPx <px> --minPx <px> --gridNum <n>\n [--runType <1|2>] [--quoteSz <n>] [--baseSz <n>]\n [--direction <long|short|neutral>] [--lever <n>] [--sz <n>] [--basePos] [--no-basePos]",
8203
8121
  description: "Create a new grid bot order (contract grid opens base position by default)"
8204
8122
  },
8205
8123
  stop: {
8206
8124
  usage: "okx bot grid stop --algoId <id> --algoOrdType <type> --instId <id> [--stopType <1|2|3|5|6>]",
8207
8125
  description: "Stop a running grid bot order"
8208
- },
8209
- "amend-basic": {
8210
- usage: "okx bot grid amend-basic --algoId <id> --minPx <px> --maxPx <px> --gridNum <n> [--topupAmount <n>]",
8211
- description: "Amend grid bot's price range and grid count"
8212
- },
8213
- "amend-order": {
8214
- usage: "okx bot grid amend-order --algoId <id> --instId <id>\n [--slTriggerPx <px>] [--tpTriggerPx <px>]\n [--tpRatio <ratio>] [--slRatio <ratio>] [--topUpAmt <n>]",
8215
- description: "Amend TP/SL settings of a running grid bot"
8216
- },
8217
- "close-position": {
8218
- usage: "okx bot grid close-position --algoId <id> [--mktClose] [--sz <n>] [--px <price>]",
8219
- description: "Close position of a stopped contract grid bot"
8220
- },
8221
- "cancel-close": {
8222
- usage: "okx bot grid cancel-close --algoId <id> --ordId <id>",
8223
- description: "Cancel a pending close order for contract grid"
8224
- },
8225
- "instant-trigger": {
8226
- usage: "okx bot grid instant-trigger --algoId <id> [--topUpAmt <n>]",
8227
- description: "Immediately trigger a pending-signal grid bot"
8228
- },
8229
- positions: {
8230
- usage: "okx bot grid positions --algoOrdType contract_grid --algoId <id>",
8231
- description: "Get contract grid bot position info"
8232
- },
8233
- "withdraw-income": {
8234
- usage: "okx bot grid withdraw-income --algoId <id>",
8235
- description: "Withdraw profit from a spot grid bot"
8236
- },
8237
- "compute-margin": {
8238
- usage: "okx bot grid compute-margin --algoId <id> --gridType <add|reduce> [--amt <n>]",
8239
- description: "Preview margin adjustment for contract grid"
8240
- },
8241
- "margin-balance": {
8242
- usage: "okx bot grid margin-balance --algoId <id> --gridType <add|reduce> [--amt <n>] [--percent <n>]",
8243
- description: "Adjust margin for contract grid bot"
8244
- },
8245
- "adjust-investment": {
8246
- usage: "okx bot grid adjust-investment --algoId <id> --amt <n> [--allowReinvestProfit <true|false>]",
8247
- description: "Add investment to a running grid bot"
8248
- },
8249
- "ai-param": {
8250
- usage: "okx bot grid ai-param --algoOrdType <grid|contract_grid> --instId <id> [--direction <dir>] [--duration <7D|30D|180D>]",
8251
- description: "Get AI-recommended grid parameters (public, no auth)"
8252
- },
8253
- "min-investment": {
8254
- usage: "okx bot grid min-investment --instId <id> --algoOrdType <type> --gridNum <n>\n --maxPx <px> --minPx <px> --runType <1|2>\n [--direction <dir>] [--lever <n>] [--basePos] [--investmentType <quote|base|dual>]",
8255
- description: "Calculate minimum investment for grid config (public, no auth)"
8256
- },
8257
- "rsi-back-testing": {
8258
- usage: "okx bot grid rsi-back-testing --instId <id> --timeframe <3m|5m|15m|30m|1H|4H|1D>\n --thold <n> --timePeriod <n> [--triggerCond <cond>] [--duration <1M>]",
8259
- description: "RSI signal back testing for grid trigger (public, no auth)"
8260
- },
8261
- "max-quantity": {
8262
- usage: "okx bot grid max-quantity --instId <id> --runType <1|2> --algoOrdType <type>\n --maxPx <px> --minPx <px> [--lever <n>]",
8263
- description: "Get maximum grid quantity for config (public, no auth)"
8264
8126
  }
8265
8127
  }
8266
8128
  },
@@ -8280,82 +8142,12 @@ var HELP_TREE = {
8280
8142
  description: "List cycles or orders within a cycle of a Contract DCA bot"
8281
8143
  },
8282
8144
  create: {
8283
- usage: "okx bot dca create --instId <id> --lever <n> --direction <long|short>\n --initOrdAmt <n> --maxSafetyOrds <n> --tpPct <n>\n [--safetyOrdAmt <n>] [--pxSteps <n>] [--pxStepsMult <n>] [--volMult <n>]\n [--slPct <n>] [--slMode <limit|market>]\n [--allowReinvest <true|false>] [--triggerStrategy <instant|price|rsi>] [--triggerPx <price>]\n [--triggerCond <cross_up|cross_down>] [--thold <n>] [--timePeriod <n>] [--timeframe <3m|5m|15m|30m|1H|4H|1D>]\n [--trackingMode <sync|async>] [--profitSharingRatio <0|0.1|0.2|0.3>]\n Ranges: maxSafetyOrds [0,100]; pxSteps [0.001,0.5] (varies by instrument);\n tpPct: long [0.001,10], short [0.001,0.9999]; slPct must > MPD\n Note: safetyOrdAmt, pxSteps required when maxSafetyOrds > 0; pxStepsMult, volMult required when maxSafetyOrds > 1\n Note: slMode required when slPct is set; triggerCond, thold, timeframe required when triggerStrategy=rsi",
8145
+ usage: "okx bot dca create --instId <id> --lever <n> --direction <long|short>\n --initOrdAmt <n> --maxSafetyOrds <n> --tpPct <n>\n [--safetyOrdAmt <n>] [--pxSteps <n>] [--pxStepsMult <n>] [--volMult <n>]\n [--slPct <n>] [--slMode <limit|market>]\n [--allowReinvest <true|false>] [--triggerStrategy <instant|price|rsi>] [--triggerPx <price>]\n Note: safetyOrdAmt, pxSteps, pxStepsMult, volMult are required when maxSafetyOrds > 0",
8284
8146
  description: "Create a new Contract DCA bot order"
8285
8147
  },
8286
8148
  stop: {
8287
8149
  usage: "okx bot dca stop --algoId <id>",
8288
8150
  description: "Stop a running Contract DCA bot order"
8289
- },
8290
- "margin-add": {
8291
- usage: "okx bot dca margin-add --algoId <id> --amt <n>",
8292
- description: "Add margin to a running DCA bot (CLI-only)"
8293
- },
8294
- "margin-reduce": {
8295
- usage: "okx bot dca margin-reduce --algoId <id> --amt <n>",
8296
- description: "Reduce margin from a running DCA bot (CLI-only)"
8297
- },
8298
- "set-tp": {
8299
- usage: "okx bot dca set-tp --algoId <id> --tpPrice <price>",
8300
- description: "Update take-profit price for a running DCA bot (CLI-only). Long: tpPrice must not be below tpPriceRange; Short: tpPrice must not exceed tpPriceRange. Get tpPriceRange from 'dca orders' (ongoing-list)"
8301
- },
8302
- "set-reinvest": {
8303
- usage: "okx bot dca set-reinvest --algoId <id> --allowReinvest <true|false>",
8304
- description: "Enable or disable reinvestment for a DCA bot (CLI-only)"
8305
- },
8306
- "manual-buy": {
8307
- usage: "okx bot dca manual-buy --algoId <id> --amt <n> --px <price>",
8308
- description: "Manually trigger a buy order within a DCA bot cycle (CLI-only)"
8309
- }
8310
- }
8311
- },
8312
- twap: {
8313
- description: "TWAP (Time-Weighted Average Price) \u2014 split large orders over time intervals",
8314
- commands: {
8315
- orders: {
8316
- usage: "okx bot twap orders [--instId <id>] [--instType <SPOT|SWAP|FUTURES|MARGIN>] [--history] [--state <effective|canceled|order_failed>]",
8317
- description: "List active or historical TWAP algo orders"
8318
- },
8319
- details: {
8320
- usage: "okx bot twap details --algoId <id> | --algoClOrdId <id>",
8321
- description: "Get details of a specific TWAP algo order"
8322
- },
8323
- place: {
8324
- usage: "okx bot twap place --instId <id> --tdMode <cross|isolated|cash> --side <buy|sell>\n --sz <n> --szLimit <n> --pxLimit <px> --timeInterval <sec>\n --pxVar <bps> | --pxSpread <abs>\n [--posSide <long|short|net>] [--algoClOrdId <id>] [--ccy <ccy>] [--tradeQuoteCcy <ccy>]\n [--reduceOnly] [--isTradeBorrowMode]",
8325
- description: "Place a TWAP algo order to split a large order over time"
8326
- },
8327
- cancel: {
8328
- usage: "okx bot twap cancel --instId <id> --algoId <id> | --algoClOrdId <id>",
8329
- description: "Cancel a running TWAP algo order"
8330
- }
8331
- }
8332
- },
8333
- recurring: {
8334
- description: "Spot Recurring Buy (\u5B9A\u6295) \u2014 periodic automatic purchases (CLI-only)",
8335
- commands: {
8336
- orders: {
8337
- usage: "okx bot recurring orders [--algoId <id>] [--history]",
8338
- description: "List active or historical recurring buy orders"
8339
- },
8340
- details: {
8341
- usage: "okx bot recurring details --algoId <id>",
8342
- description: "Get details of a specific recurring buy order"
8343
- },
8344
- "sub-orders": {
8345
- usage: "okx bot recurring sub-orders --algoId <id>",
8346
- description: "List sub-orders (individual buy executions) of a recurring buy"
8347
- },
8348
- create: {
8349
- usage: "okx bot recurring create --stgyName <name> --recurringList '<json>'\n --period <hourly|daily|weekly|monthly> --recurringTime <0-23> --timeZone <n>\n --amt <n> --investmentCcy <ccy> --tdMode <cross|cash>\n [--recurringDay <n>] [--recurringHour <1|4|8|12>] [--tradeQuoteCcy <ccy>] [--algoClOrdId <id>]",
8350
- description: "Create a new recurring buy order"
8351
- },
8352
- amend: {
8353
- usage: "okx bot recurring amend --algoId <id> --stgyName <name>",
8354
- description: "Amend strategy name of a running recurring buy order"
8355
- },
8356
- stop: {
8357
- usage: "okx bot recurring stop --algoId <id>",
8358
- description: "Stop a running recurring buy order"
8359
8151
  }
8360
8152
  }
8361
8153
  }
@@ -8573,25 +8365,6 @@ var CLI_OPTIONS = {
8573
8365
  basePos: { type: "boolean", default: true },
8574
8366
  stopType: { type: "string" },
8575
8367
  live: { type: "boolean", default: false },
8576
- // grid create extended
8577
- algoClOrdId: { type: "string" },
8578
- tpRatio: { type: "string" },
8579
- slRatio: { type: "string" },
8580
- tradeQuoteCcy: { type: "string" },
8581
- // grid extended commands
8582
- mktClose: { type: "boolean", default: false },
8583
- topupAmount: { type: "string" },
8584
- topUpAmt: { type: "string" },
8585
- allowReinvestProfit: { type: "string" },
8586
- percent: { type: "string" },
8587
- gridType: { type: "string" },
8588
- investmentType: { type: "string" },
8589
- // rsi back testing / ai param
8590
- timeframe: { type: "string" },
8591
- thold: { type: "string" },
8592
- timePeriod: { type: "string" },
8593
- triggerCond: { type: "string" },
8594
- duration: { type: "string" },
8595
8368
  // market extras
8596
8369
  instType: { type: "string" },
8597
8370
  quoteCcy: { type: "string" },
@@ -8621,19 +8394,7 @@ var CLI_OPTIONS = {
8621
8394
  allowReinvest: { type: "string" },
8622
8395
  triggerStrategy: { type: "string" },
8623
8396
  triggerPx: { type: "string" },
8624
- trackingMode: { type: "string" },
8625
- profitSharingRatio: { type: "string" },
8626
- tpPrice: { type: "string" },
8627
8397
  cycleId: { type: "string" },
8628
- // recurring buy
8629
- stgyName: { type: "string" },
8630
- recurringList: { type: "string" },
8631
- recurringDay: { type: "string" },
8632
- recurringTime: { type: "string" },
8633
- recurringHour: { type: "string" },
8634
- investmentCcy: { type: "string" },
8635
- period: { type: "string" },
8636
- timeZone: { type: "string" },
8637
8398
  // i18n
8638
8399
  lang: { type: "string" },
8639
8400
  // option
@@ -8649,14 +8410,6 @@ var CLI_OPTIONS = {
8649
8410
  tool: { type: "string" },
8650
8411
  // config profile
8651
8412
  force: { type: "boolean", default: false },
8652
- // twap bot
8653
- pxVar: { type: "string" },
8654
- pxSpread: { type: "string" },
8655
- szLimit: { type: "string" },
8656
- pxLimit: { type: "string" },
8657
- timeInterval: { type: "string" },
8658
- tgtCcy: { type: "string" },
8659
- isTradeBorrowMode: { type: "boolean", default: false },
8660
8413
  // onchain-earn
8661
8414
  productId: { type: "string" },
8662
8415
  protocolType: { type: "string" },
@@ -10771,10 +10524,10 @@ async function cmdGridDetails(run, opts) {
10771
10524
  minPx: detail["minPx"],
10772
10525
  gridNum: detail["gridNum"],
10773
10526
  runType: detail["runType"] === "1" ? "arithmetic" : "geometric",
10774
- pnl: detail["totalPnl"],
10527
+ pnl: detail["pnl"],
10775
10528
  pnlRatio: detail["pnlRatio"],
10776
- investAmt: detail["investment"],
10777
- totalAnnRate: detail["totalAnnualizedRate"],
10529
+ investAmt: detail["investAmt"],
10530
+ totalAnnRate: detail["totalAnnRate"],
10778
10531
  createdAt: new Date(Number(detail["cTime"])).toLocaleString()
10779
10532
  });
10780
10533
  }
@@ -10816,13 +10569,7 @@ async function cmdGridCreate(run, opts) {
10816
10569
  direction: opts.direction,
10817
10570
  lever: opts.lever,
10818
10571
  sz: opts.sz,
10819
- basePos: opts.basePos,
10820
- tpTriggerPx: opts.tpTriggerPx,
10821
- slTriggerPx: opts.slTriggerPx,
10822
- algoClOrdId: opts.algoClOrdId,
10823
- tpRatio: opts.tpRatio,
10824
- slRatio: opts.slRatio,
10825
- tradeQuoteCcy: opts.tradeQuoteCcy
10572
+ basePos: opts.basePos
10826
10573
  });
10827
10574
  const data = getData7(result);
10828
10575
  if (opts.json) return printJson(data);
@@ -10863,13 +10610,7 @@ async function cmdDcaCreate(run, opts) {
10863
10610
  slMode: opts.slMode,
10864
10611
  allowReinvest: opts.allowReinvest,
10865
10612
  triggerStrategy: opts.triggerStrategy,
10866
- triggerPx: opts.triggerPx,
10867
- triggerCond: opts.triggerCond,
10868
- thold: opts.thold,
10869
- timePeriod: opts.timePeriod,
10870
- timeframe: opts.timeframe,
10871
- trackingMode: opts.trackingMode,
10872
- profitSharingRatio: opts.profitSharingRatio
10613
+ triggerPx: opts.triggerPx
10873
10614
  });
10874
10615
  const data = getData7(result);
10875
10616
  if (opts.json) return printJson(data);
@@ -10965,655 +10706,6 @@ async function cmdDcaSubOrders(run, opts) {
10965
10706
  );
10966
10707
  }
10967
10708
 
10968
- // src/commands/bot-grid-ext.ts
10969
- function getDataArray(result) {
10970
- return result.data ?? [];
10971
- }
10972
- function printWriteResult(data, successMsg) {
10973
- const r = data[0];
10974
- if (!r) {
10975
- process.stdout.write("No response data\n");
10976
- return;
10977
- }
10978
- const sCode = r["sCode"];
10979
- if (sCode !== void 0 && sCode !== "0") {
10980
- process.stdout.write(`Error: [${sCode}] ${r["sMsg"] ?? "Operation failed"}
10981
- `);
10982
- return;
10983
- }
10984
- process.stdout.write(`${successMsg}
10985
- `);
10986
- }
10987
- async function cmdGridAmendBasicParam(client, opts) {
10988
- const response = await client.privatePost(
10989
- "/api/v5/tradingBot/grid/amend-algo-basic-param",
10990
- compactObject({
10991
- algoId: opts.algoId,
10992
- minPx: opts.minPx,
10993
- maxPx: opts.maxPx,
10994
- gridNum: opts.gridNum,
10995
- topupAmount: opts.topupAmount
10996
- }),
10997
- privateRateLimit("grid_amend_basic_param", 20)
10998
- );
10999
- const data = getDataArray(response);
11000
- if (opts.json) return printJson(data);
11001
- printWriteResult(data, `Grid bot amended: ${data[0]?.["algoId"]}`);
11002
- }
11003
- async function cmdGridAmendOrder(client, opts) {
11004
- const response = await client.privatePost(
11005
- "/api/v5/tradingBot/grid/amend-order-algo",
11006
- compactObject({
11007
- algoId: opts.algoId,
11008
- instId: opts.instId,
11009
- slTriggerPx: opts.slTriggerPx,
11010
- tpTriggerPx: opts.tpTriggerPx,
11011
- tpRatio: opts.tpRatio,
11012
- slRatio: opts.slRatio,
11013
- topUpAmt: opts.topUpAmt
11014
- }),
11015
- privateRateLimit("grid_amend_order", 20)
11016
- );
11017
- const data = getDataArray(response);
11018
- if (opts.json) return printJson(data);
11019
- printWriteResult(data, `Grid bot order amended: ${data[0]?.["algoId"]}`);
11020
- }
11021
- async function cmdGridClosePosition(client, opts) {
11022
- const response = await client.privatePost(
11023
- "/api/v5/tradingBot/grid/close-position",
11024
- compactObject({
11025
- algoId: opts.algoId,
11026
- mktClose: opts.mktClose,
11027
- sz: opts.sz,
11028
- px: opts.px
11029
- }),
11030
- privateRateLimit("grid_close_position", 20)
11031
- );
11032
- const data = getDataArray(response);
11033
- if (opts.json) return printJson(data);
11034
- const r = data[0];
11035
- if (opts.mktClose) {
11036
- printWriteResult(data, `Grid position market closed: ${r?.["algoId"]}`);
11037
- } else {
11038
- printWriteResult(data, `Grid close order placed: ${r?.["algoId"]} ordId=${r?.["ordId"]}`);
11039
- }
11040
- }
11041
- async function cmdGridCancelCloseOrder(client, opts) {
11042
- const response = await client.privatePost(
11043
- "/api/v5/tradingBot/grid/cancel-close-order",
11044
- { algoId: opts.algoId, ordId: opts.ordId },
11045
- privateRateLimit("grid_cancel_close_order", 20)
11046
- );
11047
- const data = getDataArray(response);
11048
- if (opts.json) return printJson(data);
11049
- printWriteResult(data, `Grid close order cancelled: ${data[0]?.["algoId"]} ordId=${data[0]?.["ordId"]}`);
11050
- }
11051
- async function cmdGridInstantTrigger(client, opts) {
11052
- const response = await client.privatePost(
11053
- "/api/v5/tradingBot/grid/order-instant-trigger",
11054
- compactObject({
11055
- algoId: opts.algoId,
11056
- topUpAmt: opts.topUpAmt
11057
- }),
11058
- privateRateLimit("grid_instant_trigger", 20)
11059
- );
11060
- const data = getDataArray(response);
11061
- if (opts.json) return printJson(data);
11062
- printWriteResult(data, `Grid bot triggered: ${data[0]?.["algoId"]}`);
11063
- }
11064
- async function cmdGridPositions(client, opts) {
11065
- const response = await client.privateGet(
11066
- "/api/v5/tradingBot/grid/positions",
11067
- { algoOrdType: opts.algoOrdType, algoId: opts.algoId },
11068
- privateRateLimit("grid_positions", 20)
11069
- );
11070
- const data = getDataArray(response);
11071
- if (opts.json) return printJson(data);
11072
- const detail = data[0];
11073
- if (!detail) {
11074
- process.stdout.write("No position data\n");
11075
- return;
11076
- }
11077
- printKv({
11078
- algoId: detail["algoId"],
11079
- instId: detail["instId"],
11080
- pos: detail["pos"],
11081
- avgPx: detail["avgPx"],
11082
- liqPx: detail["liqPx"],
11083
- lever: detail["lever"],
11084
- mgnMode: detail["mgnMode"],
11085
- upl: detail["upl"],
11086
- uplRatio: detail["uplRatio"],
11087
- markPx: detail["markPx"]
11088
- });
11089
- }
11090
- async function cmdGridWithdrawIncome(client, opts) {
11091
- const response = await client.privatePost(
11092
- "/api/v5/tradingBot/grid/withdraw-income",
11093
- { algoId: opts.algoId },
11094
- privateRateLimit("grid_withdraw_income", 20)
11095
- );
11096
- const data = getDataArray(response);
11097
- if (opts.json) return printJson(data);
11098
- const r = data[0];
11099
- process.stdout.write(`Grid income withdrawn: ${r?.["algoId"]} profit=${r?.["profit"]}
11100
- `);
11101
- }
11102
- async function cmdGridComputeMarginBalance(client, opts) {
11103
- const response = await client.privatePost(
11104
- "/api/v5/tradingBot/grid/compute-margin-balance",
11105
- compactObject({
11106
- algoId: opts.algoId,
11107
- type: opts.type,
11108
- amt: opts.amt
11109
- }),
11110
- privateRateLimit("grid_compute_margin_balance", 20)
11111
- );
11112
- const data = getDataArray(response);
11113
- if (opts.json) return printJson(data);
11114
- const detail = data[0];
11115
- if (!detail) {
11116
- process.stdout.write("No data\n");
11117
- return;
11118
- }
11119
- printKv({
11120
- maxAmt: detail["maxAmt"],
11121
- lever: detail["lever"]
11122
- });
11123
- }
11124
- async function cmdGridMarginBalance(client, opts) {
11125
- const response = await client.privatePost(
11126
- "/api/v5/tradingBot/grid/margin-balance",
11127
- compactObject({
11128
- algoId: opts.algoId,
11129
- type: opts.type,
11130
- amt: opts.amt,
11131
- percent: opts.percent
11132
- }),
11133
- privateRateLimit("grid_margin_balance", 20)
11134
- );
11135
- const data = getDataArray(response);
11136
- if (opts.json) return printJson(data);
11137
- printWriteResult(data, `Grid margin adjusted: ${data[0]?.["algoId"]}`);
11138
- }
11139
- async function cmdGridAdjustInvestment(client, opts) {
11140
- const response = await client.privatePost(
11141
- "/api/v5/tradingBot/grid/adjust-investment",
11142
- compactObject({
11143
- algoId: opts.algoId,
11144
- amt: opts.amt,
11145
- allowReinvestProfit: opts.allowReinvestProfit
11146
- }),
11147
- privateRateLimit("grid_adjust_investment", 20)
11148
- );
11149
- const data = getDataArray(response);
11150
- if (opts.json) return printJson(data);
11151
- printWriteResult(data, `Grid investment adjusted: ${data[0]?.["algoId"]}`);
11152
- }
11153
- async function cmdGridAiParam(client, opts) {
11154
- const response = await client.publicGet(
11155
- "/api/v5/tradingBot/grid/ai-param",
11156
- compactObject({
11157
- algoOrdType: opts.algoOrdType,
11158
- instId: opts.instId,
11159
- direction: opts.direction,
11160
- duration: opts.duration
11161
- }),
11162
- publicRateLimit("grid_ai_param", 20)
11163
- );
11164
- const data = getDataArray(response);
11165
- if (opts.json) return printJson(data);
11166
- const detail = data[0];
11167
- if (!detail) {
11168
- process.stdout.write("No AI param data\n");
11169
- return;
11170
- }
11171
- printKv({
11172
- instId: detail["instId"],
11173
- algoOrdType: detail["algoOrdType"],
11174
- duration: detail["duration"],
11175
- gridNum: detail["gridNum"],
11176
- maxPx: detail["maxPx"],
11177
- minPx: detail["minPx"],
11178
- minInvestment: `${detail["minInvestment"]} ${detail["ccy"]}`,
11179
- annualizedRate: detail["annualizedRate"],
11180
- runType: detail["runType"] === "1" ? "arithmetic" : "geometric"
11181
- });
11182
- }
11183
- async function cmdGridMinInvestment(client, opts) {
11184
- const response = await client.publicPost(
11185
- "/api/v5/tradingBot/grid/min-investment",
11186
- compactObject({
11187
- instId: opts.instId,
11188
- algoOrdType: opts.algoOrdType,
11189
- gridNum: opts.gridNum,
11190
- maxPx: opts.maxPx,
11191
- minPx: opts.minPx,
11192
- runType: opts.runType,
11193
- direction: opts.direction,
11194
- lever: opts.lever,
11195
- basePos: opts.basePos,
11196
- investmentType: opts.investmentType
11197
- }),
11198
- publicRateLimit("grid_min_investment", 20)
11199
- );
11200
- const data = getDataArray(response);
11201
- if (opts.json) return printJson(data);
11202
- const detail = data[0];
11203
- if (!detail) {
11204
- process.stdout.write("No data\n");
11205
- return;
11206
- }
11207
- const minData = detail["minInvestmentData"];
11208
- if (minData && minData.length > 0) {
11209
- process.stdout.write("Min Investment:\n");
11210
- for (const item of minData) {
11211
- process.stdout.write(` ${item["amt"]} ${item["ccy"]}
11212
- `);
11213
- }
11214
- }
11215
- process.stdout.write(`Single Amount: ${detail["singleAmt"]}
11216
- `);
11217
- }
11218
- async function cmdGridRsiBackTesting(client, opts) {
11219
- const response = await client.publicGet(
11220
- "/api/v5/tradingBot/public/rsi-back-testing",
11221
- compactObject({
11222
- instId: opts.instId,
11223
- timeframe: opts.timeframe,
11224
- thold: opts.thold,
11225
- timePeriod: opts.timePeriod,
11226
- triggerCond: opts.triggerCond,
11227
- duration: opts.duration
11228
- }),
11229
- publicRateLimit("grid_rsi_back_testing", 20)
11230
- );
11231
- const data = getDataArray(response);
11232
- if (opts.json) return printJson(data);
11233
- const detail = data[0];
11234
- process.stdout.write(`RSI trigger count: ${detail?.["triggerNum"] ?? "N/A"}
11235
- `);
11236
- }
11237
- async function cmdGridMaxQuantity(client, opts) {
11238
- const response = await client.publicGet(
11239
- "/api/v5/tradingBot/grid/grid-quantity",
11240
- compactObject({
11241
- instId: opts.instId,
11242
- runType: opts.runType,
11243
- algoOrdType: opts.algoOrdType,
11244
- maxPx: opts.maxPx,
11245
- minPx: opts.minPx,
11246
- lever: opts.lever
11247
- }),
11248
- publicRateLimit("grid_max_quantity", 5)
11249
- );
11250
- const data = getDataArray(response);
11251
- if (opts.json) return printJson(data);
11252
- const detail = data[0];
11253
- process.stdout.write(`Max grid quantity: ${detail?.["maxGridQty"] ?? "N/A"} (min: 2)
11254
- `);
11255
- }
11256
-
11257
- // src/commands/bot-dca-ext.ts
11258
- var BASE2 = "/api/v5/tradingBot/dca";
11259
- function getDataArray2(result) {
11260
- return result.data ?? [];
11261
- }
11262
- function printWriteResult2(data, successMsg) {
11263
- const r = data[0];
11264
- if (!r) {
11265
- process.stdout.write("No response data\n");
11266
- return;
11267
- }
11268
- const sCode = r["sCode"];
11269
- if (sCode !== void 0 && sCode !== "0") {
11270
- process.stdout.write(`Error: [${sCode}] ${r["sMsg"] ?? "Operation failed"}
11271
- `);
11272
- return;
11273
- }
11274
- process.stdout.write(`${successMsg}
11275
- `);
11276
- }
11277
- async function cmdDcaMarginAdd(client, opts) {
11278
- const response = await client.privatePost(
11279
- `${BASE2}/margin/add`,
11280
- { algoId: opts.algoId, amt: opts.amt },
11281
- privateRateLimit("dca_margin_add", 20)
11282
- );
11283
- const data = getDataArray2(response);
11284
- if (opts.json) return printJson(data);
11285
- printWriteResult2(data, `DCA margin added: ${opts.amt} (algoId: ${opts.algoId})`);
11286
- }
11287
- async function cmdDcaMarginReduce(client, opts) {
11288
- const response = await client.privatePost(
11289
- `${BASE2}/margin/reduce`,
11290
- { algoId: opts.algoId, amt: opts.amt },
11291
- privateRateLimit("dca_margin_reduce", 20)
11292
- );
11293
- const data = getDataArray2(response);
11294
- if (opts.json) return printJson(data);
11295
- printWriteResult2(data, `DCA margin reduced: ${opts.amt} (algoId: ${opts.algoId})`);
11296
- }
11297
- async function cmdDcaSetTakeProfit(client, opts) {
11298
- const response = await client.privatePost(
11299
- `${BASE2}/settings/take-profit`,
11300
- { algoId: opts.algoId, algoOrdType: "contract_dca", tpPrice: opts.tpPrice },
11301
- privateRateLimit("dca_set_take_profit", 20)
11302
- );
11303
- const data = getDataArray2(response);
11304
- if (opts.json) return printJson(data);
11305
- printWriteResult2(data, `DCA take-profit updated: ${opts.tpPrice} (algoId: ${opts.algoId})`);
11306
- }
11307
- async function cmdDcaSetReinvestment(client, opts) {
11308
- const response = await client.privatePost(
11309
- `${BASE2}/settings/reinvestment`,
11310
- { algoId: opts.algoId, algoOrdType: "contract_dca", allowReinvest: opts.allowReinvest },
11311
- privateRateLimit("dca_set_reinvestment", 20)
11312
- );
11313
- const data = getDataArray2(response);
11314
- if (opts.json) return printJson(data);
11315
- const label = opts.allowReinvest === "true" ? "enabled" : "disabled";
11316
- printWriteResult2(data, `DCA reinvestment ${label} (algoId: ${opts.algoId})`);
11317
- }
11318
- async function cmdDcaManualBuy(client, opts) {
11319
- const response = await client.privatePost(
11320
- `${BASE2}/orders/manual-buy`,
11321
- {
11322
- algoId: opts.algoId,
11323
- algoOrdType: "contract_dca",
11324
- amt: opts.amt,
11325
- price: opts.px
11326
- },
11327
- privateRateLimit("dca_manual_buy", 20)
11328
- );
11329
- const data = getDataArray2(response);
11330
- if (opts.json) return printJson(data);
11331
- printWriteResult2(data, `DCA manual buy: ${opts.amt} (algoId: ${opts.algoId})`);
11332
- }
11333
-
11334
- // src/commands/bot-recurring-ext.ts
11335
- var BASE3 = "/api/v5/tradingBot/recurring";
11336
- function getDataArray3(result) {
11337
- return result.data ?? [];
11338
- }
11339
- async function cmdRecurringCreate(client, opts) {
11340
- let parsed;
11341
- try {
11342
- parsed = JSON.parse(opts.recurringList);
11343
- } catch {
11344
- throw new Error(`recurringList must be a valid JSON array, e.g. '[{"ccy":"BTC","ratio":"1"}]'`);
11345
- }
11346
- if (!Array.isArray(parsed) || parsed.length === 0) {
11347
- throw new Error("recurringList must be a non-empty array of {ccy, ratio} objects");
11348
- }
11349
- if (opts.period === "hourly" && !opts.recurringHour) {
11350
- throw new Error("recurringHour is required when period=hourly (valid: 1, 4, 8, 12)");
11351
- }
11352
- const body = compactObject({
11353
- stgyName: opts.stgyName,
11354
- recurringList: parsed,
11355
- period: opts.period,
11356
- recurringDay: opts.recurringDay,
11357
- recurringTime: opts.recurringTime,
11358
- recurringHour: opts.recurringHour,
11359
- timeZone: opts.timeZone,
11360
- amt: opts.amt,
11361
- investmentCcy: opts.investmentCcy,
11362
- tdMode: opts.tdMode,
11363
- tradeQuoteCcy: opts.tradeQuoteCcy,
11364
- algoClOrdId: opts.algoClOrdId,
11365
- tag: DEFAULT_SOURCE_TAG
11366
- });
11367
- const response = await client.privatePost(
11368
- `${BASE3}/order-algo`,
11369
- body,
11370
- privateRateLimit("recurring_create", 20)
11371
- );
11372
- const data = getDataArray3(response);
11373
- if (opts.json) return printJson(data);
11374
- const r = data[0];
11375
- process.stdout.write(
11376
- `Recurring buy created: ${r?.["algoId"]} (${r?.["sCode"] === "0" ? "OK" : r?.["sMsg"]})
11377
- `
11378
- );
11379
- }
11380
- async function cmdRecurringAmend(client, opts) {
11381
- const response = await client.privatePost(
11382
- `${BASE3}/amend-order-algo`,
11383
- { algoId: opts.algoId, stgyName: opts.stgyName },
11384
- privateRateLimit("recurring_amend", 20)
11385
- );
11386
- const data = getDataArray3(response);
11387
- if (opts.json) return printJson(data);
11388
- const r = data[0];
11389
- process.stdout.write(
11390
- `Recurring buy amended: ${r?.["algoId"]} (${r?.["sCode"] === "0" ? "OK" : r?.["sMsg"]})
11391
- `
11392
- );
11393
- }
11394
- async function cmdRecurringStop(client, opts) {
11395
- const response = await client.privatePost(
11396
- `${BASE3}/stop-order-algo`,
11397
- [{ algoId: opts.algoId }],
11398
- privateRateLimit("recurring_stop", 20)
11399
- );
11400
- const data = getDataArray3(response);
11401
- if (opts.json) return printJson(data);
11402
- const r = data[0];
11403
- process.stdout.write(
11404
- `Recurring buy stopped: ${r?.["algoId"]} (${r?.["sCode"] === "0" ? "OK" : r?.["sMsg"]})
11405
- `
11406
- );
11407
- }
11408
- async function cmdRecurringOrders(client, opts) {
11409
- const endpoint = opts.history ? `${BASE3}/orders-algo-history` : `${BASE3}/orders-algo-pending`;
11410
- const params = compactObject({ algoId: opts.algoId });
11411
- const response = await client.privateGet(
11412
- endpoint,
11413
- params,
11414
- privateRateLimit("recurring_orders", 20)
11415
- );
11416
- const orders = getDataArray3(response);
11417
- if (opts.json) return printJson(orders);
11418
- if (!orders.length) {
11419
- process.stdout.write("No recurring buy orders\n");
11420
- return;
11421
- }
11422
- printTable(
11423
- orders.map((o) => ({
11424
- algoId: o["algoId"],
11425
- stgyName: o["stgyName"],
11426
- state: o["state"],
11427
- amt: o["amt"],
11428
- period: o["period"],
11429
- ccy: o["investmentCcy"],
11430
- createdAt: new Date(Number(o["cTime"])).toLocaleString()
11431
- }))
11432
- );
11433
- }
11434
- async function cmdRecurringDetails(client, opts) {
11435
- const response = await client.privateGet(
11436
- `${BASE3}/orders-algo-details`,
11437
- { algoId: opts.algoId },
11438
- privateRateLimit("recurring_details", 20)
11439
- );
11440
- const detail = getDataArray3(response)[0];
11441
- if (!detail) {
11442
- process.stdout.write("Recurring buy not found\n");
11443
- return;
11444
- }
11445
- if (opts.json) return printJson(detail);
11446
- printKv({
11447
- algoId: detail["algoId"],
11448
- stgyName: detail["stgyName"],
11449
- state: detail["state"],
11450
- amt: detail["amt"],
11451
- investmentCcy: detail["investmentCcy"],
11452
- period: detail["period"],
11453
- recurringDay: detail["recurringDay"],
11454
- recurringTime: detail["recurringTime"],
11455
- tdMode: detail["tdMode"],
11456
- totalAmt: detail["totalAmt"],
11457
- totalPnl: detail["totalPnl"],
11458
- createdAt: new Date(Number(detail["cTime"])).toLocaleString()
11459
- });
11460
- }
11461
- async function cmdRecurringSubOrders(client, opts) {
11462
- const response = await client.privateGet(
11463
- `${BASE3}/sub-orders`,
11464
- { algoId: opts.algoId },
11465
- privateRateLimit("recurring_sub_orders", 20)
11466
- );
11467
- const orders = getDataArray3(response);
11468
- if (opts.json) return printJson(orders);
11469
- if (!orders.length) {
11470
- process.stdout.write("No sub-orders\n");
11471
- return;
11472
- }
11473
- printTable(
11474
- orders.map((o) => ({
11475
- ordId: o["ordId"],
11476
- ccy: o["ccy"],
11477
- amt: o["amt"],
11478
- px: o["px"],
11479
- sz: o["sz"],
11480
- state: o["state"],
11481
- ts: o["ts"] ? new Date(Number(o["ts"])).toLocaleString() : ""
11482
- }))
11483
- );
11484
- }
11485
-
11486
- // src/commands/bot-twap-ext.ts
11487
- function getDataArray4(result) {
11488
- return result.data ?? [];
11489
- }
11490
- function printWriteResult3(data, successMsg) {
11491
- const r = data[0];
11492
- if (!r) {
11493
- process.stdout.write("No response data\n");
11494
- return;
11495
- }
11496
- const sCode = r["sCode"];
11497
- if (sCode !== void 0 && sCode !== "0") {
11498
- process.stdout.write(`Error: [${sCode}] ${r["sMsg"] ?? "Operation failed"}
11499
- `);
11500
- return;
11501
- }
11502
- process.stdout.write(`${successMsg}
11503
- `);
11504
- }
11505
- async function cmdTwapPlace(client, opts) {
11506
- const response = await client.privatePost(
11507
- "/api/v5/trade/order-algo",
11508
- compactObject({
11509
- instId: opts.instId,
11510
- tdMode: opts.tdMode,
11511
- side: opts.side,
11512
- ordType: "twap",
11513
- sz: opts.sz,
11514
- szLimit: opts.szLimit,
11515
- pxLimit: opts.pxLimit,
11516
- timeInterval: opts.timeInterval,
11517
- posSide: opts.posSide,
11518
- pxVar: opts.pxVar,
11519
- pxSpread: opts.pxSpread,
11520
- tag: "CLI",
11521
- algoClOrdId: opts.algoClOrdId,
11522
- ccy: opts.ccy,
11523
- tradeQuoteCcy: opts.tradeQuoteCcy,
11524
- reduceOnly: opts.reduceOnly !== void 0 ? String(opts.reduceOnly) : void 0,
11525
- isTradeBorrowMode: opts.isTradeBorrowMode !== void 0 ? String(opts.isTradeBorrowMode) : void 0
11526
- }),
11527
- privateRateLimit("twap_place_order", 20)
11528
- );
11529
- const data = getDataArray4(response);
11530
- if (opts.json) return printJson(data);
11531
- printWriteResult3(data, `TWAP order placed: ${data[0]?.["algoId"]}`);
11532
- }
11533
- async function cmdTwapCancel(client, opts) {
11534
- if (!opts.algoId && !opts.algoClOrdId) {
11535
- throw new Error("Must provide --algoId or --algoClOrdId");
11536
- }
11537
- const response = await client.privatePost(
11538
- "/api/v5/trade/cancel-algos",
11539
- [compactObject({
11540
- algoId: opts.algoId,
11541
- algoClOrdId: opts.algoClOrdId,
11542
- instId: opts.instId
11543
- })],
11544
- privateRateLimit("twap_cancel_order", 20)
11545
- );
11546
- const data = getDataArray4(response);
11547
- if (opts.json) return printJson(data);
11548
- printWriteResult3(data, `TWAP order cancelled: ${data[0]?.["algoId"]}`);
11549
- }
11550
- async function cmdTwapOrders(client, opts) {
11551
- const path5 = opts.history ? "/api/v5/trade/orders-algo-history" : "/api/v5/trade/orders-algo-pending";
11552
- const response = await client.privateGet(
11553
- path5,
11554
- compactObject({
11555
- ordType: "twap",
11556
- instType: opts.instType,
11557
- instId: opts.instId,
11558
- ...opts.history && !opts.state ? { state: "effective" } : {},
11559
- ...opts.history && opts.state ? { state: opts.state } : {}
11560
- }),
11561
- privateRateLimit("twap_get_orders", 20)
11562
- );
11563
- const orders = getDataArray4(response);
11564
- if (opts.json) return printJson(orders);
11565
- if (!orders.length) {
11566
- process.stdout.write("No TWAP orders\n");
11567
- return;
11568
- }
11569
- printTable(
11570
- orders.map((o) => ({
11571
- algoId: o["algoId"],
11572
- instId: o["instId"],
11573
- side: o["side"],
11574
- state: o["state"],
11575
- sz: o["sz"],
11576
- szLimit: o["szLimit"],
11577
- pxLimit: o["pxLimit"],
11578
- timeInterval: o["timeInterval"],
11579
- createdAt: new Date(Number(o["cTime"])).toLocaleString()
11580
- }))
11581
- );
11582
- }
11583
- async function cmdTwapDetails(client, opts) {
11584
- if (!opts.algoId && !opts.algoClOrdId) {
11585
- throw new Error("Must provide --algoId or --algoClOrdId");
11586
- }
11587
- const response = await client.privateGet(
11588
- "/api/v5/trade/order-algo",
11589
- compactObject({
11590
- algoId: opts.algoId,
11591
- algoClOrdId: opts.algoClOrdId
11592
- }),
11593
- privateRateLimit("twap_get_order_details", 20)
11594
- );
11595
- const data = getDataArray4(response);
11596
- const detail = data[0];
11597
- if (!detail) {
11598
- process.stdout.write("TWAP order not found\n");
11599
- return;
11600
- }
11601
- if (opts.json) return printJson(detail);
11602
- printKv({
11603
- algoId: detail["algoId"],
11604
- instId: detail["instId"],
11605
- side: detail["side"],
11606
- state: detail["state"],
11607
- sz: detail["sz"],
11608
- szLimit: detail["szLimit"],
11609
- pxLimit: detail["pxLimit"],
11610
- pxVar: detail["pxVar"],
11611
- pxSpread: detail["pxSpread"],
11612
- timeInterval: detail["timeInterval"],
11613
- createdAt: new Date(Number(detail["cTime"])).toLocaleString()
11614
- });
11615
- }
11616
-
11617
10709
  // src/commands/onchain-earn.ts
11618
10710
  function cmdOnchainEarnOffers(run, v) {
11619
10711
  return run("onchain_earn_get_offers", {
@@ -11910,7 +11002,7 @@ async function cmdDcdQuoteAndBuy(run, opts) {
11910
11002
  // src/index.ts
11911
11003
  var _require3 = createRequire3(import.meta.url);
11912
11004
  var CLI_VERSION2 = _require3("../package.json").version;
11913
- var GIT_HASH2 = true ? "a8b36d0" : "dev";
11005
+ var GIT_HASH2 = true ? "50eb95e" : "dev";
11914
11006
  function handleConfigCommand(action, rest, json, lang, force) {
11915
11007
  if (action === "init") return cmdConfigInit(lang === "zh" ? "zh" : "en");
11916
11008
  if (action === "show") return cmdConfigShow(json);
@@ -12438,7 +11530,7 @@ function handleFuturesCommand(run, action, rest, v, json) {
12438
11530
  if (action === "algo")
12439
11531
  return handleFuturesAlgoCommand(run, rest[0], v, json);
12440
11532
  }
12441
- function handleBotGridCommand(run, client, v, rest, json) {
11533
+ function handleBotGridCommand(run, v, rest, json) {
12442
11534
  const subAction = rest[0];
12443
11535
  if (subAction === "orders")
12444
11536
  return cmdGridOrders(run, {
@@ -12475,12 +11567,6 @@ function handleBotGridCommand(run, client, v, rest, json) {
12475
11567
  lever: v.lever,
12476
11568
  sz: v.sz,
12477
11569
  basePos: v.basePos,
12478
- tpTriggerPx: v.tpTriggerPx,
12479
- slTriggerPx: v.slTriggerPx,
12480
- algoClOrdId: v.algoClOrdId,
12481
- tpRatio: v.tpRatio,
12482
- slRatio: v.slRatio,
12483
- tradeQuoteCcy: v.tradeQuoteCcy,
12484
11570
  json
12485
11571
  });
12486
11572
  if (subAction === "stop")
@@ -12491,123 +11577,8 @@ function handleBotGridCommand(run, client, v, rest, json) {
12491
11577
  stopType: v.stopType,
12492
11578
  json
12493
11579
  });
12494
- if (subAction === "amend-basic")
12495
- return cmdGridAmendBasicParam(client, {
12496
- algoId: v.algoId,
12497
- minPx: v.minPx,
12498
- maxPx: v.maxPx,
12499
- gridNum: v.gridNum,
12500
- topupAmount: v.topupAmount,
12501
- json
12502
- });
12503
- if (subAction === "amend-order")
12504
- return cmdGridAmendOrder(client, {
12505
- algoId: v.algoId,
12506
- instId: v.instId,
12507
- slTriggerPx: v.slTriggerPx,
12508
- tpTriggerPx: v.tpTriggerPx,
12509
- tpRatio: v.tpRatio,
12510
- slRatio: v.slRatio,
12511
- topUpAmt: v.topUpAmt,
12512
- json
12513
- });
12514
- if (subAction === "close-position")
12515
- return cmdGridClosePosition(client, {
12516
- algoId: v.algoId,
12517
- mktClose: v.mktClose ?? false,
12518
- sz: v.sz,
12519
- px: v.px,
12520
- json
12521
- });
12522
- if (subAction === "cancel-close")
12523
- return cmdGridCancelCloseOrder(client, {
12524
- algoId: v.algoId,
12525
- ordId: v.ordId,
12526
- json
12527
- });
12528
- if (subAction === "instant-trigger")
12529
- return cmdGridInstantTrigger(client, {
12530
- algoId: v.algoId,
12531
- topUpAmt: v.topUpAmt,
12532
- json
12533
- });
12534
- if (subAction === "positions")
12535
- return cmdGridPositions(client, {
12536
- algoOrdType: v.algoOrdType,
12537
- algoId: v.algoId,
12538
- json
12539
- });
12540
- if (subAction === "withdraw-income")
12541
- return cmdGridWithdrawIncome(client, {
12542
- algoId: v.algoId,
12543
- json
12544
- });
12545
- if (subAction === "compute-margin")
12546
- return cmdGridComputeMarginBalance(client, {
12547
- algoId: v.algoId,
12548
- type: v.gridType,
12549
- amt: v.amt,
12550
- json
12551
- });
12552
- if (subAction === "margin-balance")
12553
- return cmdGridMarginBalance(client, {
12554
- algoId: v.algoId,
12555
- type: v.gridType,
12556
- amt: v.amt,
12557
- percent: v.percent,
12558
- json
12559
- });
12560
- if (subAction === "adjust-investment")
12561
- return cmdGridAdjustInvestment(client, {
12562
- algoId: v.algoId,
12563
- amt: v.amt,
12564
- allowReinvestProfit: v.allowReinvestProfit,
12565
- json
12566
- });
12567
- if (subAction === "ai-param")
12568
- return cmdGridAiParam(client, {
12569
- algoOrdType: v.algoOrdType,
12570
- instId: v.instId,
12571
- direction: v.direction,
12572
- duration: v.duration,
12573
- json
12574
- });
12575
- if (subAction === "min-investment")
12576
- return cmdGridMinInvestment(client, {
12577
- instId: v.instId,
12578
- algoOrdType: v.algoOrdType,
12579
- gridNum: v.gridNum,
12580
- maxPx: v.maxPx,
12581
- minPx: v.minPx,
12582
- runType: v.runType,
12583
- direction: v.direction,
12584
- lever: v.lever,
12585
- basePos: v.basePos,
12586
- investmentType: v.investmentType,
12587
- json
12588
- });
12589
- if (subAction === "rsi-back-testing")
12590
- return cmdGridRsiBackTesting(client, {
12591
- instId: v.instId,
12592
- timeframe: v.timeframe,
12593
- thold: v.thold,
12594
- timePeriod: v.timePeriod,
12595
- triggerCond: v.triggerCond,
12596
- duration: v.duration,
12597
- json
12598
- });
12599
- if (subAction === "max-quantity")
12600
- return cmdGridMaxQuantity(client, {
12601
- instId: v.instId,
12602
- runType: v.runType,
12603
- algoOrdType: v.algoOrdType,
12604
- maxPx: v.maxPx,
12605
- minPx: v.minPx,
12606
- lever: v.lever,
12607
- json
12608
- });
12609
11580
  }
12610
- function handleBotDcaCommand(run, client, subAction, v, json) {
11581
+ function handleBotDcaCommand(run, subAction, v, json) {
12611
11582
  if (subAction === "orders")
12612
11583
  return cmdDcaOrders(run, { algoId: v.algoId, instId: v.instId, history: v.history ?? false, json });
12613
11584
  if (subAction === "details")
@@ -12631,93 +11602,14 @@ function handleBotDcaCommand(run, client, subAction, v, json) {
12631
11602
  allowReinvest: v.allowReinvest,
12632
11603
  triggerStrategy: v.triggerStrategy,
12633
11604
  triggerPx: v.triggerPx,
12634
- triggerCond: v.triggerCond,
12635
- thold: v.thold,
12636
- timePeriod: v.timePeriod,
12637
- timeframe: v.timeframe,
12638
- trackingMode: v.trackingMode,
12639
- profitSharingRatio: v.profitSharingRatio,
12640
11605
  json
12641
11606
  });
12642
11607
  if (subAction === "stop")
12643
11608
  return cmdDcaStop(run, { algoId: v.algoId, json });
12644
- if (subAction === "margin-add")
12645
- return cmdDcaMarginAdd(client, { algoId: v.algoId, amt: v.amt, json });
12646
- if (subAction === "margin-reduce")
12647
- return cmdDcaMarginReduce(client, { algoId: v.algoId, amt: v.amt, json });
12648
- if (subAction === "set-tp")
12649
- return cmdDcaSetTakeProfit(client, { algoId: v.algoId, tpPrice: v.tpPrice, json });
12650
- if (subAction === "set-reinvest")
12651
- return cmdDcaSetReinvestment(client, { algoId: v.algoId, allowReinvest: v.allowReinvest, json });
12652
- if (subAction === "manual-buy") {
12653
- if (!v.px) throw new Error("--px <price> is required for manual-buy");
12654
- return cmdDcaManualBuy(client, { algoId: v.algoId, amt: v.amt, px: v.px, json });
12655
- }
12656
- }
12657
- function handleBotTwapCommand(client, subAction, v, json) {
12658
- if (subAction === "orders")
12659
- return cmdTwapOrders(client, { history: v.history ?? false, instId: v.instId, instType: v.instType, state: v.state, json });
12660
- if (subAction === "details")
12661
- return cmdTwapDetails(client, { algoId: v.algoId, algoClOrdId: v.algoClOrdId, json });
12662
- if (subAction === "place")
12663
- return cmdTwapPlace(client, {
12664
- instId: v.instId,
12665
- tdMode: v.tdMode,
12666
- side: v.side,
12667
- sz: v.sz,
12668
- szLimit: v.szLimit,
12669
- pxLimit: v.pxLimit,
12670
- timeInterval: v.timeInterval,
12671
- posSide: v.posSide,
12672
- pxVar: v.pxVar,
12673
- pxSpread: v.pxSpread,
12674
- algoClOrdId: v.algoClOrdId,
12675
- ccy: v.ccy,
12676
- tradeQuoteCcy: v.tradeQuoteCcy,
12677
- reduceOnly: v.reduceOnly || void 0,
12678
- isTradeBorrowMode: v.isTradeBorrowMode || void 0,
12679
- json
12680
- });
12681
- if (subAction === "cancel")
12682
- return cmdTwapCancel(client, { instId: v.instId, algoId: v.algoId, algoClOrdId: v.algoClOrdId, json });
12683
- }
12684
- function handleBotRecurringCommand(client, subAction, v, json) {
12685
- if (subAction === "orders")
12686
- return cmdRecurringOrders(client, { algoId: v.algoId, history: v.history ?? false, json });
12687
- if (subAction === "details")
12688
- return cmdRecurringDetails(client, { algoId: v.algoId, json });
12689
- if (subAction === "sub-orders")
12690
- return cmdRecurringSubOrders(client, { algoId: v.algoId, json });
12691
- if (subAction === "create")
12692
- return cmdRecurringCreate(client, {
12693
- stgyName: v.stgyName,
12694
- recurringList: v.recurringList,
12695
- period: v.period,
12696
- recurringDay: v.recurringDay,
12697
- recurringTime: v.recurringTime,
12698
- recurringHour: v.recurringHour,
12699
- timeZone: v.timeZone,
12700
- amt: v.amt,
12701
- investmentCcy: v.investmentCcy,
12702
- tdMode: v.tdMode,
12703
- tradeQuoteCcy: v.tradeQuoteCcy,
12704
- algoClOrdId: v.algoClOrdId,
12705
- json
12706
- });
12707
- if (subAction === "amend")
12708
- return cmdRecurringAmend(client, {
12709
- algoId: v.algoId,
12710
- stgyName: v.stgyName,
12711
- json
12712
- });
12713
- if (subAction === "stop")
12714
- return cmdRecurringStop(client, { algoId: v.algoId, json });
12715
11609
  }
12716
- function handleBotCommand(run, client, action, rest, v, json) {
12717
- if (action === "grid") return handleBotGridCommand(run, client, v, rest, json);
12718
- if (action === "dca") return handleBotDcaCommand(run, client, rest[0], v, json);
12719
- if (action === "twap") return handleBotTwapCommand(client, rest[0], v, json);
12720
- if (action === "recurring") return handleBotRecurringCommand(client, rest[0], v, json);
11610
+ function handleBotCommand(run, action, rest, v, json) {
11611
+ if (action === "grid") return handleBotGridCommand(run, v, rest, json);
11612
+ if (action === "dca") return handleBotDcaCommand(run, rest[0], v, json);
12721
11613
  }
12722
11614
  function handleEarnCommand(run, submodule, rest, v, json) {
12723
11615
  const action = rest[0];
@@ -12865,7 +11757,7 @@ async function main() {
12865
11757
  swap: () => handleSwapCommand(run, action, rest, v, json),
12866
11758
  futures: () => handleFuturesCommand(run, action, rest, v, json),
12867
11759
  option: () => handleOptionCommand(run, action, rest, v, json),
12868
- bot: () => handleBotCommand(run, client, action, rest, v, json),
11760
+ bot: () => handleBotCommand(run, action, rest, v, json),
12869
11761
  earn: () => handleEarnCommand(run, action, rest, v, json)
12870
11762
  };
12871
11763
  const handler = moduleHandlers[module];
@@ -12891,8 +11783,6 @@ export {
12891
11783
  handleBotCommand,
12892
11784
  handleBotDcaCommand,
12893
11785
  handleBotGridCommand,
12894
- handleBotRecurringCommand,
12895
- handleBotTwapCommand,
12896
11786
  handleConfigCommand,
12897
11787
  handleEarnCommand,
12898
11788
  handleFuturesAlgoCommand,