@okx_ai/okx-trade-cli 1.2.8-beta.2 → 1.2.8-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
@@ -1095,13 +1095,14 @@ var OkxRestClient = class {
1095
1095
  rateLimit
1096
1096
  });
1097
1097
  }
1098
- async privateGet(path42, query, rateLimit) {
1098
+ async privateGet(path42, query, rateLimit, extraHeaders) {
1099
1099
  return this.request({
1100
1100
  method: "GET",
1101
1101
  path: path42,
1102
1102
  auth: "private",
1103
1103
  query,
1104
- rateLimit
1104
+ rateLimit,
1105
+ extraHeaders
1105
1106
  });
1106
1107
  }
1107
1108
  async publicPost(path42, body, rateLimit) {
@@ -1213,16 +1214,7 @@ var OkxRestClient = class {
1213
1214
  raw: parsed
1214
1215
  };
1215
1216
  }
1216
- async request(reqConfig) {
1217
- const queryString = buildQueryString(reqConfig.query);
1218
- const requestPath = queryString.length > 0 ? `${reqConfig.path}?${queryString}` : reqConfig.path;
1219
- const url = `${this.config.baseUrl}${requestPath}`;
1220
- const bodyJson = reqConfig.body ? JSON.stringify(reqConfig.body) : "";
1221
- const timestamp = getNow();
1222
- this.logRequest(reqConfig.method, url, reqConfig.auth);
1223
- if (reqConfig.rateLimit) {
1224
- await this.rateLimiter.consume(reqConfig.rateLimit);
1225
- }
1217
+ buildHeaders(reqConfig, requestPath, bodyJson, timestamp) {
1226
1218
  const headers = new Headers({
1227
1219
  "Content-Type": "application/json",
1228
1220
  Accept: "application/json"
@@ -1236,6 +1228,24 @@ var OkxRestClient = class {
1236
1228
  if (this.config.demo) {
1237
1229
  headers.set("x-simulated-trading", "1");
1238
1230
  }
1231
+ if (reqConfig.extraHeaders) {
1232
+ for (const [key, value] of Object.entries(reqConfig.extraHeaders)) {
1233
+ headers.set(key, value);
1234
+ }
1235
+ }
1236
+ return headers;
1237
+ }
1238
+ async request(reqConfig) {
1239
+ const queryString = buildQueryString(reqConfig.query);
1240
+ const requestPath = queryString.length > 0 ? `${reqConfig.path}?${queryString}` : reqConfig.path;
1241
+ const url = `${this.config.baseUrl}${requestPath}`;
1242
+ const bodyJson = reqConfig.body ? JSON.stringify(reqConfig.body) : "";
1243
+ const timestamp = getNow();
1244
+ this.logRequest(reqConfig.method, url, reqConfig.auth);
1245
+ if (reqConfig.rateLimit) {
1246
+ await this.rateLimiter.consume(reqConfig.rateLimit);
1247
+ }
1248
+ const headers = this.buildHeaders(reqConfig, requestPath, bodyJson, timestamp);
1239
1249
  const t0 = Date.now();
1240
1250
  let response;
1241
1251
  try {
@@ -1534,6 +1544,7 @@ var MODULES = [
1534
1544
  "futures",
1535
1545
  "option",
1536
1546
  "account",
1547
+ "news",
1537
1548
  ...EARN_SUB_MODULE_IDS,
1538
1549
  ...BOT_SUB_MODULE_IDS
1539
1550
  ];
@@ -5319,6 +5330,304 @@ function registerMarketTools() {
5319
5330
  }
5320
5331
  ];
5321
5332
  }
5333
+ var NEWS_SEARCH = "/api/v5/orbit/news-search";
5334
+ var NEWS_DETAIL = "/api/v5/orbit/news-detail";
5335
+ var NEWS_DOMAINS = "/api/v5/orbit/news-platform";
5336
+ var SENTIMENT_QUERY = "/api/v5/orbit/currency-sentiment-query";
5337
+ var SENTIMENT_RANKING = "/api/v5/orbit/currency-sentiment-ranking";
5338
+ var NEWS_LANGUAGE = ["en_US", "zh_CN"];
5339
+ function langHeader(lang) {
5340
+ if (lang === "zh_CN" || lang === "en_US") return { "Accept-Language": lang };
5341
+ return void 0;
5342
+ }
5343
+ var NEWS_DETAIL_LVL = ["brief", "summary", "full"];
5344
+ var NEWS_IMPORTANCE = ["high", "medium", "low"];
5345
+ var NEWS_SENTIMENT = ["bullish", "bearish", "neutral"];
5346
+ var NEWS_SORT = ["latest", "relevant"];
5347
+ var SENTIMENT_PERIOD = ["1h", "4h", "24h"];
5348
+ var D_COINS_NEWS = 'Comma-separated uppercase ticker symbols (e.g. "BTC,ETH"). Normalize names/aliases to standard tickers.';
5349
+ var D_COINS_SENTIMENT = 'Comma-separated uppercase ticker symbols, max 20 (e.g. "BTC,ETH"). Normalize names/aliases to standard tickers.';
5350
+ var D_LANGUAGE = "Content language: zh_CN or en_US. Infer from user's message. No server default.";
5351
+ var D_BEGIN = "Start time, Unix epoch milliseconds. Parse relative time if given (e.g. 'yesterday', 'last 7 days').";
5352
+ var D_END = "End time, Unix epoch milliseconds. Parse relative time if given. Omit for no upper bound.";
5353
+ var D_IMPORTANCE = "Importance filter: high (server default), medium, low. Omit unless user wants broader coverage.";
5354
+ var D_LIMIT = "Number of results (default 10, max 50).";
5355
+ function registerNewsTools() {
5356
+ return [
5357
+ // -----------------------------------------------------------------------
5358
+ // News browsing tools
5359
+ // -----------------------------------------------------------------------
5360
+ {
5361
+ name: "news_get_latest",
5362
+ module: "news",
5363
+ description: "Get crypto news sorted by time. Omitting importance still returns only high-importance news (server default). Pass importance='medium' or 'low' explicitly to broaden results. Use when user asks 'what happened recently', 'latest news', 'any big news today', or wants to browse without a keyword.",
5364
+ isWrite: false,
5365
+ inputSchema: {
5366
+ type: "object",
5367
+ properties: {
5368
+ coins: { type: "string", description: D_COINS_NEWS + " Optional." },
5369
+ importance: { type: "string", enum: [...NEWS_IMPORTANCE], description: D_IMPORTANCE },
5370
+ begin: { type: "number", description: D_BEGIN },
5371
+ end: { type: "number", description: D_END },
5372
+ language: { type: "string", enum: [...NEWS_LANGUAGE], description: D_LANGUAGE },
5373
+ detailLvl: {
5374
+ type: "string",
5375
+ enum: [...NEWS_DETAIL_LVL],
5376
+ description: "Content level: summary (AI summary, default), full (original text), brief (title only)."
5377
+ },
5378
+ limit: { type: "number", description: D_LIMIT },
5379
+ after: { type: "string", description: "Pagination cursor from previous response nextCursor." }
5380
+ },
5381
+ required: []
5382
+ },
5383
+ handler: async (rawArgs, context) => {
5384
+ const args = asRecord(rawArgs);
5385
+ const response = await context.client.privateGet(
5386
+ NEWS_SEARCH,
5387
+ compactObject({
5388
+ sortBy: "latest",
5389
+ importance: readString(args, "importance"),
5390
+ ccyList: readString(args, "coins"),
5391
+ begin: readNumber(args, "begin"),
5392
+ end: readNumber(args, "end"),
5393
+ detailLvl: readString(args, "detailLvl"),
5394
+ limit: readNumber(args, "limit") ?? 10,
5395
+ cursor: readString(args, "after")
5396
+ }),
5397
+ publicRateLimit("news_get_latest", 20),
5398
+ langHeader(readString(args, "language"))
5399
+ );
5400
+ return normalizeResponse(response);
5401
+ }
5402
+ },
5403
+ {
5404
+ name: "news_get_by_coin",
5405
+ module: "news",
5406
+ description: "Get news for specific coins or tokens. Use when user mentions a coin: 'BTC news', 'any SOL updates'. Supports multiple coins (comma-separated).",
5407
+ isWrite: false,
5408
+ inputSchema: {
5409
+ type: "object",
5410
+ properties: {
5411
+ coins: { type: "string", description: D_COINS_NEWS + " Required." },
5412
+ importance: { type: "string", enum: [...NEWS_IMPORTANCE], description: D_IMPORTANCE },
5413
+ begin: { type: "number", description: D_BEGIN },
5414
+ end: { type: "number", description: D_END },
5415
+ language: { type: "string", enum: [...NEWS_LANGUAGE], description: D_LANGUAGE },
5416
+ detailLvl: { type: "string", enum: [...NEWS_DETAIL_LVL] },
5417
+ limit: { type: "number", description: D_LIMIT }
5418
+ },
5419
+ required: ["coins"]
5420
+ },
5421
+ handler: async (rawArgs, context) => {
5422
+ const args = asRecord(rawArgs);
5423
+ const coins = readString(args, "coins");
5424
+ if (!coins) {
5425
+ throw new Error(`Missing required parameter "coins".`);
5426
+ }
5427
+ const response = await context.client.privateGet(
5428
+ NEWS_SEARCH,
5429
+ compactObject({
5430
+ sortBy: "latest",
5431
+ ccyList: coins,
5432
+ importance: readString(args, "importance"),
5433
+ begin: readNumber(args, "begin"),
5434
+ end: readNumber(args, "end"),
5435
+ detailLvl: readString(args, "detailLvl"),
5436
+ limit: readNumber(args, "limit") ?? 10
5437
+ }),
5438
+ publicRateLimit("news_get_by_coin", 20),
5439
+ langHeader(readString(args, "language"))
5440
+ );
5441
+ return normalizeResponse(response);
5442
+ }
5443
+ },
5444
+ {
5445
+ name: "news_search",
5446
+ module: "news",
5447
+ description: "Search crypto news by keyword with optional filters. Use when user provides specific search terms: 'SEC ETF news', 'stablecoin regulation', 'Bitcoin halving'. For coin-only queries prefer news_get_by_coin.",
5448
+ isWrite: false,
5449
+ inputSchema: {
5450
+ type: "object",
5451
+ properties: {
5452
+ keyword: {
5453
+ type: "string",
5454
+ description: "Search keyword(s) extracted from user query (topic/entity). Multiple words are AND-combined. Omit to browse by filters only."
5455
+ },
5456
+ coins: { type: "string", description: D_COINS_NEWS + " Optional." },
5457
+ importance: { type: "string", enum: [...NEWS_IMPORTANCE], description: D_IMPORTANCE },
5458
+ sentiment: {
5459
+ type: "string",
5460
+ enum: [...NEWS_SENTIMENT],
5461
+ description: "Filter by sentiment if mentioned alongside the keyword."
5462
+ },
5463
+ sortBy: {
5464
+ type: "string",
5465
+ enum: [...NEWS_SORT],
5466
+ description: "Sort order: relevant (by relevance, default for keyword search), latest (by time)."
5467
+ },
5468
+ begin: { type: "number", description: D_BEGIN },
5469
+ end: { type: "number", description: D_END },
5470
+ language: { type: "string", enum: [...NEWS_LANGUAGE], description: D_LANGUAGE },
5471
+ detailLvl: { type: "string", enum: [...NEWS_DETAIL_LVL] },
5472
+ limit: { type: "number", description: D_LIMIT },
5473
+ after: { type: "string", description: "Pagination cursor from previous response nextCursor." }
5474
+ },
5475
+ required: []
5476
+ },
5477
+ handler: async (rawArgs, context) => {
5478
+ const args = asRecord(rawArgs);
5479
+ const response = await context.client.privateGet(
5480
+ NEWS_SEARCH,
5481
+ compactObject({
5482
+ keyword: readString(args, "keyword") || void 0,
5483
+ sortBy: readString(args, "sortBy") ?? "relevant",
5484
+ importance: readString(args, "importance"),
5485
+ ccyList: readString(args, "coins"),
5486
+ sentiment: readString(args, "sentiment"),
5487
+ begin: readNumber(args, "begin"),
5488
+ end: readNumber(args, "end"),
5489
+ detailLvl: readString(args, "detailLvl"),
5490
+ limit: readNumber(args, "limit") ?? 10,
5491
+ cursor: readString(args, "after")
5492
+ }),
5493
+ publicRateLimit("news_search", 20),
5494
+ langHeader(readString(args, "language"))
5495
+ );
5496
+ return normalizeResponse(response);
5497
+ }
5498
+ },
5499
+ {
5500
+ name: "news_get_detail",
5501
+ module: "news",
5502
+ description: "Get full article content by news ID (returns title + summary + full original text). Use when user says 'show full article', 'read more', or provides a specific news ID from a previous result.",
5503
+ isWrite: false,
5504
+ inputSchema: {
5505
+ type: "object",
5506
+ properties: {
5507
+ id: {
5508
+ type: "string",
5509
+ description: "News article ID from a previous news_get_latest / news_get_by_coin / news_search result. Required."
5510
+ },
5511
+ language: { type: "string", enum: [...NEWS_LANGUAGE], description: D_LANGUAGE }
5512
+ },
5513
+ required: ["id"]
5514
+ },
5515
+ handler: async (rawArgs, context) => {
5516
+ const args = asRecord(rawArgs);
5517
+ const id = readString(args, "id");
5518
+ if (!id) {
5519
+ throw new Error(`Missing required parameter "id".`);
5520
+ }
5521
+ const response = await context.client.privateGet(
5522
+ NEWS_DETAIL,
5523
+ { id },
5524
+ publicRateLimit("news_get_detail", 20),
5525
+ langHeader(readString(args, "language"))
5526
+ );
5527
+ return normalizeResponse(response);
5528
+ }
5529
+ },
5530
+ {
5531
+ name: "news_get_domains",
5532
+ module: "news",
5533
+ description: "List available news source domains (e.g. coindesk, cointelegraph). Use when user asks what news sources are available or which platforms are covered.",
5534
+ isWrite: false,
5535
+ inputSchema: {
5536
+ type: "object",
5537
+ properties: {},
5538
+ required: []
5539
+ },
5540
+ handler: async (_rawArgs, context) => {
5541
+ const response = await context.client.privateGet(
5542
+ NEWS_DOMAINS,
5543
+ {},
5544
+ publicRateLimit("news_get_domains", 20)
5545
+ );
5546
+ return normalizeResponse(response);
5547
+ }
5548
+ },
5549
+ // -----------------------------------------------------------------------
5550
+ // Token sentiment tools
5551
+ // -----------------------------------------------------------------------
5552
+ {
5553
+ name: "news_get_coin_sentiment",
5554
+ module: "news",
5555
+ description: "Get sentiment snapshot or time-series trend for coins. Returns bullish/bearish ratios and mention counts. Pass trendPoints for trend data (1h\u219224 points, 4h\u21926, 24h\u21927). Use when user asks about coin sentiment, sentiment trend, or how bullish/bearish a coin is.",
5556
+ isWrite: false,
5557
+ inputSchema: {
5558
+ type: "object",
5559
+ properties: {
5560
+ coins: { type: "string", description: D_COINS_SENTIMENT + " Required." },
5561
+ period: {
5562
+ type: "string",
5563
+ enum: [...SENTIMENT_PERIOD],
5564
+ description: "Aggregation granularity: 1h, 4h, 24h. Snapshot default: 24h. Trend default: 1h."
5565
+ },
5566
+ trendPoints: {
5567
+ type: "number",
5568
+ description: "Trend data points. Pass for time-series trend; omit for snapshot. Guide: 1h\u219224, 4h\u21926, 24h\u21927."
5569
+ }
5570
+ },
5571
+ required: ["coins"]
5572
+ },
5573
+ handler: async (rawArgs, context) => {
5574
+ const args = asRecord(rawArgs);
5575
+ const coins = readString(args, "coins");
5576
+ if (!coins) {
5577
+ throw new Error(`Missing required parameter "coins".`);
5578
+ }
5579
+ const trendPoints = readNumber(args, "trendPoints");
5580
+ const inclTrend = trendPoints !== void 0;
5581
+ const response = await context.client.privateGet(
5582
+ SENTIMENT_QUERY,
5583
+ compactObject({
5584
+ ccy: coins,
5585
+ period: readString(args, "period") ?? (inclTrend ? "1h" : "24h"),
5586
+ ...inclTrend ? { inclTrend: true, limit: trendPoints } : {}
5587
+ }),
5588
+ publicRateLimit("news_get_coin_sentiment", 20)
5589
+ );
5590
+ return normalizeResponse(response);
5591
+ }
5592
+ },
5593
+ {
5594
+ name: "news_get_sentiment_ranking",
5595
+ module: "news",
5596
+ description: "Get coin ranking by social hotness or sentiment direction. Use when user asks which coins are trending, most bullish/bearish coins. Sort by hot (mention count), bullish, or bearish.",
5597
+ isWrite: false,
5598
+ inputSchema: {
5599
+ type: "object",
5600
+ properties: {
5601
+ period: {
5602
+ type: "string",
5603
+ enum: [...SENTIMENT_PERIOD],
5604
+ description: "Aggregation granularity: 1h, 4h, 24h (default)."
5605
+ },
5606
+ sortBy: {
5607
+ type: "string",
5608
+ enum: ["hot", "bullish", "bearish"],
5609
+ description: "Sort: hot=by mentions (default), bullish=most bullish, bearish=most bearish."
5610
+ },
5611
+ limit: { type: "number", description: D_LIMIT }
5612
+ },
5613
+ required: []
5614
+ },
5615
+ handler: async (rawArgs, context) => {
5616
+ const args = asRecord(rawArgs);
5617
+ const response = await context.client.privateGet(
5618
+ SENTIMENT_RANKING,
5619
+ compactObject({
5620
+ period: readString(args, "period") ?? "24h",
5621
+ sortBy: readString(args, "sortBy") ?? "hot",
5622
+ limit: readNumber(args, "limit") ?? 10
5623
+ }),
5624
+ publicRateLimit("news_get_sentiment_ranking", 20)
5625
+ );
5626
+ return normalizeResponse(response);
5627
+ }
5628
+ }
5629
+ ];
5630
+ }
5322
5631
  function registerOptionAlgoTools() {
5323
5632
  return [
5324
5633
  {
@@ -6792,6 +7101,7 @@ function allToolSpecs() {
6792
7101
  ...registerOptionAlgoTools(),
6793
7102
  ...registerAlgoTradeTools(),
6794
7103
  ...registerAccountTools(),
7104
+ ...registerNewsTools(),
6795
7105
  ...registerBotTools(),
6796
7106
  ...registerAllEarnTools(),
6797
7107
  ...registerAuditTools()
@@ -6915,10 +7225,21 @@ function resolveBaseUrl(site, tomlBaseUrl) {
6915
7225
  }
6916
7226
  return rawBaseUrl.replace(/\/+$/, "");
6917
7227
  }
7228
+ function resolveDemo(cli, toml) {
7229
+ if (cli.demo && cli.live) {
7230
+ throw new ConfigError(
7231
+ "--demo and --live are mutually exclusive.",
7232
+ "Use --demo for simulated trading or --live to force live mode, not both."
7233
+ );
7234
+ }
7235
+ if (cli.live === true) return false;
7236
+ if (cli.demo === true) return true;
7237
+ return process.env.OKX_DEMO === "1" || process.env.OKX_DEMO === "true" || (toml.demo ?? false);
7238
+ }
6918
7239
  function loadConfig(cli) {
6919
7240
  const toml = readTomlProfile(cli.profile);
6920
7241
  const creds = loadCredentials(toml);
6921
- const demo = cli.demo || process.env.OKX_DEMO === "1" || process.env.OKX_DEMO === "true" || (toml.demo ?? false);
7242
+ const demo = resolveDemo(cli, toml);
6922
7243
  const site = resolveSite(cli.site, toml.site);
6923
7244
  const baseUrl = resolveBaseUrl(site, toml.base_url);
6924
7245
  const rawTimeout = process.env.OKX_TIMEOUT_MS ? Number(process.env.OKX_TIMEOUT_MS) : toml.timeout_ms ?? 15e3;
@@ -6975,6 +7296,22 @@ function isNewerVersion(current, latest) {
6975
7296
  if (lMin !== cMin) return lMin > cMin;
6976
7297
  return lPat > cPat;
6977
7298
  }
7299
+ async function fetchDistTags(packageName) {
7300
+ try {
7301
+ const controller = new AbortController();
7302
+ const timeout = setTimeout(() => controller.abort(), 3e3);
7303
+ const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(packageName)}`, {
7304
+ signal: controller.signal,
7305
+ headers: { accept: "application/json" }
7306
+ });
7307
+ clearTimeout(timeout);
7308
+ if (!res.ok) return null;
7309
+ const data = await res.json();
7310
+ return data["dist-tags"] ?? null;
7311
+ } catch {
7312
+ return null;
7313
+ }
7314
+ }
6978
7315
  async function fetchLatestVersion(packageName) {
6979
7316
  try {
6980
7317
  const controller = new AbortController();
@@ -7776,7 +8113,7 @@ async function cmdDiagnoseMcp(options = {}) {
7776
8113
 
7777
8114
  // src/commands/diagnose.ts
7778
8115
  var CLI_VERSION = readCliVersion();
7779
- var GIT_HASH = true ? "f9ea608" : "dev";
8116
+ var GIT_HASH = true ? "7b97fe6" : "dev";
7780
8117
  function maskKey2(key) {
7781
8118
  if (!key) return "(not set)";
7782
8119
  if (key.length <= 8) return "****";
@@ -8071,13 +8408,329 @@ async function runCliChecks(config, profile, outputPath) {
8071
8408
  writeReportIfRequested(report, outputPath);
8072
8409
  }
8073
8410
 
8411
+ // src/commands/upgrade.ts
8412
+ import { spawnSync as spawnSync2 } from "child_process";
8413
+ import { readFileSync as readFileSync4, writeFileSync as writeFileSync4, mkdirSync as mkdirSync4 } from "fs";
8414
+ import { dirname as dirname3, join as join4 } from "path";
8415
+ import { homedir as homedir4 } from "os";
8416
+ var PACKAGES = ["@okx_ai/okx-trade-mcp", "@okx_ai/okx-trade-cli"];
8417
+ var CACHE_FILE2 = join4(homedir4(), ".okx", "last_check");
8418
+ var THROTTLE_MS = 12 * 60 * 60 * 1e3;
8419
+ var NPM_BIN = join4(dirname3(process.execPath), process.platform === "win32" ? "npm.cmd" : "npm");
8420
+ function readLastCheck() {
8421
+ try {
8422
+ return parseInt(readFileSync4(CACHE_FILE2, "utf-8").trim(), 10) || 0;
8423
+ } catch {
8424
+ return 0;
8425
+ }
8426
+ }
8427
+ function writeLastCheck() {
8428
+ try {
8429
+ mkdirSync4(join4(homedir4(), ".okx"), { recursive: true });
8430
+ writeFileSync4(CACHE_FILE2, String(Math.floor(Date.now() / 1e3)), "utf-8");
8431
+ } catch {
8432
+ }
8433
+ }
8434
+ function printResult(result, json) {
8435
+ if (json) {
8436
+ process.stdout.write(JSON.stringify(result) + "\n");
8437
+ } else {
8438
+ switch (result.status) {
8439
+ case "up-to-date":
8440
+ process.stderr.write(`[ok] Already up to date: ${result.currentVersion}
8441
+ `);
8442
+ break;
8443
+ case "update-available":
8444
+ process.stderr.write(
8445
+ `[info] Update available: ${result.currentVersion} \u2192 ${result.latestVersion}
8446
+ Run: okx upgrade
8447
+ `
8448
+ );
8449
+ break;
8450
+ case "updated":
8451
+ process.stderr.write(`[ok] Upgraded: ${result.currentVersion} \u2192 ${result.latestVersion}
8452
+ `);
8453
+ break;
8454
+ case "error":
8455
+ process.stderr.write(`[error] Failed to fetch latest version from npm registry
8456
+ `);
8457
+ break;
8458
+ }
8459
+ }
8460
+ }
8461
+ function isThrottled(options) {
8462
+ if (options.force || options.check) return false;
8463
+ return Date.now() - readLastCheck() * 1e3 < THROTTLE_MS;
8464
+ }
8465
+ async function resolveLatestVersion(beta) {
8466
+ if (beta) {
8467
+ const tags = await fetchDistTags("@okx_ai/okx-trade-cli");
8468
+ return tags?.["next"] ?? tags?.["latest"] ?? null;
8469
+ }
8470
+ return fetchLatestVersion("@okx_ai/okx-trade-cli");
8471
+ }
8472
+ function runNpmInstall(json) {
8473
+ const result = spawnSync2(NPM_BIN, ["install", "-g", ...PACKAGES], {
8474
+ stdio: json ? ["inherit", "ignore", process.stderr] : "inherit",
8475
+ shell: false
8476
+ });
8477
+ return result.status === 0;
8478
+ }
8479
+ async function cmdUpgrade(currentVersion, options, json) {
8480
+ if (isThrottled(options)) {
8481
+ if (json) {
8482
+ process.stdout.write(
8483
+ JSON.stringify({ currentVersion, latestVersion: currentVersion, status: "up-to-date", updated: false }) + "\n"
8484
+ );
8485
+ }
8486
+ return;
8487
+ }
8488
+ const latestVersion = await resolveLatestVersion(options.beta ?? false);
8489
+ if (!latestVersion) {
8490
+ printResult({ currentVersion, latestVersion: "unknown", status: "error", updated: false }, json);
8491
+ process.exitCode = 1;
8492
+ return;
8493
+ }
8494
+ const stableCurrentVersion = currentVersion.split(/[-+]/)[0] ?? currentVersion;
8495
+ const needsUpdate = options.force || isNewerVersion(stableCurrentVersion, latestVersion);
8496
+ if (!needsUpdate) {
8497
+ if (!options.check) writeLastCheck();
8498
+ printResult({ currentVersion, latestVersion, status: "up-to-date", updated: false }, json);
8499
+ return;
8500
+ }
8501
+ if (options.check) {
8502
+ printResult({ currentVersion, latestVersion, status: "update-available", updated: false }, json);
8503
+ return;
8504
+ }
8505
+ if (runNpmInstall(json)) {
8506
+ writeLastCheck();
8507
+ printResult({ currentVersion, latestVersion, status: "updated", updated: true }, json);
8508
+ } else {
8509
+ printResult({ currentVersion, latestVersion, status: "error", updated: false }, json);
8510
+ process.exitCode = 1;
8511
+ }
8512
+ }
8513
+
8514
+ // src/commands/news.ts
8515
+ function getData(result) {
8516
+ return result.data;
8517
+ }
8518
+ function formatTime(ts) {
8519
+ if (!ts) return "-";
8520
+ return new Date(Number(ts)).toLocaleString();
8521
+ }
8522
+ async function cmdNewsLatest(run, opts) {
8523
+ const result = await run("news_get_latest", {
8524
+ coins: opts.coins,
8525
+ importance: opts.importance,
8526
+ begin: opts.begin,
8527
+ end: opts.end,
8528
+ language: opts.language,
8529
+ detailLvl: opts.detailLvl,
8530
+ limit: opts.limit,
8531
+ after: opts.after
8532
+ });
8533
+ const raw = getData(result);
8534
+ const pageData = raw?.[0];
8535
+ if (opts.json) return printJson(pageData ?? null);
8536
+ const items = pageData?.["details"] ?? [];
8537
+ printTable(
8538
+ items.map((n) => ({
8539
+ id: n["id"],
8540
+ time: formatTime(n["cTime"] ?? n["createTime"]),
8541
+ platforms: n["platformList"]?.join(",") ?? "-",
8542
+ title: String(n["title"] ?? "").slice(0, 80)
8543
+ }))
8544
+ );
8545
+ const cursor = pageData?.["nextCursor"];
8546
+ if (cursor) outputLine(`[next] --after ${cursor}`);
8547
+ }
8548
+ async function cmdNewsImportant(run, opts) {
8549
+ const result = await run("news_get_latest", {
8550
+ coins: opts.coins,
8551
+ importance: "high",
8552
+ begin: opts.begin,
8553
+ end: opts.end,
8554
+ language: opts.language,
8555
+ detailLvl: opts.detailLvl,
8556
+ limit: opts.limit
8557
+ });
8558
+ const raw = getData(result);
8559
+ const pageData = raw?.[0];
8560
+ if (opts.json) return printJson(pageData ?? null);
8561
+ const items = pageData?.["details"] ?? [];
8562
+ printTable(
8563
+ items.map((n) => ({
8564
+ id: n["id"],
8565
+ time: formatTime(n["cTime"] ?? n["createTime"]),
8566
+ importance: n["importance"] ?? "-",
8567
+ platforms: n["platformList"]?.join(",") ?? "-",
8568
+ title: String(n["title"] ?? "").slice(0, 80)
8569
+ }))
8570
+ );
8571
+ }
8572
+ async function cmdNewsByCoin(run, coins, opts) {
8573
+ const result = await run("news_get_by_coin", {
8574
+ coins,
8575
+ importance: opts.importance,
8576
+ begin: opts.begin,
8577
+ end: opts.end,
8578
+ language: opts.language,
8579
+ detailLvl: opts.detailLvl,
8580
+ limit: opts.limit
8581
+ });
8582
+ const raw = getData(result);
8583
+ const pageData = raw?.[0];
8584
+ if (opts.json) return printJson(pageData ?? null);
8585
+ const items = pageData?.["details"] ?? [];
8586
+ printTable(
8587
+ items.map((n) => ({
8588
+ id: n["id"],
8589
+ time: formatTime(n["cTime"] ?? n["createTime"]),
8590
+ coins: n["ccyList"]?.join(",") ?? "-",
8591
+ platforms: n["platformList"]?.join(",") ?? "-",
8592
+ title: String(n["title"] ?? "").slice(0, 80)
8593
+ }))
8594
+ );
8595
+ }
8596
+ async function cmdNewsSearch(run, keyword, opts) {
8597
+ const result = await run("news_search", {
8598
+ keyword: keyword || void 0,
8599
+ coins: opts.coins,
8600
+ importance: opts.importance,
8601
+ sentiment: opts.sentiment,
8602
+ sortBy: opts.sortBy,
8603
+ begin: opts.begin,
8604
+ end: opts.end,
8605
+ language: opts.language,
8606
+ detailLvl: opts.detailLvl,
8607
+ limit: opts.limit,
8608
+ after: opts.after
8609
+ });
8610
+ const raw = getData(result);
8611
+ const pageData = raw?.[0];
8612
+ if (opts.json) return printJson(pageData ?? null);
8613
+ const items = pageData?.["details"] ?? [];
8614
+ printTable(
8615
+ items.map((n) => ({
8616
+ id: n["id"],
8617
+ time: formatTime(n["cTime"] ?? n["createTime"]),
8618
+ platforms: n["platformList"]?.join(",") ?? "-",
8619
+ title: String(n["title"] ?? "").slice(0, 80)
8620
+ }))
8621
+ );
8622
+ const cursor = pageData?.["nextCursor"];
8623
+ if (cursor) outputLine(`[next] --after ${cursor}`);
8624
+ }
8625
+ async function cmdNewsDetail(run, id, opts) {
8626
+ const result = await run("news_get_detail", { id, language: opts.language });
8627
+ const items = getData(result);
8628
+ if (opts.json) return printJson(items);
8629
+ const article = items?.[0];
8630
+ if (!article) {
8631
+ outputLine("Article not found.");
8632
+ return;
8633
+ }
8634
+ const rawContent = article["content"] ? String(article["content"]) : void 0;
8635
+ const content = rawContent ? rawContent.length > 500 ? rawContent.slice(0, 500) + "... (use --json for full text)" : rawContent : void 0;
8636
+ printKv({
8637
+ id: article["id"],
8638
+ title: article["title"],
8639
+ platforms: article["platformList"]?.join(", ") ?? "-",
8640
+ time: formatTime(article["cTime"] ?? article["createTime"]),
8641
+ sourceUrl: article["sourceUrl"],
8642
+ coins: article["ccyList"]?.join(", ") ?? "-",
8643
+ importance: article["importance"] ?? "-",
8644
+ summary: article["summary"] ?? "(see content)",
8645
+ content
8646
+ });
8647
+ }
8648
+ async function cmdNewsDomains(run, opts) {
8649
+ const result = await run("news_get_domains", {});
8650
+ const raw = getData(result);
8651
+ const items = raw?.[0]?.["platform"] ?? [];
8652
+ if (opts.json) return printJson(items);
8653
+ outputLine("Available news source domains:");
8654
+ (items ?? []).forEach((d) => outputLine(` ${d}`));
8655
+ }
8656
+ async function cmdNewsCoinSentiment(run, coins, opts) {
8657
+ const result = await run("news_get_coin_sentiment", {
8658
+ coins,
8659
+ period: opts.period
8660
+ });
8661
+ const raw = getData(result);
8662
+ if (opts.json) return printJson(raw);
8663
+ const items = raw?.[0]?.["details"] ?? [];
8664
+ printTable(
8665
+ items.map((c) => {
8666
+ const snt = c["sentiment"];
8667
+ return {
8668
+ symbol: c["ccy"],
8669
+ label: snt?.["label"] ?? "-",
8670
+ bullish: snt?.["bullishRatio"] ?? "-",
8671
+ bearish: snt?.["bearishRatio"] ?? "-",
8672
+ mentions: c["mentionCnt"]
8673
+ };
8674
+ })
8675
+ );
8676
+ }
8677
+ async function cmdNewsCoinTrend(run, coin, opts) {
8678
+ const result = await run("news_get_coin_sentiment", {
8679
+ coins: coin,
8680
+ period: opts.period,
8681
+ trendPoints: opts.points
8682
+ });
8683
+ const raw = getData(result);
8684
+ if (opts.json) return printJson(raw);
8685
+ const items = raw?.[0]?.["details"] ?? [];
8686
+ const coinData = items?.[0];
8687
+ if (!coinData) {
8688
+ outputLine("No trend data.");
8689
+ return;
8690
+ }
8691
+ const trend = coinData["trend"] ?? [];
8692
+ outputLine(`Sentiment trend for ${coin} (period: ${opts.period ?? "1h"}):`);
8693
+ printTable(
8694
+ trend.map((t) => ({
8695
+ time: formatTime(t["ts"]),
8696
+ bullish: t["bullishRatio"],
8697
+ bearish: t["bearishRatio"],
8698
+ mentions: t["mentionCnt"]
8699
+ }))
8700
+ );
8701
+ }
8702
+ async function cmdNewsSentimentRank(run, opts) {
8703
+ const result = await run("news_get_sentiment_ranking", {
8704
+ period: opts.period,
8705
+ sortBy: opts.sortBy,
8706
+ limit: opts.limit
8707
+ });
8708
+ const raw = getData(result);
8709
+ if (opts.json) return printJson(raw);
8710
+ const items = raw?.[0]?.["details"] ?? [];
8711
+ printTable(
8712
+ items.map((c, i) => {
8713
+ const snt = c["sentiment"];
8714
+ return {
8715
+ rank: i + 1,
8716
+ symbol: c["ccy"],
8717
+ label: snt?.["label"] ?? "-",
8718
+ bullish: snt?.["bullishRatio"] ?? "-",
8719
+ bearish: snt?.["bearishRatio"] ?? "-",
8720
+ mentions: c["mentionCnt"]
8721
+ };
8722
+ })
8723
+ );
8724
+ }
8725
+
8074
8726
  // src/config/loader.ts
8075
8727
  function loadProfileConfig(opts) {
8076
8728
  return loadConfig({
8077
8729
  profile: opts.profile,
8078
8730
  modules: opts.modules,
8079
8731
  readOnly: opts.readOnly ?? false,
8080
- demo: opts.demo ?? false,
8732
+ demo: opts.demo,
8733
+ live: opts.live,
8081
8734
  site: opts.site,
8082
8735
  userAgent: opts.userAgent,
8083
8736
  sourceTag: opts.sourceTag,
@@ -8672,17 +9325,67 @@ var HELP_TREE = {
8672
9325
  },
8673
9326
  diagnose: {
8674
9327
  description: "Run network / MCP server diagnostics",
8675
- usage: "okx diagnose [--cli | --mcp | --all] [--profile <name>] [--demo] [--output <file>]"
9328
+ usage: "okx diagnose [--cli | --mcp | --all] [--profile <name>] [--demo | --live] [--output <file>]"
9329
+ },
9330
+ upgrade: {
9331
+ description: "Upgrade okx CLI and MCP server to the latest stable version",
9332
+ usage: "okx upgrade [--check] [--beta] [--force] [--json]"
9333
+ },
9334
+ news: {
9335
+ description: "Orbit News \u2014 crypto news feed, coin sentiment, and trend analysis",
9336
+ commands: {
9337
+ latest: {
9338
+ usage: "okx news latest [--limit <n>] [--lang <zh_CN|en_US>]",
9339
+ description: "Get latest crypto news"
9340
+ },
9341
+ important: {
9342
+ usage: "okx news important [--limit <n>] [--lang <zh_CN|en_US>]",
9343
+ description: "Get important / high-impact crypto news"
9344
+ },
9345
+ "by-coin": {
9346
+ usage: "okx news by-coin --coins <BTC,ETH,...> [--limit <n>] [--lang <zh_CN|en_US>]",
9347
+ description: "Get news filtered by coin(s)"
9348
+ },
9349
+ "by-sentiment": {
9350
+ usage: "okx news by-sentiment --sentiment <bullish|bearish|neutral> [--limit <n>] [--lang <zh_CN|en_US>]",
9351
+ description: "Get news filtered by sentiment"
9352
+ },
9353
+ search: {
9354
+ usage: "okx news search --keyword <text> [--limit <n>] [--lang <zh_CN|en_US>]",
9355
+ description: "Search news by keyword"
9356
+ },
9357
+ detail: {
9358
+ usage: "okx news detail <articleId> [--lang <zh_CN|en_US>]",
9359
+ description: "Get full article detail by ID"
9360
+ },
9361
+ domains: {
9362
+ usage: "okx news domains",
9363
+ description: "List available news source domains"
9364
+ },
9365
+ "coin-sentiment": {
9366
+ usage: "okx news coin-sentiment --coins <BTC,ETH,...> [--period <1h|24h>]",
9367
+ description: "Get sentiment score for specific coin(s)"
9368
+ },
9369
+ "coin-trend": {
9370
+ usage: "okx news coin-trend <coin> [--period <1h|24h>] [--points <n>]",
9371
+ description: "Get sentiment trend data points for a coin"
9372
+ },
9373
+ "sentiment-rank": {
9374
+ usage: "okx news sentiment-rank [--period <1h|24h>] [--sort-by <hot|bullish|bearish>] [--limit <n>]",
9375
+ description: "Get coin ranking by social hotness or sentiment direction"
9376
+ }
9377
+ }
8676
9378
  }
8677
9379
  };
8678
9380
  function printGlobalHelp() {
8679
9381
  const lines = [
8680
9382
  "",
8681
- `Usage: okx [--profile <name>] [--demo] [--json] <module> <action> [args...]`,
9383
+ `Usage: okx [--profile <name>] [--demo | --live] [--json] <module> <action> [args...]`,
8682
9384
  "",
8683
9385
  "Global Options:",
8684
9386
  ` --profile <name> Use a named profile from ${configFilePath()}`,
8685
9387
  " --demo Use simulated trading (demo) mode",
9388
+ " --live Force live trading mode (overrides profile demo=true; mutually exclusive with --demo)",
8686
9389
  " --json Output raw JSON",
8687
9390
  " --verbose Show detailed network request/response info (stderr)",
8688
9391
  " --version, -v Show version",
@@ -8922,6 +9625,9 @@ var CLI_OPTIONS = {
8922
9625
  // audit
8923
9626
  since: { type: "string" },
8924
9627
  tool: { type: "string" },
9628
+ // upgrade
9629
+ beta: { type: "boolean", default: false },
9630
+ check: { type: "boolean", default: false },
8925
9631
  // config profile
8926
9632
  force: { type: "boolean", default: false },
8927
9633
  // onchain-earn
@@ -8951,6 +9657,15 @@ var CLI_OPTIONS = {
8951
9657
  params: { type: "string" },
8952
9658
  list: { type: "boolean", default: false },
8953
9659
  "backtest-time": { type: "string" },
9660
+ // news
9661
+ coins: { type: "string" },
9662
+ sentiment: { type: "string" },
9663
+ importance: { type: "string" },
9664
+ keyword: { type: "string" },
9665
+ "detail-lvl": { type: "string" },
9666
+ period: { type: "string" },
9667
+ points: { type: "string" },
9668
+ "sort-by": { type: "string" },
8954
9669
  // diagnostics — cli/mcp/all/output are diagnose-specific; verbose is shared
8955
9670
  verbose: { type: "boolean", default: false },
8956
9671
  mcp: { type: "boolean", default: false },
@@ -8986,12 +9701,12 @@ function parseCli(argv) {
8986
9701
  }
8987
9702
 
8988
9703
  // src/commands/market.ts
8989
- function getData(result) {
9704
+ function getData2(result) {
8990
9705
  return result.data;
8991
9706
  }
8992
9707
  async function cmdMarketInstruments(run, opts) {
8993
9708
  const result = await run("market_get_instruments", { instType: opts.instType, instId: opts.instId });
8994
- const items = getData(result);
9709
+ const items = getData2(result);
8995
9710
  if (opts.json) return printJson(items);
8996
9711
  printTable(
8997
9712
  (items ?? []).slice(0, 50).map((t) => ({
@@ -9006,7 +9721,7 @@ async function cmdMarketInstruments(run, opts) {
9006
9721
  }
9007
9722
  async function cmdMarketFundingRate(run, instId, opts) {
9008
9723
  const result = await run("market_get_funding_rate", { instId, history: opts.history, limit: opts.limit });
9009
- const items = getData(result);
9724
+ const items = getData2(result);
9010
9725
  if (opts.json) return printJson(items);
9011
9726
  if (opts.history) {
9012
9727
  printTable(
@@ -9034,7 +9749,7 @@ async function cmdMarketFundingRate(run, instId, opts) {
9034
9749
  }
9035
9750
  async function cmdMarketMarkPrice(run, opts) {
9036
9751
  const result = await run("market_get_mark_price", { instType: opts.instType, instId: opts.instId });
9037
- const items = getData(result);
9752
+ const items = getData2(result);
9038
9753
  if (opts.json) return printJson(items);
9039
9754
  printTable(
9040
9755
  (items ?? []).map((r) => ({
@@ -9047,7 +9762,7 @@ async function cmdMarketMarkPrice(run, opts) {
9047
9762
  }
9048
9763
  async function cmdMarketTrades(run, instId, opts) {
9049
9764
  const result = await run("market_get_trades", { instId, limit: opts.limit });
9050
- const items = getData(result);
9765
+ const items = getData2(result);
9051
9766
  if (opts.json) return printJson(items);
9052
9767
  printTable(
9053
9768
  (items ?? []).map((t) => ({
@@ -9061,7 +9776,7 @@ async function cmdMarketTrades(run, instId, opts) {
9061
9776
  }
9062
9777
  async function cmdMarketIndexTicker(run, opts) {
9063
9778
  const result = await run("market_get_index_ticker", { instId: opts.instId, quoteCcy: opts.quoteCcy });
9064
- const items = getData(result);
9779
+ const items = getData2(result);
9065
9780
  if (opts.json) return printJson(items);
9066
9781
  printTable(
9067
9782
  (items ?? []).map((t) => ({
@@ -9075,7 +9790,7 @@ async function cmdMarketIndexTicker(run, opts) {
9075
9790
  }
9076
9791
  async function cmdMarketIndexCandles(run, instId, opts) {
9077
9792
  const result = await run("market_get_index_candles", { instId, bar: opts.bar, limit: opts.limit, history: opts.history });
9078
- const candles = getData(result);
9793
+ const candles = getData2(result);
9079
9794
  if (opts.json) return printJson(candles);
9080
9795
  printTable(
9081
9796
  (candles ?? []).map(([ts, o, h, l, c]) => ({
@@ -9089,7 +9804,7 @@ async function cmdMarketIndexCandles(run, instId, opts) {
9089
9804
  }
9090
9805
  async function cmdMarketPriceLimit(run, instId, json) {
9091
9806
  const result = await run("market_get_price_limit", { instId });
9092
- const items = getData(result);
9807
+ const items = getData2(result);
9093
9808
  if (json) return printJson(items);
9094
9809
  const r = items?.[0];
9095
9810
  if (!r) {
@@ -9105,7 +9820,7 @@ async function cmdMarketPriceLimit(run, instId, json) {
9105
9820
  }
9106
9821
  async function cmdMarketOpenInterest(run, opts) {
9107
9822
  const result = await run("market_get_open_interest", { instType: opts.instType, instId: opts.instId });
9108
- const items = getData(result);
9823
+ const items = getData2(result);
9109
9824
  if (opts.json) return printJson(items);
9110
9825
  printTable(
9111
9826
  (items ?? []).map((r) => ({
@@ -9118,7 +9833,7 @@ async function cmdMarketOpenInterest(run, opts) {
9118
9833
  }
9119
9834
  async function cmdMarketTicker(run, instId, json) {
9120
9835
  const result = await run("market_get_ticker", { instId });
9121
- const items = getData(result);
9836
+ const items = getData2(result);
9122
9837
  if (json) return printJson(items);
9123
9838
  if (!items?.length) {
9124
9839
  outputLine("No data");
@@ -9142,7 +9857,7 @@ async function cmdMarketTicker(run, instId, json) {
9142
9857
  }
9143
9858
  async function cmdMarketTickers(run, instType, json) {
9144
9859
  const result = await run("market_get_tickers", { instType });
9145
- const items = getData(result);
9860
+ const items = getData2(result);
9146
9861
  if (json) return printJson(items);
9147
9862
  printTable(
9148
9863
  (items ?? []).map((t) => ({
@@ -9156,7 +9871,7 @@ async function cmdMarketTickers(run, instType, json) {
9156
9871
  }
9157
9872
  async function cmdMarketOrderbook(run, instId, sz, json) {
9158
9873
  const result = await run("market_get_orderbook", { instId, sz });
9159
- const data = getData(result);
9874
+ const data = getData2(result);
9160
9875
  if (json) return printJson(data);
9161
9876
  const book = data[0];
9162
9877
  if (!book) {
@@ -9173,7 +9888,7 @@ async function cmdMarketOrderbook(run, instId, sz, json) {
9173
9888
  }
9174
9889
  async function cmdMarketCandles(run, instId, opts) {
9175
9890
  const result = await run("market_get_candles", { instId, bar: opts.bar, limit: opts.limit, after: opts.after, before: opts.before });
9176
- const candles = getData(result);
9891
+ const candles = getData2(result);
9177
9892
  if (opts.json) return printJson(candles);
9178
9893
  printTable(
9179
9894
  (candles ?? []).map(([ts, o, h, l, c, vol]) => ({
@@ -9197,7 +9912,7 @@ async function cmdMarketIndicator(run, indicator, instId, opts) {
9197
9912
  limit: opts.limit,
9198
9913
  backtestTime: opts.backtestTime
9199
9914
  });
9200
- const outerArray = getData(result);
9915
+ const outerArray = getData2(result);
9201
9916
  if (opts.json) return printJson(outerArray);
9202
9917
  if (!outerArray?.length) {
9203
9918
  process.stdout.write("No data\n");
@@ -9236,7 +9951,7 @@ async function cmdMarketIndicator(run, indicator, instId, opts) {
9236
9951
  }
9237
9952
  async function cmdMarketStockTokens(run, opts) {
9238
9953
  const result = await run("market_get_stock_tokens", { instType: opts.instType, instId: opts.instId });
9239
- const items = getData(result);
9954
+ const items = getData2(result);
9240
9955
  if (opts.json) return printJson(items);
9241
9956
  printTable(
9242
9957
  (items ?? []).slice(0, 50).map((t) => ({
@@ -9255,12 +9970,12 @@ async function cmdMarketStockTokens(run, opts) {
9255
9970
  import * as fs6 from "fs";
9256
9971
  import * as path4 from "path";
9257
9972
  import * as os5 from "os";
9258
- function getData2(result) {
9973
+ function getData3(result) {
9259
9974
  return result.data;
9260
9975
  }
9261
9976
  async function cmdAccountBalance(run, ccy, json) {
9262
9977
  const result = await run("account_get_balance", { ccy });
9263
- const data = getData2(result);
9978
+ const data = getData3(result);
9264
9979
  if (json) return printJson(data);
9265
9980
  const details = data?.[0]?.["details"] ?? [];
9266
9981
  const rows = details.filter((d) => Number(d["eq"]) > 0).map((d) => ({
@@ -9313,7 +10028,7 @@ async function cmdAccountAssetBalance(run, ccy, json, showValuation) {
9313
10028
  }
9314
10029
  async function cmdAccountPositions(run, opts) {
9315
10030
  const result = await run("account_get_positions", { instType: opts.instType, instId: opts.instId });
9316
- const positions = getData2(result);
10031
+ const positions = getData3(result);
9317
10032
  if (opts.json) return printJson(positions);
9318
10033
  const open = (positions ?? []).filter((p) => Number(p["pos"]) !== 0);
9319
10034
  if (!open.length) {
@@ -9335,7 +10050,7 @@ async function cmdAccountPositions(run, opts) {
9335
10050
  async function cmdAccountBills(run, opts) {
9336
10051
  const toolName = opts.archive ? "account_get_bills_archive" : "account_get_bills";
9337
10052
  const result = await run(toolName, { instType: opts.instType, ccy: opts.ccy, limit: opts.limit });
9338
- const bills = getData2(result);
10053
+ const bills = getData3(result);
9339
10054
  if (opts.json) return printJson(bills);
9340
10055
  printTable(
9341
10056
  (bills ?? []).map((b) => ({
@@ -9351,7 +10066,7 @@ async function cmdAccountBills(run, opts) {
9351
10066
  }
9352
10067
  async function cmdAccountFees(run, opts) {
9353
10068
  const result = await run("account_get_trade_fee", { instType: opts.instType, instId: opts.instId });
9354
- const data = getData2(result);
10069
+ const data = getData3(result);
9355
10070
  if (opts.json) return printJson(data);
9356
10071
  const fee = data?.[0];
9357
10072
  if (!fee) {
@@ -9369,7 +10084,7 @@ async function cmdAccountFees(run, opts) {
9369
10084
  }
9370
10085
  async function cmdAccountConfig(run, json) {
9371
10086
  const result = await run("account_get_config", {});
9372
- const data = getData2(result);
10087
+ const data = getData3(result);
9373
10088
  if (json) return printJson(data);
9374
10089
  const cfg = data?.[0];
9375
10090
  if (!cfg) {
@@ -9388,14 +10103,14 @@ async function cmdAccountConfig(run, json) {
9388
10103
  }
9389
10104
  async function cmdAccountSetPositionMode(run, posMode, json) {
9390
10105
  const result = await run("account_set_position_mode", { posMode });
9391
- const data = getData2(result);
10106
+ const data = getData3(result);
9392
10107
  if (json) return printJson(data);
9393
10108
  const r = data?.[0];
9394
10109
  outputLine(`Position mode set: ${r?.["posMode"]}`);
9395
10110
  }
9396
10111
  async function cmdAccountMaxSize(run, opts) {
9397
10112
  const result = await run("account_get_max_size", { instId: opts.instId, tdMode: opts.tdMode, px: opts.px });
9398
- const data = getData2(result);
10113
+ const data = getData3(result);
9399
10114
  if (opts.json) return printJson(data);
9400
10115
  const r = data?.[0];
9401
10116
  if (!r) {
@@ -9406,7 +10121,7 @@ async function cmdAccountMaxSize(run, opts) {
9406
10121
  }
9407
10122
  async function cmdAccountMaxAvailSize(run, opts) {
9408
10123
  const result = await run("account_get_max_avail_size", { instId: opts.instId, tdMode: opts.tdMode });
9409
- const data = getData2(result);
10124
+ const data = getData3(result);
9410
10125
  if (opts.json) return printJson(data);
9411
10126
  const r = data?.[0];
9412
10127
  if (!r) {
@@ -9417,7 +10132,7 @@ async function cmdAccountMaxAvailSize(run, opts) {
9417
10132
  }
9418
10133
  async function cmdAccountMaxWithdrawal(run, ccy, json) {
9419
10134
  const result = await run("account_get_max_withdrawal", { ccy });
9420
- const data = getData2(result);
10135
+ const data = getData3(result);
9421
10136
  if (json) return printJson(data);
9422
10137
  printTable(
9423
10138
  (data ?? []).map((r) => ({
@@ -9429,7 +10144,7 @@ async function cmdAccountMaxWithdrawal(run, ccy, json) {
9429
10144
  }
9430
10145
  async function cmdAccountPositionsHistory(run, opts) {
9431
10146
  const result = await run("account_get_positions_history", { instType: opts.instType, instId: opts.instId, limit: opts.limit });
9432
- const data = getData2(result);
10147
+ const data = getData3(result);
9433
10148
  if (opts.json) return printJson(data);
9434
10149
  printTable(
9435
10150
  (data ?? []).map((p) => ({
@@ -9451,7 +10166,7 @@ async function cmdAccountTransfer(run, opts) {
9451
10166
  type: opts.transferType,
9452
10167
  subAcct: opts.subAcct
9453
10168
  });
9454
- const data = getData2(result);
10169
+ const data = getData3(result);
9455
10170
  if (opts.json) return printJson(data);
9456
10171
  const r = data?.[0];
9457
10172
  outputLine(`Transfer: ${r?.["transId"]} (${r?.["ccy"]} ${r?.["amt"]})`);
@@ -9511,7 +10226,7 @@ function cmdAccountAudit(opts) {
9511
10226
  }
9512
10227
 
9513
10228
  // src/commands/spot.ts
9514
- function getData3(result) {
10229
+ function getData4(result) {
9515
10230
  return result.data;
9516
10231
  }
9517
10232
  function emitWriteResult(item, label, idKey) {
@@ -9535,7 +10250,7 @@ function emitBatchResults(items) {
9535
10250
  }
9536
10251
  async function cmdSpotOrders(run, opts) {
9537
10252
  const result = await run("spot_get_orders", { instId: opts.instId, status: opts.status });
9538
- const orders = getData3(result);
10253
+ const orders = getData4(result);
9539
10254
  if (opts.json) return printJson(orders);
9540
10255
  printTable(
9541
10256
  (orders ?? []).map((o) => ({
@@ -9564,7 +10279,7 @@ async function cmdSpotPlace(run, opts) {
9564
10279
  slTriggerPx: opts.slTriggerPx,
9565
10280
  slOrdPx: opts.slOrdPx
9566
10281
  });
9567
- const data = getData3(result);
10282
+ const data = getData4(result);
9568
10283
  if (opts.json) return printJson(data);
9569
10284
  emitWriteResult(data?.[0], "Order placed", "ordId");
9570
10285
  }
@@ -9572,7 +10287,7 @@ async function cmdSpotCancel(run, opts) {
9572
10287
  const { instId, ordId, clOrdId, json } = opts;
9573
10288
  if (!ordId && !clOrdId) throw new Error("Either --ordId or --clOrdId is required");
9574
10289
  const result = await run("spot_cancel_order", { instId, ...ordId ? { ordId } : { clOrdId } });
9575
- const data = getData3(result);
10290
+ const data = getData4(result);
9576
10291
  if (json) return printJson(data);
9577
10292
  emitWriteResult(data?.[0], "Cancelled", "ordId");
9578
10293
  }
@@ -9592,7 +10307,7 @@ async function cmdSpotAlgoPlace(run, opts) {
9592
10307
  callbackSpread: opts.callbackSpread,
9593
10308
  activePx: opts.activePx
9594
10309
  });
9595
- const data = getData3(result);
10310
+ const data = getData4(result);
9596
10311
  if (opts.json) return printJson(data);
9597
10312
  emitWriteResult(data?.[0], "Algo order placed", "algoId");
9598
10313
  }
@@ -9606,19 +10321,19 @@ async function cmdSpotAlgoAmend(run, opts) {
9606
10321
  newSlTriggerPx: opts.newSlTriggerPx,
9607
10322
  newSlOrdPx: opts.newSlOrdPx
9608
10323
  });
9609
- const data = getData3(result);
10324
+ const data = getData4(result);
9610
10325
  if (opts.json) return printJson(data);
9611
10326
  emitWriteResult(data?.[0], "Algo order amended", "algoId");
9612
10327
  }
9613
10328
  async function cmdSpotAlgoCancel(run, instId, algoId, json) {
9614
10329
  const result = await run("spot_cancel_algo_order", { instId, algoId });
9615
- const data = getData3(result);
10330
+ const data = getData4(result);
9616
10331
  if (json) return printJson(data);
9617
10332
  emitWriteResult(data?.[0], "Algo order cancelled", "algoId");
9618
10333
  }
9619
10334
  async function cmdSpotGet(run, opts) {
9620
10335
  const result = await run("spot_get_order", { instId: opts.instId, ordId: opts.ordId, clOrdId: opts.clOrdId });
9621
- const data = getData3(result);
10336
+ const data = getData4(result);
9622
10337
  if (opts.json) return printJson(data);
9623
10338
  const o = data?.[0];
9624
10339
  if (!o) {
@@ -9646,7 +10361,7 @@ async function cmdSpotAmend(run, opts) {
9646
10361
  newSz: opts.newSz,
9647
10362
  newPx: opts.newPx
9648
10363
  });
9649
- const data = getData3(result);
10364
+ const data = getData4(result);
9650
10365
  if (opts.json) return printJson(data);
9651
10366
  emitWriteResult(data?.[0], "Order amended", "ordId");
9652
10367
  }
@@ -9656,7 +10371,7 @@ async function cmdSpotAlgoOrders(run, opts) {
9656
10371
  status: opts.status,
9657
10372
  ordType: opts.ordType
9658
10373
  });
9659
- const orders = getData3(result);
10374
+ const orders = getData4(result);
9660
10375
  if (opts.json) return printJson(orders);
9661
10376
  if (!(orders ?? []).length) {
9662
10377
  outputLine("No algo orders");
@@ -9677,7 +10392,7 @@ async function cmdSpotAlgoOrders(run, opts) {
9677
10392
  }
9678
10393
  async function cmdSpotFills(run, opts) {
9679
10394
  const result = await run("spot_get_fills", { instId: opts.instId, ordId: opts.ordId });
9680
- const fills = getData3(result);
10395
+ const fills = getData4(result);
9681
10396
  if (opts.json) return printJson(fills);
9682
10397
  printTable(
9683
10398
  (fills ?? []).map((f) => ({
@@ -9701,7 +10416,7 @@ async function cmdSpotAlgoTrailPlace(run, opts) {
9701
10416
  callbackSpread: opts.callbackSpread,
9702
10417
  activePx: opts.activePx
9703
10418
  });
9704
- const data = getData3(result);
10419
+ const data = getData4(result);
9705
10420
  if (opts.json) return printJson(data);
9706
10421
  emitWriteResult(data?.[0], "Trailing stop placed", "algoId");
9707
10422
  }
@@ -9731,13 +10446,13 @@ async function cmdSpotBatch(run, opts) {
9731
10446
  return;
9732
10447
  }
9733
10448
  const result = await run(tool, tool === "spot_batch_orders" ? { action: opts.action, orders: parsed } : { orders: parsed });
9734
- const data = getData3(result);
10449
+ const data = getData4(result);
9735
10450
  if (opts.json) return printJson(data);
9736
10451
  emitBatchResults(data ?? []);
9737
10452
  }
9738
10453
 
9739
10454
  // src/commands/swap.ts
9740
- function getData4(result) {
10455
+ function getData5(result) {
9741
10456
  return result.data;
9742
10457
  }
9743
10458
  function emitWriteResult2(item, label, idKey) {
@@ -9761,7 +10476,7 @@ function emitBatchResults2(items) {
9761
10476
  }
9762
10477
  async function cmdSwapPositions(run, instId, json) {
9763
10478
  const result = await run("swap_get_positions", { instId });
9764
- const positions = getData4(result);
10479
+ const positions = getData5(result);
9765
10480
  if (json) return printJson(positions);
9766
10481
  const open = (positions ?? []).filter((p) => Number(p["pos"]) !== 0);
9767
10482
  if (!open.length) {
@@ -9782,7 +10497,7 @@ async function cmdSwapPositions(run, instId, json) {
9782
10497
  }
9783
10498
  async function cmdSwapOrders(run, opts) {
9784
10499
  const result = await run("swap_get_orders", { instId: opts.instId, status: opts.status });
9785
- const orders = getData4(result);
10500
+ const orders = getData5(result);
9786
10501
  if (opts.json) return printJson(orders);
9787
10502
  printTable(
9788
10503
  (orders ?? []).map((o) => ({
@@ -9812,7 +10527,7 @@ async function cmdSwapPlace(run, opts) {
9812
10527
  slTriggerPx: opts.slTriggerPx,
9813
10528
  slOrdPx: opts.slOrdPx
9814
10529
  });
9815
- const data = getData4(result);
10530
+ const data = getData5(result);
9816
10531
  if (opts.json) return printJson(data);
9817
10532
  emitWriteResult2(data?.[0], "Order placed", "ordId");
9818
10533
  }
@@ -9820,7 +10535,7 @@ async function cmdSwapCancel(run, opts) {
9820
10535
  const { instId, ordId, clOrdId, json } = opts;
9821
10536
  if (!ordId && !clOrdId) throw new Error("Either --ordId or --clOrdId is required");
9822
10537
  const result = await run("swap_cancel_order", { instId, ...ordId ? { ordId } : { clOrdId } });
9823
- const data = getData4(result);
10538
+ const data = getData5(result);
9824
10539
  if (json) return printJson(data);
9825
10540
  emitWriteResult2(data?.[0], "Cancelled", "ordId");
9826
10541
  }
@@ -9842,7 +10557,7 @@ async function cmdSwapAlgoPlace(run, opts) {
9842
10557
  callbackSpread: opts.callbackSpread,
9843
10558
  activePx: opts.activePx
9844
10559
  });
9845
- const data = getData4(result);
10560
+ const data = getData5(result);
9846
10561
  if (opts.json) return printJson(data);
9847
10562
  emitWriteResult2(data?.[0], "Algo order placed", "algoId");
9848
10563
  }
@@ -9856,7 +10571,7 @@ async function cmdSwapAlgoAmend(run, opts) {
9856
10571
  newSlTriggerPx: opts.newSlTriggerPx,
9857
10572
  newSlOrdPx: opts.newSlOrdPx
9858
10573
  });
9859
- const data = getData4(result);
10574
+ const data = getData5(result);
9860
10575
  if (opts.json) return printJson(data);
9861
10576
  emitWriteResult2(data?.[0], "Algo order amended", "algoId");
9862
10577
  }
@@ -9872,13 +10587,13 @@ async function cmdSwapAlgoTrailPlace(run, opts) {
9872
10587
  posSide: opts.posSide,
9873
10588
  reduceOnly: opts.reduceOnly
9874
10589
  });
9875
- const data = getData4(result);
10590
+ const data = getData5(result);
9876
10591
  if (opts.json) return printJson(data);
9877
10592
  emitWriteResult2(data?.[0], "Trailing stop placed", "algoId");
9878
10593
  }
9879
10594
  async function cmdSwapAlgoCancel(run, instId, algoId, json) {
9880
10595
  const result = await run("swap_cancel_algo_orders", { orders: [{ instId, algoId }] });
9881
- const data = getData4(result);
10596
+ const data = getData5(result);
9882
10597
  if (json) return printJson(data);
9883
10598
  emitWriteResult2(data?.[0], "Algo order cancelled", "algoId");
9884
10599
  }
@@ -9888,7 +10603,7 @@ async function cmdSwapAlgoOrders(run, opts) {
9888
10603
  status: opts.status,
9889
10604
  ordType: opts.ordType
9890
10605
  });
9891
- const orders = getData4(result);
10606
+ const orders = getData5(result);
9892
10607
  if (opts.json) return printJson(orders);
9893
10608
  if (!(orders ?? []).length) {
9894
10609
  outputLine("No algo orders");
@@ -9909,7 +10624,7 @@ async function cmdSwapAlgoOrders(run, opts) {
9909
10624
  }
9910
10625
  async function cmdSwapFills(run, opts) {
9911
10626
  const result = await run("swap_get_fills", { instId: opts.instId, ordId: opts.ordId, archive: opts.archive });
9912
- const fills = getData4(result);
10627
+ const fills = getData5(result);
9913
10628
  if (opts.json) return printJson(fills);
9914
10629
  printTable(
9915
10630
  (fills ?? []).map((f) => ({
@@ -9924,7 +10639,7 @@ async function cmdSwapFills(run, opts) {
9924
10639
  }
9925
10640
  async function cmdSwapGet(run, opts) {
9926
10641
  const result = await run("swap_get_order", { instId: opts.instId, ordId: opts.ordId, clOrdId: opts.clOrdId });
9927
- const data = getData4(result);
10642
+ const data = getData5(result);
9928
10643
  if (opts.json) return printJson(data);
9929
10644
  const o = data?.[0];
9930
10645
  if (!o) {
@@ -9952,14 +10667,14 @@ async function cmdSwapClose(run, opts) {
9952
10667
  posSide: opts.posSide,
9953
10668
  autoCxl: opts.autoCxl
9954
10669
  });
9955
- const data = getData4(result);
10670
+ const data = getData5(result);
9956
10671
  if (opts.json) return printJson(data);
9957
10672
  const r = data?.[0];
9958
10673
  outputLine(`Position closed: ${r?.["instId"]} ${r?.["posSide"] ?? ""}`);
9959
10674
  }
9960
10675
  async function cmdSwapGetLeverage(run, opts) {
9961
10676
  const result = await run("swap_get_leverage", { instId: opts.instId, mgnMode: opts.mgnMode });
9962
- const data = getData4(result);
10677
+ const data = getData5(result);
9963
10678
  if (opts.json) return printJson(data);
9964
10679
  printTable(
9965
10680
  (data ?? []).map((r) => ({
@@ -9978,7 +10693,7 @@ async function cmdSwapAmend(run, opts) {
9978
10693
  newSz: opts.newSz,
9979
10694
  newPx: opts.newPx
9980
10695
  });
9981
- const data = getData4(result);
10696
+ const data = getData5(result);
9982
10697
  if (opts.json) return printJson(data);
9983
10698
  emitWriteResult2(data?.[0], "Order amended", "ordId");
9984
10699
  }
@@ -9989,7 +10704,7 @@ async function cmdSwapSetLeverage(run, opts) {
9989
10704
  mgnMode: opts.mgnMode,
9990
10705
  posSide: opts.posSide
9991
10706
  });
9992
- const data = getData4(result);
10707
+ const data = getData5(result);
9993
10708
  if (opts.json) return printJson(data);
9994
10709
  const r = data?.[0];
9995
10710
  outputLine(`Leverage set: ${r?.["lever"]}x ${r?.["instId"]}`);
@@ -10020,13 +10735,13 @@ async function cmdSwapBatch(run, opts) {
10020
10735
  return;
10021
10736
  }
10022
10737
  const result = await run(tool, tool === "swap_batch_orders" ? { action: opts.action, orders: parsed } : { orders: parsed });
10023
- const data = getData4(result);
10738
+ const data = getData5(result);
10024
10739
  if (opts.json) return printJson(data);
10025
10740
  emitBatchResults2(data ?? []);
10026
10741
  }
10027
10742
 
10028
10743
  // src/commands/futures.ts
10029
- function getData5(result) {
10744
+ function getData6(result) {
10030
10745
  return result.data;
10031
10746
  }
10032
10747
  function emitWriteResult3(item, label, idKey) {
@@ -10050,7 +10765,7 @@ function emitBatchResults3(items) {
10050
10765
  }
10051
10766
  async function cmdFuturesOrders(run, opts) {
10052
10767
  const result = await run("futures_get_orders", { instId: opts.instId, status: opts.status });
10053
- const orders = getData5(result);
10768
+ const orders = getData6(result);
10054
10769
  if (opts.json) return printJson(orders);
10055
10770
  printTable(
10056
10771
  (orders ?? []).map((o) => ({
@@ -10067,7 +10782,7 @@ async function cmdFuturesOrders(run, opts) {
10067
10782
  }
10068
10783
  async function cmdFuturesPositions(run, instId, json) {
10069
10784
  const result = await run("futures_get_positions", { instId });
10070
- const positions = getData5(result);
10785
+ const positions = getData6(result);
10071
10786
  if (json) return printJson(positions);
10072
10787
  const open = (positions ?? []).filter((p) => Number(p["pos"]) !== 0);
10073
10788
  if (!open.length) {
@@ -10087,7 +10802,7 @@ async function cmdFuturesPositions(run, instId, json) {
10087
10802
  }
10088
10803
  async function cmdFuturesFills(run, opts) {
10089
10804
  const result = await run("futures_get_fills", { instId: opts.instId, ordId: opts.ordId, archive: opts.archive });
10090
- const fills = getData5(result);
10805
+ const fills = getData6(result);
10091
10806
  if (opts.json) return printJson(fills);
10092
10807
  printTable(
10093
10808
  (fills ?? []).map((f) => ({
@@ -10116,7 +10831,7 @@ async function cmdFuturesPlace(run, opts) {
10116
10831
  slTriggerPx: opts.slTriggerPx,
10117
10832
  slOrdPx: opts.slOrdPx
10118
10833
  });
10119
- const data = getData5(result);
10834
+ const data = getData6(result);
10120
10835
  if (opts.json) return printJson(data);
10121
10836
  emitWriteResult3(data?.[0], "Order placed", "ordId");
10122
10837
  }
@@ -10124,13 +10839,13 @@ async function cmdFuturesCancel(run, opts) {
10124
10839
  const { instId, ordId, clOrdId, json } = opts;
10125
10840
  if (!ordId && !clOrdId) throw new Error("Either --ordId or --clOrdId is required");
10126
10841
  const result = await run("futures_cancel_order", { instId, ...ordId ? { ordId } : { clOrdId } });
10127
- const data = getData5(result);
10842
+ const data = getData6(result);
10128
10843
  if (json) return printJson(data);
10129
10844
  emitWriteResult3(data?.[0], "Cancelled", "ordId");
10130
10845
  }
10131
10846
  async function cmdFuturesGet(run, opts) {
10132
10847
  const result = await run("futures_get_order", { instId: opts.instId, ordId: opts.ordId });
10133
- const data = getData5(result);
10848
+ const data = getData6(result);
10134
10849
  if (opts.json) return printJson(data);
10135
10850
  const o = data?.[0];
10136
10851
  if (!o) {
@@ -10159,7 +10874,7 @@ async function cmdFuturesAmend(run, opts) {
10159
10874
  newSz: opts.newSz,
10160
10875
  newPx: opts.newPx
10161
10876
  });
10162
- const data = getData5(result);
10877
+ const data = getData6(result);
10163
10878
  if (opts.json) return printJson(data);
10164
10879
  emitWriteResult3(data?.[0], "Order amended", "ordId");
10165
10880
  }
@@ -10170,7 +10885,7 @@ async function cmdFuturesClose(run, opts) {
10170
10885
  posSide: opts.posSide,
10171
10886
  autoCxl: opts.autoCxl
10172
10887
  });
10173
- const data = getData5(result);
10888
+ const data = getData6(result);
10174
10889
  if (opts.json) return printJson(data);
10175
10890
  const r = data?.[0];
10176
10891
  outputLine(`Position closed: ${r?.["instId"]} ${r?.["posSide"] ?? ""}`);
@@ -10182,14 +10897,14 @@ async function cmdFuturesSetLeverage(run, opts) {
10182
10897
  mgnMode: opts.mgnMode,
10183
10898
  posSide: opts.posSide
10184
10899
  });
10185
- const data = getData5(result);
10900
+ const data = getData6(result);
10186
10901
  if (opts.json) return printJson(data);
10187
10902
  const r = data?.[0];
10188
10903
  outputLine(`Leverage set: ${r?.["lever"]}x ${r?.["instId"]}`);
10189
10904
  }
10190
10905
  async function cmdFuturesGetLeverage(run, opts) {
10191
10906
  const result = await run("futures_get_leverage", { instId: opts.instId, mgnMode: opts.mgnMode });
10192
- const data = getData5(result);
10907
+ const data = getData6(result);
10193
10908
  if (opts.json) return printJson(data);
10194
10909
  printTable(
10195
10910
  (data ?? []).map((r) => ({
@@ -10226,7 +10941,7 @@ async function cmdFuturesBatch(run, opts) {
10226
10941
  return;
10227
10942
  }
10228
10943
  const result = await run(tool, { orders: parsed });
10229
- const data = getData5(result);
10944
+ const data = getData6(result);
10230
10945
  if (opts.json) return printJson(data);
10231
10946
  emitBatchResults3(data ?? []);
10232
10947
  }
@@ -10248,7 +10963,7 @@ async function cmdFuturesAlgoPlace(run, opts) {
10248
10963
  callbackSpread: opts.callbackSpread,
10249
10964
  activePx: opts.activePx
10250
10965
  });
10251
- const data = getData5(result);
10966
+ const data = getData6(result);
10252
10967
  if (opts.json) return printJson(data);
10253
10968
  emitWriteResult3(data?.[0], "Algo order placed", "algoId");
10254
10969
  }
@@ -10264,7 +10979,7 @@ async function cmdFuturesAlgoTrailPlace(run, opts) {
10264
10979
  posSide: opts.posSide,
10265
10980
  reduceOnly: opts.reduceOnly
10266
10981
  });
10267
- const data = getData5(result);
10982
+ const data = getData6(result);
10268
10983
  if (opts.json) return printJson(data);
10269
10984
  emitWriteResult3(data?.[0], "Trailing stop placed", "algoId");
10270
10985
  }
@@ -10278,13 +10993,13 @@ async function cmdFuturesAlgoAmend(run, opts) {
10278
10993
  newSlTriggerPx: opts.newSlTriggerPx,
10279
10994
  newSlOrdPx: opts.newSlOrdPx
10280
10995
  });
10281
- const data = getData5(result);
10996
+ const data = getData6(result);
10282
10997
  if (opts.json) return printJson(data);
10283
10998
  emitWriteResult3(data?.[0], "Algo order amended", "algoId");
10284
10999
  }
10285
11000
  async function cmdFuturesAlgoCancel(run, instId, algoId, json) {
10286
11001
  const result = await run("futures_cancel_algo_orders", { orders: [{ instId, algoId }] });
10287
- const data = getData5(result);
11002
+ const data = getData6(result);
10288
11003
  if (json) return printJson(data);
10289
11004
  emitWriteResult3(data?.[0], "Algo order cancelled", "algoId");
10290
11005
  }
@@ -10294,7 +11009,7 @@ async function cmdFuturesAlgoOrders(run, opts) {
10294
11009
  status: opts.status,
10295
11010
  ordType: opts.ordType
10296
11011
  });
10297
- const orders = getData5(result);
11012
+ const orders = getData6(result);
10298
11013
  if (opts.json) return printJson(orders);
10299
11014
  if (!(orders ?? []).length) {
10300
11015
  outputLine("No algo orders");
@@ -10315,7 +11030,7 @@ async function cmdFuturesAlgoOrders(run, opts) {
10315
11030
  }
10316
11031
 
10317
11032
  // src/commands/option.ts
10318
- function getData6(result) {
11033
+ function getData7(result) {
10319
11034
  return result.data;
10320
11035
  }
10321
11036
  function emitWriteResult4(item, label, idKey) {
@@ -10343,7 +11058,7 @@ async function cmdOptionOrders(run, opts) {
10343
11058
  uly: opts.uly,
10344
11059
  status: opts.status
10345
11060
  });
10346
- const orders = getData6(result);
11061
+ const orders = getData7(result);
10347
11062
  if (opts.json) return printJson(orders);
10348
11063
  printTable(
10349
11064
  (orders ?? []).map((o) => ({
@@ -10363,7 +11078,7 @@ async function cmdOptionGet(run, opts) {
10363
11078
  ordId: opts.ordId,
10364
11079
  clOrdId: opts.clOrdId
10365
11080
  });
10366
- const data = getData6(result);
11081
+ const data = getData7(result);
10367
11082
  if (opts.json) return printJson(data);
10368
11083
  const o = data?.[0];
10369
11084
  if (!o) {
@@ -10388,7 +11103,7 @@ async function cmdOptionPositions(run, opts) {
10388
11103
  instId: opts.instId,
10389
11104
  uly: opts.uly
10390
11105
  });
10391
- const positions = getData6(result);
11106
+ const positions = getData7(result);
10392
11107
  if (opts.json) return printJson(positions);
10393
11108
  const open = (positions ?? []).filter((p) => Number(p["pos"]) !== 0);
10394
11109
  if (!open.length) {
@@ -10415,7 +11130,7 @@ async function cmdOptionFills(run, opts) {
10415
11130
  ordId: opts.ordId,
10416
11131
  archive: opts.archive
10417
11132
  });
10418
- const fills = getData6(result);
11133
+ const fills = getData7(result);
10419
11134
  if (opts.json) return printJson(fills);
10420
11135
  printTable(
10421
11136
  (fills ?? []).map((f) => ({
@@ -10433,7 +11148,7 @@ async function cmdOptionInstruments(run, opts) {
10433
11148
  uly: opts.uly,
10434
11149
  expTime: opts.expTime
10435
11150
  });
10436
- const instruments = getData6(result);
11151
+ const instruments = getData7(result);
10437
11152
  if (opts.json) return printJson(instruments);
10438
11153
  printTable(
10439
11154
  (instruments ?? []).map((i) => ({
@@ -10451,7 +11166,7 @@ async function cmdOptionGreeks(run, opts) {
10451
11166
  uly: opts.uly,
10452
11167
  expTime: opts.expTime
10453
11168
  });
10454
- const greeks = getData6(result);
11169
+ const greeks = getData7(result);
10455
11170
  if (opts.json) return printJson(greeks);
10456
11171
  printTable(
10457
11172
  (greeks ?? []).map((g) => ({
@@ -10480,7 +11195,7 @@ async function cmdOptionPlace(run, opts) {
10480
11195
  slTriggerPx: opts.slTriggerPx,
10481
11196
  slOrdPx: opts.slOrdPx
10482
11197
  });
10483
- const data = getData6(result);
11198
+ const data = getData7(result);
10484
11199
  if (opts.json) return printJson(data);
10485
11200
  emitWriteResult4(data?.[0], "Order placed", "ordId");
10486
11201
  }
@@ -10490,7 +11205,7 @@ async function cmdOptionCancel(run, opts) {
10490
11205
  ordId: opts.ordId,
10491
11206
  clOrdId: opts.clOrdId
10492
11207
  });
10493
- const data = getData6(result);
11208
+ const data = getData7(result);
10494
11209
  if (opts.json) return printJson(data);
10495
11210
  emitWriteResult4(data?.[0], "Cancelled", "ordId");
10496
11211
  }
@@ -10502,7 +11217,7 @@ async function cmdOptionAmend(run, opts) {
10502
11217
  newSz: opts.newSz,
10503
11218
  newPx: opts.newPx
10504
11219
  });
10505
- const data = getData6(result);
11220
+ const data = getData7(result);
10506
11221
  if (opts.json) return printJson(data);
10507
11222
  emitWriteResult4(data?.[0], "Amended", "ordId");
10508
11223
  }
@@ -10521,7 +11236,7 @@ async function cmdOptionBatchCancel(run, opts) {
10521
11236
  return;
10522
11237
  }
10523
11238
  const result = await run("option_batch_cancel", { orders: parsed });
10524
- const data = getData6(result);
11239
+ const data = getData7(result);
10525
11240
  if (opts.json) return printJson(data);
10526
11241
  emitBatchResults4(data ?? []);
10527
11242
  }
@@ -10540,7 +11255,7 @@ async function cmdOptionAlgoPlace(run, opts) {
10540
11255
  reduceOnly: opts.reduceOnly,
10541
11256
  clOrdId: opts.clOrdId
10542
11257
  });
10543
- const data = getData6(result);
11258
+ const data = getData7(result);
10544
11259
  if (opts.json) return printJson(data);
10545
11260
  emitWriteResult4(data?.[0], "Algo order placed", "algoId");
10546
11261
  }
@@ -10554,13 +11269,13 @@ async function cmdOptionAlgoAmend(run, opts) {
10554
11269
  newSlTriggerPx: opts.newSlTriggerPx,
10555
11270
  newSlOrdPx: opts.newSlOrdPx
10556
11271
  });
10557
- const data = getData6(result);
11272
+ const data = getData7(result);
10558
11273
  if (opts.json) return printJson(data);
10559
11274
  emitWriteResult4(data?.[0], "Algo order amended", "algoId");
10560
11275
  }
10561
11276
  async function cmdOptionAlgoCancel(run, opts) {
10562
11277
  const result = await run("option_cancel_algo_orders", { orders: [{ instId: opts.instId, algoId: opts.algoId }] });
10563
- const data = getData6(result);
11278
+ const data = getData7(result);
10564
11279
  if (opts.json) return printJson(data);
10565
11280
  emitWriteResult4(data?.[0], "Algo order cancelled", "algoId");
10566
11281
  }
@@ -10570,7 +11285,7 @@ async function cmdOptionAlgoOrders(run, opts) {
10570
11285
  status: opts.status,
10571
11286
  ordType: opts.ordType
10572
11287
  });
10573
- const orders = getData6(result);
11288
+ const orders = getData7(result);
10574
11289
  if (opts.json) return printJson(orders);
10575
11290
  if (!(orders ?? []).length) {
10576
11291
  outputLine("No algo orders");
@@ -10597,7 +11312,7 @@ function writeCliConfig(config) {
10597
11312
 
10598
11313
  // src/commands/config.ts
10599
11314
  import { createInterface } from "readline";
10600
- import { spawnSync as spawnSync2 } from "child_process";
11315
+ import { spawnSync as spawnSync3 } from "child_process";
10601
11316
  var messages = {
10602
11317
  en: {
10603
11318
  title: "OKX Trade CLI \u2014 Configuration Wizard",
@@ -10739,7 +11454,7 @@ function tryOpenUrl(url) {
10739
11454
  } else {
10740
11455
  opener = "xdg-open";
10741
11456
  }
10742
- spawnSync2(opener, [url], { stdio: "ignore", shell: process.platform === "win32" });
11457
+ spawnSync3(opener, [url], { stdio: "ignore", shell: process.platform === "win32" });
10743
11458
  } catch {
10744
11459
  }
10745
11460
  }
@@ -11089,7 +11804,7 @@ function emitWriteResult5(item, label, idKey) {
11089
11804
  outputLine(`${label}: ${item?.[idKey]} (OK)`);
11090
11805
  }
11091
11806
  }
11092
- function getData7(result) {
11807
+ function getData8(result) {
11093
11808
  return result.data;
11094
11809
  }
11095
11810
  async function cmdGridOrders(run, opts) {
@@ -11099,7 +11814,7 @@ async function cmdGridOrders(run, opts) {
11099
11814
  algoId: opts.algoId,
11100
11815
  status: opts.status
11101
11816
  });
11102
- const orders = getData7(result) ?? [];
11817
+ const orders = getData8(result) ?? [];
11103
11818
  if (opts.json) return printJson(orders);
11104
11819
  if (!orders.length) {
11105
11820
  outputLine("No grid bots");
@@ -11124,7 +11839,7 @@ async function cmdGridDetails(run, opts) {
11124
11839
  algoOrdType: opts.algoOrdType,
11125
11840
  algoId: opts.algoId
11126
11841
  });
11127
- const detail = (getData7(result) ?? [])[0];
11842
+ const detail = (getData8(result) ?? [])[0];
11128
11843
  if (!detail) {
11129
11844
  outputLine("Bot not found");
11130
11845
  return;
@@ -11152,7 +11867,7 @@ async function cmdGridSubOrders(run, opts) {
11152
11867
  algoId: opts.algoId,
11153
11868
  type: opts.type
11154
11869
  });
11155
- const orders = getData7(result) ?? [];
11870
+ const orders = getData8(result) ?? [];
11156
11871
  if (opts.json) return printJson(orders);
11157
11872
  if (!orders.length) {
11158
11873
  outputLine("No sub-orders");
@@ -11191,7 +11906,7 @@ async function cmdGridCreate(run, opts) {
11191
11906
  slRatio: opts.slRatio,
11192
11907
  algoClOrdId: opts.algoClOrdId
11193
11908
  });
11194
- const data = getData7(result);
11909
+ const data = getData8(result);
11195
11910
  if (opts.json) return printJson(data);
11196
11911
  emitWriteResult5(data?.[0], "Grid bot created", "algoId");
11197
11912
  }
@@ -11202,7 +11917,7 @@ async function cmdGridStop(run, opts) {
11202
11917
  instId: opts.instId,
11203
11918
  stopType: opts.stopType
11204
11919
  });
11205
- const data = getData7(result);
11920
+ const data = getData8(result);
11206
11921
  if (opts.json) return printJson(data);
11207
11922
  emitWriteResult5(data?.[0], "Grid bot stopped", "algoId");
11208
11923
  }
@@ -11232,7 +11947,7 @@ async function cmdDcaCreate(run, opts) {
11232
11947
  reserveFunds: opts.reserveFunds,
11233
11948
  tradeQuoteCcy: opts.tradeQuoteCcy
11234
11949
  });
11235
- const data = getData7(result);
11950
+ const data = getData8(result);
11236
11951
  if (opts.json) return printJson(data);
11237
11952
  emitWriteResult5(data?.[0], "DCA bot created", "algoId");
11238
11953
  }
@@ -11242,7 +11957,7 @@ async function cmdDcaStop(run, opts) {
11242
11957
  algoOrdType: opts.algoOrdType,
11243
11958
  stopType: opts.stopType
11244
11959
  });
11245
- const data = getData7(result);
11960
+ const data = getData8(result);
11246
11961
  if (opts.json) return printJson(data);
11247
11962
  emitWriteResult5(data?.[0], "DCA bot stopped", "algoId");
11248
11963
  }
@@ -11253,7 +11968,7 @@ async function cmdDcaOrders(run, opts) {
11253
11968
  algoId: opts.algoId,
11254
11969
  instId: opts.instId
11255
11970
  });
11256
- const orders = getData7(result) ?? [];
11971
+ const orders = getData8(result) ?? [];
11257
11972
  if (opts.json) return printJson(orders);
11258
11973
  if (!orders.length) {
11259
11974
  outputLine("No DCA bots");
@@ -11276,7 +11991,7 @@ async function cmdDcaDetails(run, opts) {
11276
11991
  algoId: opts.algoId,
11277
11992
  algoOrdType: opts.algoOrdType
11278
11993
  });
11279
- const detail = (getData7(result) ?? [])[0];
11994
+ const detail = (getData8(result) ?? [])[0];
11280
11995
  if (!detail) {
11281
11996
  outputLine("DCA bot not found");
11282
11997
  return;
@@ -11305,7 +12020,7 @@ async function cmdDcaSubOrders(run, opts) {
11305
12020
  algoOrdType: opts.algoOrdType,
11306
12021
  cycleId: opts.cycleId
11307
12022
  });
11308
- const rows = getData7(result) ?? [];
12023
+ const rows = getData8(result) ?? [];
11309
12024
  if (opts.json) return printJson(rows);
11310
12025
  if (!rows.length) {
11311
12026
  outputLine("No sub-orders");
@@ -11637,7 +12352,7 @@ async function cmdDcdQuoteAndBuy(run, opts) {
11637
12352
  // src/index.ts
11638
12353
  var _require3 = createRequire3(import.meta.url);
11639
12354
  var CLI_VERSION2 = _require3("../package.json").version;
11640
- var GIT_HASH2 = true ? "f9ea608" : "dev";
12355
+ var GIT_HASH2 = true ? "7b97fe6" : "dev";
11641
12356
  function handleConfigCommand(action, rest, json, lang, force) {
11642
12357
  if (action === "init") return cmdConfigInit(lang === "zh" ? "zh" : "en");
11643
12358
  if (action === "show") return cmdConfigShow(json);
@@ -12396,6 +13111,36 @@ function handleEarnDcdCommand(run, action, v, json) {
12396
13111
  errorLine("Valid: pairs, products, quote-and-buy, redeem-execute, order, orders");
12397
13112
  process.exitCode = 1;
12398
13113
  }
13114
+ function handleNewsCommand(run, action, rest, v, json) {
13115
+ const limit = v.limit !== void 0 ? Number(v.limit) : void 0;
13116
+ const begin = v.begin !== void 0 ? Number(v.begin) : void 0;
13117
+ const end = v.end !== void 0 ? Number(v.end) : void 0;
13118
+ const language = v.lang;
13119
+ const detailLvl = v["detail-lvl"];
13120
+ const after = v.after;
13121
+ const period = v.period;
13122
+ const points = v.points !== void 0 ? Number(v.points) : 24;
13123
+ const sortBy = v["sort-by"];
13124
+ const searchOpts = { coins: v.coins, importance: v.importance, sentiment: v.sentiment, sortBy, begin, end, language, detailLvl, limit, after, json };
13125
+ const listOpts = { coins: v.coins, importance: v.importance, begin, end, language, detailLvl, limit, after, json };
13126
+ const dispatch = {
13127
+ latest: () => cmdNewsLatest(run, listOpts),
13128
+ important: () => cmdNewsImportant(run, { coins: v.coins, begin, end, language, detailLvl, limit, json }),
13129
+ "by-coin": () => cmdNewsByCoin(run, v.coins ?? rest[0], { importance: v.importance, begin, end, language, detailLvl, limit, json }),
13130
+ search: () => cmdNewsSearch(run, v.keyword ?? rest[0], searchOpts),
13131
+ detail: () => cmdNewsDetail(run, rest[0], { language, json }),
13132
+ domains: () => cmdNewsDomains(run, { json }),
13133
+ "coin-sentiment": () => cmdNewsCoinSentiment(run, v.coins ?? rest[0], { period, json }),
13134
+ "coin-trend": () => cmdNewsCoinTrend(run, rest[0], { period, points, json }),
13135
+ "by-sentiment": () => cmdNewsSearch(run, "", { ...searchOpts, sentiment: v.sentiment ?? rest[0], sortBy: sortBy ?? "latest" }),
13136
+ "sentiment-rank": () => cmdNewsSentimentRank(run, { period, sortBy, limit, json })
13137
+ };
13138
+ const handler = dispatch[action];
13139
+ if (handler) return handler();
13140
+ process.stderr.write(`Unknown news command: ${action}
13141
+ `);
13142
+ process.exitCode = 1;
13143
+ }
12399
13144
  function outputResult(result, json) {
12400
13145
  if (json) {
12401
13146
  outputLine(JSON.stringify(result, null, 2));
@@ -12429,15 +13174,16 @@ async function main() {
12429
13174
  const json = v.json ?? false;
12430
13175
  if (module === "config") return handleConfigCommand(action, rest, json, v.lang, v.force);
12431
13176
  if (module === "setup") return handleSetupCommand(v);
13177
+ if (module === "upgrade") return cmdUpgrade(CLI_VERSION2, { beta: v.beta, check: v.check, force: v.force }, json);
12432
13178
  if (module === "diagnose") {
12433
13179
  let config2;
12434
13180
  try {
12435
- config2 = loadProfileConfig({ profile: v.profile, demo: v.demo, verbose: v.verbose, userAgent: `okx-trade-cli/${CLI_VERSION2}`, sourceTag: "CLI" });
13181
+ config2 = loadProfileConfig({ profile: v.profile, demo: v.demo, live: v.live, verbose: v.verbose, userAgent: `okx-trade-cli/${CLI_VERSION2}`, sourceTag: "CLI" });
12436
13182
  } catch {
12437
13183
  }
12438
13184
  return cmdDiagnose(config2, v.profile ?? "default", { mcp: v.mcp, cli: v.cli, all: v.all, output: v.output });
12439
13185
  }
12440
- const config = loadProfileConfig({ profile: v.profile, demo: v.demo, verbose: v.verbose, userAgent: `okx-trade-cli/${CLI_VERSION2}`, sourceTag: "CLI" });
13186
+ const config = loadProfileConfig({ profile: v.profile, demo: v.demo, live: v.live, verbose: v.verbose, userAgent: `okx-trade-cli/${CLI_VERSION2}`, sourceTag: "CLI" });
12441
13187
  const client = new OkxRestClient(config);
12442
13188
  const baseRunner = createToolRunner(client, config);
12443
13189
  const writeToolNames = new Set(allToolSpecs().filter((t) => t.isWrite).map((t) => t.name));
@@ -12455,6 +13201,7 @@ async function main() {
12455
13201
  swap: () => handleSwapCommand(run, action, rest, v, json),
12456
13202
  futures: () => handleFuturesCommand(run, action, rest, v, json),
12457
13203
  option: () => handleOptionCommand(run, action, rest, v, json),
13204
+ news: () => handleNewsCommand(run, action, rest, v, json),
12458
13205
  bot: () => handleBotCommand(run, action, rest, v, json),
12459
13206
  earn: () => handleEarnCommand(run, action, rest, v, json)
12460
13207
  };
@@ -12483,6 +13230,7 @@ export {
12483
13230
  handleMarketCommand,
12484
13231
  handleMarketDataCommand,
12485
13232
  handleMarketPublicCommand,
13233
+ handleNewsCommand,
12486
13234
  handleOptionAlgoCommand,
12487
13235
  handleOptionCommand,
12488
13236
  handleSetupCommand,