@okx_ai/okx-trade-cli 1.3.8-beta.4 → 1.3.8-beta.5

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
@@ -1003,6 +1003,7 @@ function writeCache(hostname, entry, cachePath = getDefaultCachePath()) {
1003
1003
  }
1004
1004
  }
1005
1005
  var FAILED_NODE_TTL_MS = 60 * 60 * 1e3;
1006
+ var MAX_PROXY_CACHE_AGE_MS = 60 * 60 * 1e3;
1006
1007
  function classifyAndCache(node, hostname, failedNodes, cachePath) {
1007
1008
  if (!node) {
1008
1009
  return { mode: null, node: null };
@@ -1036,6 +1037,10 @@ function resolvePilot(hostname, cachePath) {
1036
1037
  return { mode: "direct", node: null };
1037
1038
  }
1038
1039
  if (entry.mode === "proxy" && entry.node) {
1040
+ const effectiveTtlMs = Math.min(entry.node.ttl > 0 ? entry.node.ttl * 1e3 : MAX_PROXY_CACHE_AGE_MS, MAX_PROXY_CACHE_AGE_MS);
1041
+ if (Date.now() - entry.updatedAt > effectiveTtlMs) {
1042
+ return { mode: null, node: null };
1043
+ }
1039
1044
  return { mode: "proxy", node: entry.node };
1040
1045
  }
1041
1046
  }
@@ -1555,6 +1560,14 @@ var OKX_CODE_BEHAVIORS = {
1555
1560
  "51022": { retry: false, suggestion: "Instrument not available for trading." },
1556
1561
  "51027": { retry: false, suggestion: "Contract has expired." }
1557
1562
  };
1563
+ function hasOkxJsonCode(text) {
1564
+ try {
1565
+ const parsed = JSON.parse(text);
1566
+ return typeof parsed.code === "string" && parsed.code.length > 0;
1567
+ } catch {
1568
+ return false;
1569
+ }
1570
+ }
1558
1571
  function isDefined(value) {
1559
1572
  return value !== void 0 && value !== null;
1560
1573
  }
@@ -2032,6 +2045,12 @@ var OkxRestClient = class _OkxRestClient {
2032
2045
  const rawText = await response.text();
2033
2046
  const elapsed = Date.now() - t0;
2034
2047
  const traceId = extractTraceId(response.headers);
2048
+ if (this.pilot.isProxyActive && !response.ok && !hasOkxJsonCode(rawText) && !this.pilot.hasRetried) {
2049
+ const shouldRetry = await this.pilot.handleNetworkFailure();
2050
+ if (shouldRetry && (reqConfig.method === "GET" || reqConfig.retryOnNetworkError)) {
2051
+ return this.request(reqConfig);
2052
+ }
2053
+ }
2035
2054
  this.pilot.cacheDirectIfNeeded();
2036
2055
  return this.processResponse(rawText, response, elapsed, traceId, reqConfig, requestPath);
2037
2056
  }
@@ -2506,6 +2525,56 @@ function resolveIndicatorCode(name) {
2506
2525
  const lower = name.toLowerCase();
2507
2526
  return INDICATOR_CODE_OVERRIDES[lower] ?? name.toUpperCase().replace(/-/g, "_");
2508
2527
  }
2528
+ var DEFAULT_INDICATOR_PARAMS = {
2529
+ // Moving Averages — PRD example default is [14]
2530
+ ma: [14],
2531
+ ema: [14],
2532
+ wma: [14],
2533
+ dema: [14],
2534
+ tema: [14],
2535
+ zlema: [14],
2536
+ hma: [14],
2537
+ kama: [14],
2538
+ // Trend
2539
+ macd: [12, 26, 9],
2540
+ adx: [14],
2541
+ aroon: [14],
2542
+ cci: [20],
2543
+ dpo: [20],
2544
+ // Momentum
2545
+ rsi: [14],
2546
+ "stoch-rsi": [14],
2547
+ stoch: [14, 3, 3],
2548
+ roc: [12],
2549
+ mom: [10],
2550
+ ppo: [12, 26, 9],
2551
+ trix: [15],
2552
+ uo: [7, 14, 28],
2553
+ wr: [14],
2554
+ // Volatility
2555
+ bb: [20, 2],
2556
+ bbwidth: [20, 2],
2557
+ bbpct: [20, 2],
2558
+ atr: [14],
2559
+ keltner: [20, 2],
2560
+ donchian: [20],
2561
+ hv: [20],
2562
+ stddev: [20],
2563
+ // Volume
2564
+ mvwap: [20],
2565
+ cmf: [20],
2566
+ mfi: [14],
2567
+ // Custom
2568
+ kdj: [9, 3, 3],
2569
+ supertrend: [10, 3]
2570
+ };
2571
+ function getDefaultIndicatorParams(name) {
2572
+ const lower = name.toLowerCase();
2573
+ const direct = DEFAULT_INDICATOR_PARAMS[lower];
2574
+ if (direct !== void 0) return direct;
2575
+ const code = resolveIndicatorCode(lower);
2576
+ return DEFAULT_INDICATOR_PARAMS[code.toLowerCase()];
2577
+ }
2509
2578
  function validateIndicatorName(name) {
2510
2579
  const lower = name.toLowerCase();
2511
2580
  if (VALID_INDICATOR_NAMES.has(lower)) return;
@@ -2549,7 +2618,7 @@ function registerIndicatorTools() {
2549
2618
  params: {
2550
2619
  type: "array",
2551
2620
  items: { type: "number" },
2552
- description: "Indicator-specific parameters as a number array. Examples: MA/EMA [14] (period), MACD [12,26,9] (fast,slow,signal), BB [20,2] (period,stdDev), RSI [14] (period). Omit to use server defaults."
2621
+ description: "Indicator-specific parameters as a number array. Examples: MA/EMA [14] (period), MACD [12,26,9] (fast,slow,signal), BB [20,2] (period,stdDev), RSI [14] (period). For period-based indicators a parameter is required; the CLI applies a sensible default when omitted."
2553
2622
  },
2554
2623
  returnList: {
2555
2624
  type: "boolean",
@@ -14671,7 +14740,7 @@ async function cmdDiagnoseMcp(options = {}) {
14671
14740
 
14672
14741
  // src/commands/diagnose.ts
14673
14742
  var CLI_VERSION = readCliVersion();
14674
- var GIT_HASH = true ? "9beb3ee8" : "dev";
14743
+ var GIT_HASH = true ? "884b3632" : "dev";
14675
14744
  function maskKey2(key) {
14676
14745
  if (!key) return "(not set)";
14677
14746
  if (key.length <= 8) return "****";
@@ -17085,6 +17154,7 @@ function parseCli(argv) {
17085
17154
  }
17086
17155
 
17087
17156
  // src/commands/market.ts
17157
+ var NO_INDICATOR_VALUES_HINT = "No indicator values returned. This indicator may require a period \u2014 try --params (e.g. --params 14).";
17088
17158
  function getData2(result) {
17089
17159
  return result.data;
17090
17160
  }
@@ -17291,11 +17361,13 @@ function cmdMarketIndicatorList(json) {
17291
17361
  }
17292
17362
  async function cmdMarketIndicator(run, indicator, instId, opts) {
17293
17363
  const params = opts.params ? opts.params.split(",").map((p) => Number(p.trim())).filter((n) => !Number.isNaN(n)) : void 0;
17364
+ const explicit = params && params.length > 0 ? params : void 0;
17365
+ const effectiveParams = explicit ?? getDefaultIndicatorParams(indicator);
17294
17366
  const result = await run("market_get_indicator", {
17295
17367
  instId,
17296
17368
  indicator,
17297
17369
  bar: opts.bar,
17298
- params: params && params.length > 0 ? params : void 0,
17370
+ params: effectiveParams,
17299
17371
  returnList: opts.list ?? false,
17300
17372
  limit: opts.limit,
17301
17373
  backtestTime: opts.backtestTime
@@ -17303,7 +17375,7 @@ async function cmdMarketIndicator(run, indicator, instId, opts) {
17303
17375
  const outerArray = getData2(result);
17304
17376
  if (opts.json) return printJson(outerArray);
17305
17377
  if (!outerArray?.length) {
17306
- process.stdout.write("No data\n");
17378
+ outputLine("No data");
17307
17379
  return;
17308
17380
  }
17309
17381
  const apiCode = resolveIndicatorCode(indicator);
@@ -17312,16 +17384,18 @@ async function cmdMarketIndicator(run, indicator, instId, opts) {
17312
17384
  const instData = innerArray?.[0];
17313
17385
  const timeframes = instData?.["timeframes"];
17314
17386
  if (!timeframes) {
17315
- process.stdout.write(JSON.stringify(outerArray, null, 2) + "\n");
17387
+ output(JSON.stringify(outerArray, null, 2) + "\n");
17316
17388
  return;
17317
17389
  }
17390
+ let printed = false;
17318
17391
  for (const [tf, tfData] of Object.entries(timeframes)) {
17319
17392
  const indicators = tfData?.["indicators"];
17320
17393
  const values = indicators?.[apiCode];
17321
17394
  if (!values?.length) continue;
17322
- process.stdout.write(`${instId} | ${apiCode} | ${tf}
17395
+ printed = true;
17396
+ output(`${instId} | ${apiCode} | ${tf}
17323
17397
  `);
17324
- process.stdout.write("-".repeat(40) + "\n");
17398
+ output("-".repeat(40) + "\n");
17325
17399
  if (opts.list) {
17326
17400
  const tableRows = values.map((entry) => ({
17327
17401
  ts: new Date(Number(entry["ts"])).toLocaleString(),
@@ -17336,6 +17410,7 @@ async function cmdMarketIndicator(run, indicator, instId, opts) {
17336
17410
  });
17337
17411
  }
17338
17412
  }
17413
+ if (!printed) outputLine(NO_INDICATOR_VALUES_HINT);
17339
17414
  }
17340
17415
  async function cmdMarketInstrumentsByCategory(run, opts) {
17341
17416
  const result = await run("market_get_instruments_by_category", {
@@ -17409,8 +17484,9 @@ async function cmdMarketFilter(run, opts) {
17409
17484
  sortOrder: opts.sortOrder,
17410
17485
  limit: opts.limit
17411
17486
  });
17412
- const data = getData2(result);
17413
- if (opts.json) return printJson(data);
17487
+ const raw = getData2(result);
17488
+ if (opts.json) return printJson(raw);
17489
+ const data = Array.isArray(raw) ? raw[0] : raw;
17414
17490
  const rows = data?.["rows"] ?? [];
17415
17491
  const total = data?.["total"] ?? rows.length;
17416
17492
  outputLine(`Total: ${total}`);
@@ -21467,7 +21543,7 @@ async function cmdEventCancel(run, opts) {
21467
21543
  // src/index.ts
21468
21544
  var _require3 = createRequire3(import.meta.url);
21469
21545
  var CLI_VERSION2 = _require3("../package.json").version;
21470
- var GIT_HASH2 = true ? "9beb3ee8" : "dev";
21546
+ var GIT_HASH2 = true ? "884b3632" : "dev";
21471
21547
  function handlePilotCommand(action, json, force, binaryPath) {
21472
21548
  if (action === "status") return cmdPilotStatus(json, binaryPath);
21473
21549
  if (action === "install") return cmdPilotInstall(json, binaryPath);