@okx_ai/okx-trade-cli 1.2.6-beta.1 → 1.2.7-beta.1

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
@@ -1524,7 +1524,8 @@ var BOT_DEFAULT_SUB_MODULES = ["bot.grid"];
1524
1524
  var EARN_SUB_MODULE_IDS = [
1525
1525
  "earn.savings",
1526
1526
  "earn.onchain",
1527
- "earn.dcd"
1527
+ "earn.dcd",
1528
+ "earn.autoearn"
1528
1529
  ];
1529
1530
  var MODULES = [
1530
1531
  "market",
@@ -2141,6 +2142,11 @@ function registerAlgoTradeTools() {
2141
2142
  type: "string",
2142
2143
  description: "Activation price; tracking starts after market reaches this level (move_order_stop only)"
2143
2144
  },
2145
+ tgtCcy: {
2146
+ type: "string",
2147
+ enum: ["base_ccy", "quote_ccy"],
2148
+ description: "Size unit. base_ccy(default): sz in contracts, quote_ccy: sz in USDT"
2149
+ },
2144
2150
  reduceOnly: {
2145
2151
  type: "boolean",
2146
2152
  description: "Ensure order only reduces position"
@@ -2164,6 +2170,7 @@ function registerAlgoTradeTools() {
2164
2170
  posSide: readString(args, "posSide"),
2165
2171
  ordType: requireString(args, "ordType"),
2166
2172
  sz: requireString(args, "sz"),
2173
+ tgtCcy: readString(args, "tgtCcy"),
2167
2174
  tpTriggerPx: readString(args, "tpTriggerPx"),
2168
2175
  tpOrdPx: readString(args, "tpOrdPx"),
2169
2176
  tpTriggerPxType: readString(args, "tpTriggerPxType"),
@@ -2468,6 +2475,11 @@ function registerFuturesAlgoTools() {
2468
2475
  type: "string",
2469
2476
  description: "Activation price; tracking starts after market reaches this level (move_order_stop only)"
2470
2477
  },
2478
+ tgtCcy: {
2479
+ type: "string",
2480
+ enum: ["base_ccy", "quote_ccy"],
2481
+ description: "Size unit. base_ccy(default): sz in contracts, quote_ccy: sz in USDT"
2482
+ },
2471
2483
  reduceOnly: {
2472
2484
  type: "boolean",
2473
2485
  description: "Ensure order only reduces position"
@@ -2491,6 +2503,7 @@ function registerFuturesAlgoTools() {
2491
2503
  posSide: readString(args, "posSide"),
2492
2504
  ordType: requireString(args, "ordType"),
2493
2505
  sz: requireString(args, "sz"),
2506
+ tgtCcy: readString(args, "tgtCcy"),
2494
2507
  tpTriggerPx: readString(args, "tpTriggerPx"),
2495
2508
  tpOrdPx: readString(args, "tpOrdPx"),
2496
2509
  tpTriggerPxType: readString(args, "tpTriggerPxType"),
@@ -2873,7 +2886,7 @@ function registerGridTools() {
2873
2886
  enum: ["active", "history"],
2874
2887
  description: "active=running (default); history=stopped"
2875
2888
  },
2876
- instId: { type: "string", description: "e.g. BTC-USDT" },
2889
+ instId: { type: "string", description: "e.g. BTC-USDT, BTC-USD-SWAP" },
2877
2890
  algoId: { type: "string", description: "Grid bot algo order ID (not a trade ordId)" },
2878
2891
  after: { type: "string", description: "Cursor for older records" },
2879
2892
  before: { type: "string", description: "Cursor for newer records" },
@@ -2978,12 +2991,12 @@ function registerGridTools() {
2978
2991
  {
2979
2992
  name: "grid_create_order",
2980
2993
  module: "bot.grid",
2981
- description: "Create grid bot. [CAUTION] Real trades, locks funds. Spot('grid'): need quoteSz|baseSz. Contract('contract_grid'): need direction+lever+sz.",
2994
+ description: "Create grid bot (spot, USDT-margined, or coin-margined contract). [CAUTION] Locks funds. Spot: quoteSz|baseSz. Contract: direction+lever+sz.",
2982
2995
  isWrite: true,
2983
2996
  inputSchema: {
2984
2997
  type: "object",
2985
2998
  properties: {
2986
- instId: { type: "string", description: "e.g. BTC-USDT" },
2999
+ instId: { type: "string", description: "e.g. BTC-USDT, BTC-USDT-SWAP, BTC-USD-SWAP (coin-margined)" },
2987
3000
  algoOrdType: {
2988
3001
  type: "string",
2989
3002
  enum: ["grid", "contract_grid"],
@@ -3005,8 +3018,13 @@ function registerGridTools() {
3005
3018
  description: "Contract only"
3006
3019
  },
3007
3020
  lever: { type: "string", description: "Leverage. Contract only" },
3008
- sz: { type: "string", description: "Margin amount. Contract only" },
3009
- basePos: { type: "boolean", description: "Open base position for contract. Default: true" }
3021
+ sz: { type: "string", description: "Margin in USDT or base coin (CoinM). Contract only" },
3022
+ basePos: { type: "boolean", description: "Open base position for contract. Default: true" },
3023
+ tpTriggerPx: { type: "string", description: "TP trigger price" },
3024
+ slTriggerPx: { type: "string", description: "SL trigger price" },
3025
+ tpRatio: { type: "string", description: "TP ratio e.g. 0.1=10%. Contract only" },
3026
+ slRatio: { type: "string", description: "SL ratio e.g. 0.1=10%. Contract only" },
3027
+ algoClOrdId: { type: "string", description: "User-defined ID. Alphanumeric, max 32, unique per user" }
3010
3028
  },
3011
3029
  required: ["instId", "algoOrdType", "maxPx", "minPx", "gridNum"]
3012
3030
  },
@@ -3025,9 +3043,15 @@ function registerGridTools() {
3025
3043
  direction: readString(args, "direction"),
3026
3044
  lever: readString(args, "lever"),
3027
3045
  sz: readString(args, "sz"),
3046
+ tpTriggerPx: readString(args, "tpTriggerPx"),
3047
+ slTriggerPx: readString(args, "slTriggerPx"),
3048
+ tpRatio: readString(args, "tpRatio"),
3049
+ slRatio: readString(args, "slRatio"),
3050
+ algoClOrdId: readString(args, "algoClOrdId"),
3028
3051
  tag: context.config.sourceTag
3029
3052
  });
3030
3053
  if (algoOrdType === "contract_grid") {
3054
+ requireString(args, "direction");
3031
3055
  body.triggerParams = [{ triggerAction: "start", triggerStrategy: "instant" }];
3032
3056
  body.basePos = readBoolean(args, "basePos") ?? true;
3033
3057
  }
@@ -3053,11 +3077,11 @@ function registerGridTools() {
3053
3077
  enum: ["grid", "contract_grid"],
3054
3078
  description: "grid=Spot, contract_grid=Contract"
3055
3079
  },
3056
- instId: { type: "string", description: "e.g. BTC-USDT" },
3080
+ instId: { type: "string", description: "e.g. BTC-USDT, BTC-USD-SWAP" },
3057
3081
  stopType: {
3058
3082
  type: "string",
3059
3083
  enum: ["1", "2", "3", "5", "6"],
3060
- description: "1=close all; 2=keep assets (default); 3=limit close; 5=partial; 6=no sell"
3084
+ description: "1=close all (default); 2=keep assets; 3=limit close; 5=partial; 6=no sell"
3061
3085
  }
3062
3086
  },
3063
3087
  required: ["algoId", "algoOrdType", "instId"]
@@ -3070,7 +3094,7 @@ function registerGridTools() {
3070
3094
  algoId: requireString(args, "algoId"),
3071
3095
  algoOrdType: requireString(args, "algoOrdType"),
3072
3096
  instId: requireString(args, "instId"),
3073
- stopType: readString(args, "stopType") ?? "2"
3097
+ stopType: readString(args, "stopType") ?? "1"
3074
3098
  })],
3075
3099
  privateRateLimit("grid_stop_order", 20)
3076
3100
  );
@@ -3311,7 +3335,7 @@ function registerEarnTools() {
3311
3335
  {
3312
3336
  name: "earn_get_savings_balance",
3313
3337
  module: "earn.savings",
3314
- description: "Get Simple Earn (savings/flexible earn) balance. Returns current holdings for all currencies or a specific one. To show market rates alongside balance (\u5E02\u573A\u5747\u5229\u7387), call earn_get_lending_rate_history \u2014 do NOT use earn_get_lending_rate_summary for this purpose.",
3338
+ description: "Get Simple Earn (savings/flexible earn) balance. Returns current holdings, lent amount, pending interest, and the user's set rate. Response fields: amt (total held), loanAmt (actively lent), pendingAmt (awaiting match), earnings (cumulative interest), rate (user's own minimum lending rate setting \u2014 NOT market yield, NOT APY). To get the actual market lending rate, call earn_get_lending_rate_history instead.",
3315
3339
  isWrite: false,
3316
3340
  inputSchema: {
3317
3341
  type: "object",
@@ -3350,7 +3374,7 @@ function registerEarnTools() {
3350
3374
  },
3351
3375
  rate: {
3352
3376
  type: "string",
3353
- description: "Lending rate. Annual rate in decimal, e.g. 0.01 = 1%. Defaults to 0.01 (1%, minimum rate, easiest to match)."
3377
+ description: "Minimum lending rate threshold (annual, decimal). e.g. 0.01 = 1%. Only matched when market rate \u2265 this value. Defaults to 0.01. Keep at 0.01 to maximize matching probability \u2014 do NOT raise this to increase yield, as actual yield (lendingRate) is determined by market supply/demand, not this setting."
3354
3378
  }
3355
3379
  },
3356
3380
  required: ["ccy", "amt"]
@@ -3419,7 +3443,7 @@ function registerEarnTools() {
3419
3443
  },
3420
3444
  rate: {
3421
3445
  type: "string",
3422
- description: "Lending rate. Annual rate in decimal, e.g. 0.01 = 1%"
3446
+ description: "Minimum lending rate threshold (annual, decimal). e.g. 0.01 = 1%. Only matched when market rate \u2265 this value. Keep at 0.01 to maximize matching probability \u2014 do NOT raise this to increase yield, as actual yield (lendingRate) is determined by market supply/demand, not this setting."
3423
3447
  }
3424
3448
  },
3425
3449
  required: ["ccy", "rate"]
@@ -3441,7 +3465,7 @@ function registerEarnTools() {
3441
3465
  {
3442
3466
  name: "earn_get_lending_history",
3443
3467
  module: "earn.savings",
3444
- description: "Get market lending rate history for Simple Earn. Use this tool to query market lending rates. Returns market lending records with amount, rate, and earnings data.",
3468
+ description: "Get personal lending records for Simple Earn (your own lending history). NOT for market rate queries. Returns your lending records with amount, rate, and earnings data.",
3445
3469
  isWrite: false,
3446
3470
  inputSchema: {
3447
3471
  type: "object",
@@ -3479,34 +3503,10 @@ function registerEarnTools() {
3479
3503
  return normalizeResponse(response);
3480
3504
  }
3481
3505
  },
3482
- {
3483
- name: "earn_get_lending_rate_summary",
3484
- module: "earn.savings",
3485
- description: "Get coin lending market rate summary. NOT related to Simple Earn. Use this to query the lending/borrowing market rates (\u501F\u5E01\u5E02\u573A\u5229\u7387). Returns aggregate overview: average rate (avgRate), estimated next-cycle rate (estRate), previous-cycle rate (preRate), and available lending amounts.",
3486
- isWrite: false,
3487
- inputSchema: {
3488
- type: "object",
3489
- properties: {
3490
- ccy: {
3491
- type: "string",
3492
- description: "e.g. USDT. Omit for all."
3493
- }
3494
- }
3495
- },
3496
- handler: async (rawArgs, context) => {
3497
- const args = asRecord(rawArgs);
3498
- const response = await context.client.publicGet(
3499
- "/api/v5/finance/savings/lending-rate-summary",
3500
- compactObject({ ccy: readString(args, "ccy") }),
3501
- publicRateLimit("earn_get_lending_rate_summary", 6)
3502
- );
3503
- return normalizeResponse(response);
3504
- }
3505
- },
3506
3506
  {
3507
3507
  name: "earn_get_lending_rate_history",
3508
3508
  module: "earn.savings",
3509
- description: "Query Simple Earn lending rates. Use this tool when the user asks about current or historical lending rates for Simple Earn, or when displaying savings balance with market rate context (\u5E02\u573A\u5747\u5229\u7387). Returns actual settled lending rate records (lendingRate field) with timestamps, ordered newest-first.",
3509
+ description: "Query Simple Earn lending rates. Public endpoint (no API key required). Use this tool when the user asks about current or historical lending rates for Simple Earn, or when displaying savings balance with market rate context. Response fields per record: rate (market lending rate \u2014 the rate borrowers pay this period; user's minimum setting must be \u2264 this to be eligible), lendingRate (actual yield received by lenders; stablecoins e.g. USDT/USDC only: subject to pro-rata dilution \u2014 when eligible supply exceeds borrowing demand total interest is shared so lendingRate < rate; non-stablecoins: lendingRate = rate, no dilution; always use lendingRate as the true APY to show users), ts (settlement timestamp ms). To get current APY: use limit=1 and read lendingRate.",
3510
3510
  isWrite: false,
3511
3511
  inputSchema: {
3512
3512
  type: "object",
@@ -3890,7 +3890,7 @@ function registerDcdTools() {
3890
3890
  properties: {
3891
3891
  baseCcy: { type: "string", description: "Base currency, e.g. BTC" },
3892
3892
  quoteCcy: { type: "string", description: "Quote currency, e.g. USDT" },
3893
- optType: { type: "string", description: "Option type: C (Call/\u9AD8\u5356) or P (Put/\u4F4E\u4E70)" }
3893
+ optType: { type: "string", description: "Option type: C (Call, sell high) or P (Put, buy low)" }
3894
3894
  },
3895
3895
  required: ["baseCcy", "quoteCcy", "optType"]
3896
3896
  },
@@ -4129,11 +4129,53 @@ function registerDcdTools() {
4129
4129
  }
4130
4130
  ];
4131
4131
  }
4132
+ function registerAutoEarnTools() {
4133
+ return [
4134
+ {
4135
+ name: "earn_auto_set",
4136
+ module: "earn.autoearn",
4137
+ description: "Enable or disable auto-earn for a currency. earnType='0' for auto-lend+stake (most currencies); earnType='1' for USDG earn (USDG, BUIDL). Use account_get_balance first: if autoLendStatus or autoStakingStatus != 'unsupported', use earnType='0'; for USDG/BUIDL use earnType='1'. [CAUTION] Cannot disable within 24h of enabling.",
4138
+ isWrite: true,
4139
+ inputSchema: {
4140
+ type: "object",
4141
+ properties: {
4142
+ ccy: {
4143
+ type: "string",
4144
+ description: "Currency, e.g. SOL, USDG"
4145
+ },
4146
+ action: {
4147
+ type: "string",
4148
+ description: "turn_on or turn_off"
4149
+ },
4150
+ earnType: {
4151
+ type: "string",
4152
+ description: "0=auto-lend+stake (default), 1=USDG earn. Omit to use default."
4153
+ }
4154
+ },
4155
+ required: ["ccy", "action"]
4156
+ },
4157
+ handler: async (rawArgs, context) => {
4158
+ const args = asRecord(rawArgs);
4159
+ const response = await context.client.privatePost(
4160
+ "/api/v5/account/set-auto-earn",
4161
+ compactObject({
4162
+ ccy: requireString(args, "ccy"),
4163
+ action: requireString(args, "action"),
4164
+ earnType: readString(args, "earnType") ?? "0"
4165
+ }),
4166
+ privateRateLimit("earn_auto_set", 10)
4167
+ );
4168
+ return normalizeResponse(response);
4169
+ }
4170
+ }
4171
+ ];
4172
+ }
4132
4173
  function registerAllEarnTools() {
4133
4174
  return [
4134
4175
  ...registerEarnTools(),
4135
4176
  ...registerOnchainEarnTools(),
4136
- ...registerDcdTools()
4177
+ ...registerDcdTools(),
4178
+ ...registerAutoEarnTools()
4137
4179
  ];
4138
4180
  }
4139
4181
  function buildContractTradeTools(cfg) {
@@ -5247,6 +5289,11 @@ function registerOptionAlgoTools() {
5247
5289
  type: "string",
5248
5290
  enum: ["last", "index", "mark"]
5249
5291
  },
5292
+ tgtCcy: {
5293
+ type: "string",
5294
+ enum: ["base_ccy", "quote_ccy"],
5295
+ description: "Size unit. base_ccy(default): sz in contracts, quote_ccy: sz in USDT (may not be supported for options)"
5296
+ },
5250
5297
  reduceOnly: {
5251
5298
  type: "boolean",
5252
5299
  description: "Ensure order only reduces position"
@@ -5269,6 +5316,7 @@ function registerOptionAlgoTools() {
5269
5316
  side: requireString(args, "side"),
5270
5317
  ordType: requireString(args, "ordType"),
5271
5318
  sz: requireString(args, "sz"),
5319
+ tgtCcy: readString(args, "tgtCcy"),
5272
5320
  tpTriggerPx: readString(args, "tpTriggerPx"),
5273
5321
  tpOrdPx: readString(args, "tpOrdPx"),
5274
5322
  tpTriggerPxType: readString(args, "tpTriggerPxType"),
@@ -6116,6 +6164,11 @@ function registerSpotTradeTools() {
6116
6164
  type: "string",
6117
6165
  description: "SL order price, -1=market (conditional/oco only)"
6118
6166
  },
6167
+ tgtCcy: {
6168
+ type: "string",
6169
+ enum: ["base_ccy", "quote_ccy"],
6170
+ description: "Size unit. base_ccy(default): sz in base (e.g. BTC), quote_ccy: sz in quote (e.g. USDT)"
6171
+ },
6119
6172
  callbackRatio: {
6120
6173
  type: "string",
6121
6174
  description: "Callback ratio e.g. 0.01=1%, use ratio or spread (move_order_stop only)"
@@ -6141,6 +6194,7 @@ function registerSpotTradeTools() {
6141
6194
  side: requireString(args, "side"),
6142
6195
  ordType: requireString(args, "ordType"),
6143
6196
  sz: requireString(args, "sz"),
6197
+ tgtCcy: readString(args, "tgtCcy"),
6144
6198
  tpTriggerPx: readString(args, "tpTriggerPx"),
6145
6199
  tpOrdPx: readString(args, "tpOrdPx"),
6146
6200
  slTriggerPx: readString(args, "slTriggerPx"),
@@ -7524,7 +7578,7 @@ async function cmdDiagnoseMcp(options = {}) {
7524
7578
 
7525
7579
  // src/commands/diagnose.ts
7526
7580
  var CLI_VERSION = readCliVersion();
7527
- var GIT_HASH = true ? "c27439d" : "dev";
7581
+ var GIT_HASH = true ? "7ff8d64" : "dev";
7528
7582
  function maskKey2(key) {
7529
7583
  if (!key) return "(not set)";
7530
7584
  if (key.length <= 8) return "****";
@@ -8253,11 +8307,7 @@ var HELP_TREE = {
8253
8307
  },
8254
8308
  "lending-history": {
8255
8309
  usage: "okx earn savings lending-history [--ccy <ccy>] [--limit <n>]",
8256
- description: "Get market lending rate history"
8257
- },
8258
- "rate-summary": {
8259
- usage: "okx earn savings rate-summary [<ccy>]",
8260
- description: "Get coin lending market rate summary (not Simple Earn, public)"
8310
+ description: "Get personal lending records (requires auth)"
8261
8311
  },
8262
8312
  "rate-history": {
8263
8313
  usage: "okx earn savings rate-history [--ccy <ccy>] [--limit <n>]",
@@ -8294,6 +8344,23 @@ var HELP_TREE = {
8294
8344
  }
8295
8345
  }
8296
8346
  },
8347
+ "auto-earn": {
8348
+ description: "Auto-earn \u2014 automatically lend, stake, or earn on idle assets",
8349
+ commands: {
8350
+ status: {
8351
+ usage: "okx earn auto-earn status [<ccy>]",
8352
+ description: "Query auto-earn status for all or a specific currency"
8353
+ },
8354
+ on: {
8355
+ usage: "okx earn auto-earn on <ccy>",
8356
+ description: "Enable auto-earn for a currency (auto-detects lend/stake vs USDG earn)"
8357
+ },
8358
+ off: {
8359
+ usage: "okx earn auto-earn off <ccy>",
8360
+ description: "Disable auto-earn for a currency"
8361
+ }
8362
+ }
8363
+ },
8297
8364
  dcd: {
8298
8365
  description: "DCD (Dual Currency Deposit) \u2014 structured products with fixed yield",
8299
8366
  commands: {
@@ -8344,7 +8411,7 @@ var HELP_TREE = {
8344
8411
  description: "List sub-orders of a grid bot (filled or live)"
8345
8412
  },
8346
8413
  create: {
8347
- 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]",
8414
+ 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>] [--tpRatio <n>] [--slRatio <n>] [--algoClOrdId <id>]",
8348
8415
  description: "Create a new grid bot order (contract grid opens base position by default)"
8349
8416
  },
8350
8417
  stop: {
@@ -8588,6 +8655,9 @@ var CLI_OPTIONS = {
8588
8655
  baseSz: { type: "string" },
8589
8656
  direction: { type: "string" },
8590
8657
  basePos: { type: "boolean", default: true },
8658
+ tpRatio: { type: "string" },
8659
+ slRatio: { type: "string" },
8660
+ algoClOrdId: { type: "string" },
8591
8661
  stopType: { type: "string" },
8592
8662
  live: { type: "boolean", default: false },
8593
8663
  // market extras
@@ -9263,6 +9333,7 @@ async function cmdSpotAlgoPlace(run, opts) {
9263
9333
  side: opts.side,
9264
9334
  ordType: opts.ordType,
9265
9335
  sz: opts.sz,
9336
+ tgtCcy: opts.tgtCcy,
9266
9337
  tpTriggerPx: opts.tpTriggerPx,
9267
9338
  tpOrdPx: opts.tpOrdPx,
9268
9339
  slTriggerPx: opts.slTriggerPx,
@@ -9510,6 +9581,7 @@ async function cmdSwapAlgoPlace(run, opts) {
9510
9581
  side: opts.side,
9511
9582
  ordType: opts.ordType,
9512
9583
  sz: opts.sz,
9584
+ tgtCcy: opts.tgtCcy,
9513
9585
  posSide: opts.posSide,
9514
9586
  tpTriggerPx: opts.tpTriggerPx,
9515
9587
  tpOrdPx: opts.tpOrdPx,
@@ -9915,6 +9987,7 @@ async function cmdFuturesAlgoPlace(run, opts) {
9915
9987
  side: opts.side,
9916
9988
  ordType: opts.ordType,
9917
9989
  sz: opts.sz,
9990
+ tgtCcy: opts.tgtCcy,
9918
9991
  posSide: opts.posSide,
9919
9992
  tpTriggerPx: opts.tpTriggerPx,
9920
9993
  tpOrdPx: opts.tpOrdPx,
@@ -10209,6 +10282,7 @@ async function cmdOptionAlgoPlace(run, opts) {
10209
10282
  side: opts.side,
10210
10283
  ordType: opts.ordType,
10211
10284
  sz: opts.sz,
10285
+ tgtCcy: opts.tgtCcy,
10212
10286
  tpTriggerPx: opts.tpTriggerPx,
10213
10287
  tpOrdPx: opts.tpOrdPx,
10214
10288
  slTriggerPx: opts.slTriggerPx,
@@ -10648,15 +10722,6 @@ async function cmdEarnLendingHistory(run, opts) {
10648
10722
  ts: new Date(Number(r["ts"])).toLocaleString()
10649
10723
  }));
10650
10724
  }
10651
- async function cmdEarnLendingRateSummary(run, ccy, json) {
10652
- const data = extractData(await run("earn_get_lending_rate_summary", { ccy }));
10653
- printDataList(data, json, "No rate summary data", (r) => ({
10654
- ccy: r["ccy"],
10655
- avgRate: r["avgRate"],
10656
- estRate: r["estRate"],
10657
- avgAmt: r["avgAmt"]
10658
- }));
10659
- }
10660
10725
  async function cmdEarnLendingRateHistory(run, opts) {
10661
10726
  const data = extractData(await run("earn_get_lending_rate_history", { ccy: opts.ccy, limit: opts.limit }));
10662
10727
  printDataList(data, opts.json, "No rate history data", (r) => ({
@@ -10667,6 +10732,92 @@ async function cmdEarnLendingRateHistory(run, opts) {
10667
10732
  }));
10668
10733
  }
10669
10734
 
10735
+ // src/commands/auto-earn.ts
10736
+ var USDG_EARN_CURRENCIES = /* @__PURE__ */ new Set(["USDG", "BUIDL"]);
10737
+ function isSupported(status) {
10738
+ return !!status && status !== "unsupported";
10739
+ }
10740
+ function inferEarnType(detail) {
10741
+ if (isSupported(detail.autoLendStatus) || isSupported(detail.autoStakingStatus)) return "0";
10742
+ if (USDG_EARN_CURRENCIES.has(detail.ccy)) return "1";
10743
+ return null;
10744
+ }
10745
+ async function getBalanceDetails(run, ccy) {
10746
+ const result = await run("account_get_balance", ccy ? { ccy } : {});
10747
+ const data = result.data;
10748
+ const first = data?.[0];
10749
+ return first?.details ?? [];
10750
+ }
10751
+ function earnTypeLabel(et) {
10752
+ return et === "1" ? "USDG earn" : "lend+stake";
10753
+ }
10754
+ async function cmdAutoEarnStatus(run, ccy, json) {
10755
+ const details = await getBalanceDetails(run, ccy);
10756
+ const relevant = details.filter((d) => inferEarnType(d) !== null);
10757
+ if (json) {
10758
+ printJson(relevant);
10759
+ return;
10760
+ }
10761
+ if (!relevant.length) {
10762
+ outputLine(ccy ? `${ccy} does not support auto-earn` : "No currencies support auto-earn");
10763
+ return;
10764
+ }
10765
+ printTable(relevant.map((d) => {
10766
+ const et = inferEarnType(d);
10767
+ return {
10768
+ ccy: d.ccy,
10769
+ earnType: earnTypeLabel(et),
10770
+ autoLend: d.autoLendStatus,
10771
+ autoStaking: d.autoStakingStatus,
10772
+ invested: et === "1" ? d.eq || "-" : d.autoLendAmt || "-",
10773
+ matched: d.autoLendMtAmt || "-",
10774
+ apr: d.autoLendApr ? `${(Number(d.autoLendApr) * 100).toFixed(2)}%` : "-"
10775
+ };
10776
+ }));
10777
+ }
10778
+ async function cmdAutoEarnOn(run, ccy, json) {
10779
+ const details = await getBalanceDetails(run, ccy);
10780
+ const detail = details.find((d) => d.ccy === ccy);
10781
+ if (!detail) {
10782
+ errorLine(`Currency ${ccy} not found in account balance`);
10783
+ process.exitCode = 1;
10784
+ return;
10785
+ }
10786
+ const earnType = inferEarnType(detail);
10787
+ if (earnType === null) {
10788
+ errorLine(`${ccy} does not support auto-earn`);
10789
+ process.exitCode = 1;
10790
+ return;
10791
+ }
10792
+ const result = await run("earn_auto_set", { ccy, action: "turn_on", earnType });
10793
+ if (json) {
10794
+ printJson(result.data);
10795
+ return;
10796
+ }
10797
+ outputLine(`Auto-earn enabled for ${ccy} (${earnTypeLabel(earnType)})`);
10798
+ }
10799
+ async function cmdAutoEarnOff(run, ccy, json) {
10800
+ const details = await getBalanceDetails(run, ccy);
10801
+ const detail = details.find((d) => d.ccy === ccy);
10802
+ if (!detail) {
10803
+ errorLine(`Currency ${ccy} not found in account balance`);
10804
+ process.exitCode = 1;
10805
+ return;
10806
+ }
10807
+ const earnType = inferEarnType(detail);
10808
+ if (earnType === null) {
10809
+ errorLine(`${ccy} does not support auto-earn`);
10810
+ process.exitCode = 1;
10811
+ return;
10812
+ }
10813
+ const result = await run("earn_auto_set", { ccy, action: "turn_off", earnType });
10814
+ if (json) {
10815
+ printJson(result.data);
10816
+ return;
10817
+ }
10818
+ outputLine(`Auto-earn disabled for ${ccy} (${earnTypeLabel(earnType)})`);
10819
+ }
10820
+
10670
10821
  // src/commands/bot.ts
10671
10822
  function emitWriteResult5(item, label, idKey) {
10672
10823
  const isError = item?.["sCode"] !== "0" && item?.["sCode"] !== 0;
@@ -10771,7 +10922,12 @@ async function cmdGridCreate(run, opts) {
10771
10922
  direction: opts.direction,
10772
10923
  lever: opts.lever,
10773
10924
  sz: opts.sz,
10774
- basePos: opts.basePos
10925
+ basePos: opts.basePos,
10926
+ tpTriggerPx: opts.tpTriggerPx,
10927
+ slTriggerPx: opts.slTriggerPx,
10928
+ tpRatio: opts.tpRatio,
10929
+ slRatio: opts.slRatio,
10930
+ algoClOrdId: opts.algoClOrdId
10775
10931
  });
10776
10932
  const data = getData7(result);
10777
10933
  if (opts.json) return printJson(data);
@@ -11193,7 +11349,7 @@ async function cmdDcdQuoteAndBuy(run, opts) {
11193
11349
  // src/index.ts
11194
11350
  var _require3 = createRequire3(import.meta.url);
11195
11351
  var CLI_VERSION2 = _require3("../package.json").version;
11196
- var GIT_HASH2 = true ? "c27439d" : "dev";
11352
+ var GIT_HASH2 = true ? "7ff8d64" : "dev";
11197
11353
  function handleConfigCommand(action, rest, json, lang, force) {
11198
11354
  if (action === "init") return cmdConfigInit(lang === "zh" ? "zh" : "en");
11199
11355
  if (action === "show") return cmdConfigShow(json);
@@ -11331,6 +11487,7 @@ function handleSpotAlgoCommand(run, subAction, v, json) {
11331
11487
  side: v.side,
11332
11488
  ordType: v.ordType ?? "conditional",
11333
11489
  sz: v.sz,
11490
+ tgtCcy: v.tgtCcy,
11334
11491
  tpTriggerPx: v.tpTriggerPx,
11335
11492
  tpOrdPx: v.tpOrdPx,
11336
11493
  slTriggerPx: v.slTriggerPx,
@@ -11425,6 +11582,7 @@ function handleSwapAlgoCommand(run, subAction, v, json) {
11425
11582
  sz: v.sz,
11426
11583
  posSide: v.posSide,
11427
11584
  tdMode: v.tdMode ?? "cross",
11585
+ tgtCcy: v.tgtCcy,
11428
11586
  tpTriggerPx: v.tpTriggerPx,
11429
11587
  tpOrdPx: v.tpOrdPx,
11430
11588
  slTriggerPx: v.slTriggerPx,
@@ -11537,6 +11695,7 @@ function handleOptionAlgoCommand(run, subAction, v, json) {
11537
11695
  side: v.side,
11538
11696
  ordType: v.ordType ?? "conditional",
11539
11697
  sz: v.sz,
11698
+ tgtCcy: v.tgtCcy,
11540
11699
  tpTriggerPx: v.tpTriggerPx,
11541
11700
  tpOrdPx: v.tpOrdPx,
11542
11701
  slTriggerPx: v.slTriggerPx,
@@ -11637,6 +11796,7 @@ function handleFuturesAlgoCommand(run, subAction, v, json) {
11637
11796
  sz: v.sz,
11638
11797
  posSide: v.posSide,
11639
11798
  tdMode: v.tdMode ?? "cross",
11799
+ tgtCcy: v.tgtCcy,
11640
11800
  tpTriggerPx: v.tpTriggerPx,
11641
11801
  tpOrdPx: v.tpOrdPx,
11642
11802
  slTriggerPx: v.slTriggerPx,
@@ -11779,6 +11939,11 @@ function handleBotGridCommand(run, v, rest, json) {
11779
11939
  lever: v.lever,
11780
11940
  sz: v.sz,
11781
11941
  basePos: v.basePos,
11942
+ tpTriggerPx: v.tpTriggerPx,
11943
+ slTriggerPx: v.slTriggerPx,
11944
+ tpRatio: v.tpRatio,
11945
+ slRatio: v.slRatio,
11946
+ algoClOrdId: v.algoClOrdId,
11782
11947
  json
11783
11948
  });
11784
11949
  if (subAction === "stop")
@@ -11829,8 +11994,32 @@ function handleEarnCommand(run, submodule, rest, v, json) {
11829
11994
  if (submodule === "savings") return handleEarnSavingsCommand(run, action, innerRest, v, json);
11830
11995
  if (submodule === "onchain") return handleEarnOnchainCommand(run, action, v, json);
11831
11996
  if (submodule === "dcd") return handleEarnDcdCommand(run, action, v, json);
11997
+ if (submodule === "auto-earn") return handleEarnAutoEarnCommand(run, action, innerRest, v, json);
11832
11998
  errorLine(`Unknown earn sub-module: ${submodule}`);
11833
- errorLine("Valid: savings, onchain, dcd");
11999
+ errorLine("Valid: savings, onchain, dcd, auto-earn");
12000
+ process.exitCode = 1;
12001
+ }
12002
+ function handleEarnAutoEarnCommand(run, action, rest, v, json) {
12003
+ const ccy = rest[0] ?? v.ccy;
12004
+ if (action === "status") return cmdAutoEarnStatus(run, ccy, json);
12005
+ if (action === "on") {
12006
+ if (!ccy) {
12007
+ errorLine("Currency required: okx earn auto-earn on <ccy>");
12008
+ process.exitCode = 1;
12009
+ return;
12010
+ }
12011
+ return cmdAutoEarnOn(run, ccy, json);
12012
+ }
12013
+ if (action === "off") {
12014
+ if (!ccy) {
12015
+ errorLine("Currency required: okx earn auto-earn off <ccy>");
12016
+ process.exitCode = 1;
12017
+ return;
12018
+ }
12019
+ return cmdAutoEarnOff(run, ccy, json);
12020
+ }
12021
+ errorLine(`Unknown auto-earn command: ${action}`);
12022
+ errorLine("Valid: status, on, off");
11834
12023
  process.exitCode = 1;
11835
12024
  }
11836
12025
  function handleEarnSavingsCommand(run, action, rest, v, json) {
@@ -11840,7 +12029,6 @@ function handleEarnSavingsCommand(run, action, rest, v, json) {
11840
12029
  if (action === "redeem") return cmdEarnSavingsRedeem(run, { ccy: v.ccy, amt: v.amt, json });
11841
12030
  if (action === "set-rate") return cmdEarnSetLendingRate(run, { ccy: v.ccy, rate: v.rate, json });
11842
12031
  if (action === "lending-history") return cmdEarnLendingHistory(run, { ccy: v.ccy, limit, json });
11843
- if (action === "rate-summary") return cmdEarnLendingRateSummary(run, rest[0] ?? v.ccy, json);
11844
12032
  if (action === "rate-history") return cmdEarnLendingRateHistory(run, { ccy: v.ccy, limit, json });
11845
12033
  errorLine(`Unknown earn savings command: ${action}`);
11846
12034
  process.exitCode = 1;