@okx_ai/okx-trade-cli 1.2.8-beta.1 → 1.2.8-beta.2

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
@@ -4,7 +4,7 @@
4
4
  import { createRequire as createRequire3 } from "module";
5
5
 
6
6
  // ../core/dist/index.js
7
- import { Agent, ProxyAgent } from "undici";
7
+ import { ProxyAgent } from "undici";
8
8
  import { createHmac } from "crypto";
9
9
  import fs from "fs";
10
10
  import path from "path";
@@ -847,13 +847,6 @@ import * as fs3 from "fs";
847
847
  import * as path3 from "path";
848
848
  import * as os3 from "os";
849
849
  import { execFileSync } from "child_process";
850
- async function resolveDoh(_domain) {
851
- return {
852
- ip: "47.242.161.22",
853
- host: "okexweb.qqhrss.com",
854
- ttl: 120
855
- };
856
- }
857
850
  function getNow() {
858
851
  return (/* @__PURE__ */ new Date()).toISOString();
859
852
  }
@@ -1072,61 +1065,12 @@ var OkxRestClient = class {
1072
1065
  config;
1073
1066
  rateLimiter;
1074
1067
  dispatcher;
1075
- // DoH proxy state (lazy-resolved on first request)
1076
- dohResolverFn;
1077
- dohResolved = false;
1078
- dohNode = null;
1079
- dohAgent = null;
1080
- dohBaseUrl = null;
1081
- /**
1082
- * @param config - OKX API client configuration
1083
- * @param options - Optional overrides (e.g. custom DoH resolver for testing).
1084
- * Pass `{ resolveDoh: null }` to disable DoH entirely.
1085
- */
1086
- constructor(config, options) {
1068
+ constructor(config) {
1087
1069
  this.config = config;
1088
1070
  this.rateLimiter = new RateLimiter(3e4, config.verbose);
1089
1071
  if (config.proxyUrl) {
1090
1072
  this.dispatcher = new ProxyAgent(config.proxyUrl);
1091
1073
  }
1092
- this.dohResolverFn = options?.resolveDoh !== void 0 ? options.resolveDoh : resolveDoh;
1093
- }
1094
- /**
1095
- * Lazily resolve the DoH proxy node on the first request.
1096
- * Skipped entirely when the user has configured proxy_url or DoH is disabled.
1097
- * On failure, silently falls back to direct connection.
1098
- */
1099
- async ensureDoh() {
1100
- if (this.dohResolved || this.dispatcher || !this.dohResolverFn) return;
1101
- this.dohResolved = true;
1102
- try {
1103
- const { hostname, protocol } = new URL(this.config.baseUrl);
1104
- const node = await this.dohResolverFn(hostname);
1105
- if (node) {
1106
- this.dohNode = node;
1107
- this.dohBaseUrl = `${protocol}//${node.host}`;
1108
- this.dohAgent = new Agent({
1109
- connect: {
1110
- lookup: (_hostname, options, callback) => {
1111
- if (options?.all) {
1112
- callback(null, [{ address: node.ip, family: 4 }]);
1113
- } else {
1114
- callback(null, node.ip, 4);
1115
- }
1116
- }
1117
- }
1118
- });
1119
- if (this.config.verbose) {
1120
- vlog(`DoH proxy active: ${hostname} \u2192 ${node.host} (${node.ip}), ttl=${node.ttl}s`);
1121
- }
1122
- }
1123
- } catch (err) {
1124
- if (this.config.verbose) {
1125
- const cause = err instanceof Error ? err.message : String(err);
1126
- vlog(`DoH resolution failed, falling back to direct: ${cause}`);
1127
- }
1128
- this.dohNode = null;
1129
- }
1130
1074
  }
1131
1075
  logRequest(method, url, auth) {
1132
1076
  if (!this.config.verbose) return;
@@ -1270,11 +1214,9 @@ var OkxRestClient = class {
1270
1214
  };
1271
1215
  }
1272
1216
  async request(reqConfig) {
1273
- await this.ensureDoh();
1274
1217
  const queryString = buildQueryString(reqConfig.query);
1275
1218
  const requestPath = queryString.length > 0 ? `${reqConfig.path}?${queryString}` : reqConfig.path;
1276
- const baseUrl = this.dohNode ? this.dohBaseUrl : this.config.baseUrl;
1277
- const url = `${baseUrl}${requestPath}`;
1219
+ const url = `${this.config.baseUrl}${requestPath}`;
1278
1220
  const bodyJson = reqConfig.body ? JSON.stringify(reqConfig.body) : "";
1279
1221
  const timestamp = getNow();
1280
1222
  this.logRequest(reqConfig.method, url, reqConfig.auth);
@@ -1285,9 +1227,7 @@ var OkxRestClient = class {
1285
1227
  "Content-Type": "application/json",
1286
1228
  Accept: "application/json"
1287
1229
  });
1288
- if (this.dohNode) {
1289
- headers.set("User-Agent", "OKX/2.7.2");
1290
- } else if (this.config.userAgent) {
1230
+ if (this.config.userAgent) {
1291
1231
  headers.set("User-Agent", this.config.userAgent);
1292
1232
  }
1293
1233
  if (reqConfig.auth === "private") {
@@ -1307,8 +1247,6 @@ var OkxRestClient = class {
1307
1247
  };
1308
1248
  if (this.dispatcher) {
1309
1249
  fetchOptions.dispatcher = this.dispatcher;
1310
- } else if (this.dohAgent) {
1311
- fetchOptions.dispatcher = this.dohAgent;
1312
1250
  }
1313
1251
  response = await fetch(url, fetchOptions);
1314
1252
  } catch (error) {
@@ -7838,7 +7776,7 @@ async function cmdDiagnoseMcp(options = {}) {
7838
7776
 
7839
7777
  // src/commands/diagnose.ts
7840
7778
  var CLI_VERSION = readCliVersion();
7841
- var GIT_HASH = true ? "b691d23" : "dev";
7779
+ var GIT_HASH = true ? "f9ea608" : "dev";
7842
7780
  function maskKey2(key) {
7843
7781
  if (!key) return "(not set)";
7844
7782
  if (key.length <= 8) return "****";
@@ -9325,14 +9263,17 @@ async function cmdAccountBalance(run, ccy, json) {
9325
9263
  const data = getData2(result);
9326
9264
  if (json) return printJson(data);
9327
9265
  const details = data?.[0]?.["details"] ?? [];
9328
- printTable(
9329
- details.filter((d) => Number(d["eq"]) > 0).map((d) => ({
9330
- currency: d["ccy"],
9331
- equity: d["eq"],
9332
- available: d["availEq"],
9333
- frozen: d["frozenBal"]
9334
- }))
9335
- );
9266
+ const rows = details.filter((d) => Number(d["eq"]) > 0).map((d) => ({
9267
+ currency: d["ccy"],
9268
+ equity: d["eq"],
9269
+ available: d["availEq"],
9270
+ frozen: d["frozenBal"]
9271
+ }));
9272
+ if (rows.length === 0 && data?.[0]) {
9273
+ printTable([{ currency: "Total", equity: data[0]["totalEq"] ?? "0", available: data[0]["adjEq"] ?? "0", frozen: "-" }]);
9274
+ return;
9275
+ }
9276
+ printTable(rows);
9336
9277
  }
9337
9278
  async function cmdAccountAssetBalance(run, ccy, json, showValuation) {
9338
9279
  const result = await run("account_get_asset_balance", {
@@ -9341,14 +9282,17 @@ async function cmdAccountAssetBalance(run, ccy, json, showValuation) {
9341
9282
  });
9342
9283
  const data = result.data ?? [];
9343
9284
  if (json) return printJson(showValuation ? { data, valuation: result.valuation } : data);
9344
- printTable(
9345
- data.filter((r) => Number(r["bal"]) > 0).map((r) => ({
9346
- ccy: r["ccy"],
9347
- bal: r["bal"],
9348
- availBal: r["availBal"],
9349
- frozenBal: r["frozenBal"]
9350
- }))
9351
- );
9285
+ const assetRows = data.filter((r) => Number(r["bal"]) > 0).map((r) => ({
9286
+ ccy: r["ccy"],
9287
+ bal: r["bal"],
9288
+ availBal: r["availBal"],
9289
+ frozenBal: r["frozenBal"]
9290
+ }));
9291
+ if (assetRows.length === 0 && data.length > 0) {
9292
+ outputLine("Total balance: 0");
9293
+ } else {
9294
+ printTable(assetRows);
9295
+ }
9352
9296
  if (showValuation && result.valuation) {
9353
9297
  const valuationData = result.valuation ?? [];
9354
9298
  outputLine("");
@@ -11693,7 +11637,7 @@ async function cmdDcdQuoteAndBuy(run, opts) {
11693
11637
  // src/index.ts
11694
11638
  var _require3 = createRequire3(import.meta.url);
11695
11639
  var CLI_VERSION2 = _require3("../package.json").version;
11696
- var GIT_HASH2 = true ? "b691d23" : "dev";
11640
+ var GIT_HASH2 = true ? "f9ea608" : "dev";
11697
11641
  function handleConfigCommand(action, rest, json, lang, force) {
11698
11642
  if (action === "init") return cmdConfigInit(lang === "zh" ? "zh" : "en");
11699
11643
  if (action === "show") return cmdConfigShow(json);