@okx_ai/okx-trade-cli 1.3.8-beta.3 → 1.3.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 +339 -68
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2506,56 +2506,6 @@ function resolveIndicatorCode(name) {
|
|
|
2506
2506
|
const lower = name.toLowerCase();
|
|
2507
2507
|
return INDICATOR_CODE_OVERRIDES[lower] ?? name.toUpperCase().replace(/-/g, "_");
|
|
2508
2508
|
}
|
|
2509
|
-
var DEFAULT_INDICATOR_PARAMS = {
|
|
2510
|
-
// Moving Averages — PRD example default is [14]
|
|
2511
|
-
ma: [14],
|
|
2512
|
-
ema: [14],
|
|
2513
|
-
wma: [14],
|
|
2514
|
-
dema: [14],
|
|
2515
|
-
tema: [14],
|
|
2516
|
-
zlema: [14],
|
|
2517
|
-
hma: [14],
|
|
2518
|
-
kama: [14],
|
|
2519
|
-
// Trend
|
|
2520
|
-
macd: [12, 26, 9],
|
|
2521
|
-
adx: [14],
|
|
2522
|
-
aroon: [14],
|
|
2523
|
-
cci: [20],
|
|
2524
|
-
dpo: [20],
|
|
2525
|
-
// Momentum
|
|
2526
|
-
rsi: [14],
|
|
2527
|
-
"stoch-rsi": [14],
|
|
2528
|
-
stoch: [14, 3, 3],
|
|
2529
|
-
roc: [12],
|
|
2530
|
-
mom: [10],
|
|
2531
|
-
ppo: [12, 26, 9],
|
|
2532
|
-
trix: [15],
|
|
2533
|
-
uo: [7, 14, 28],
|
|
2534
|
-
wr: [14],
|
|
2535
|
-
// Volatility
|
|
2536
|
-
bb: [20, 2],
|
|
2537
|
-
bbwidth: [20, 2],
|
|
2538
|
-
bbpct: [20, 2],
|
|
2539
|
-
atr: [14],
|
|
2540
|
-
keltner: [20, 2],
|
|
2541
|
-
donchian: [20],
|
|
2542
|
-
hv: [20],
|
|
2543
|
-
stddev: [20],
|
|
2544
|
-
// Volume
|
|
2545
|
-
mvwap: [20],
|
|
2546
|
-
cmf: [20],
|
|
2547
|
-
mfi: [14],
|
|
2548
|
-
// Custom
|
|
2549
|
-
kdj: [9, 3, 3],
|
|
2550
|
-
supertrend: [10, 3]
|
|
2551
|
-
};
|
|
2552
|
-
function getDefaultIndicatorParams(name) {
|
|
2553
|
-
const lower = name.toLowerCase();
|
|
2554
|
-
const direct = DEFAULT_INDICATOR_PARAMS[lower];
|
|
2555
|
-
if (direct !== void 0) return direct;
|
|
2556
|
-
const code = resolveIndicatorCode(lower);
|
|
2557
|
-
return DEFAULT_INDICATOR_PARAMS[code.toLowerCase()];
|
|
2558
|
-
}
|
|
2559
2509
|
function validateIndicatorName(name) {
|
|
2560
2510
|
const lower = name.toLowerCase();
|
|
2561
2511
|
if (VALID_INDICATOR_NAMES.has(lower)) return;
|
|
@@ -2599,7 +2549,7 @@ function registerIndicatorTools() {
|
|
|
2599
2549
|
params: {
|
|
2600
2550
|
type: "array",
|
|
2601
2551
|
items: { type: "number" },
|
|
2602
|
-
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).
|
|
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."
|
|
2603
2553
|
},
|
|
2604
2554
|
returnList: {
|
|
2605
2555
|
type: "boolean",
|
|
@@ -2733,6 +2683,203 @@ var MODULE_DESCRIPTIONS = {
|
|
|
2733
2683
|
upgrade: "Upgrade okx CLI and MCP server to the latest stable version",
|
|
2734
2684
|
skill: SKILLS_MARKETPLACE_DESC
|
|
2735
2685
|
};
|
|
2686
|
+
var AGGREGATE_ENDPOINT = "/api/v5/aigc/forward/balance-aggregate";
|
|
2687
|
+
var TRADING_ENDPOINT = "/api/v5/account/balance";
|
|
2688
|
+
var FUNDING_ENDPOINT = "/api/v5/asset/balances";
|
|
2689
|
+
var VALUATION_ENDPOINT = "/api/v5/asset/asset-valuation";
|
|
2690
|
+
function parseParams(rawArgs) {
|
|
2691
|
+
const args = asRecord(rawArgs);
|
|
2692
|
+
const accounts = readString(args, "accounts") ?? "trading,funding";
|
|
2693
|
+
return {
|
|
2694
|
+
ccy: readString(args, "ccy"),
|
|
2695
|
+
accounts,
|
|
2696
|
+
requestedAccounts: accounts.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean),
|
|
2697
|
+
showValuation: readBoolean(args, "showValuation") ?? true,
|
|
2698
|
+
valuationCcy: readString(args, "valuationCcy") ?? "USDT",
|
|
2699
|
+
preferParallel: readBoolean(args, "preferParallel") ?? false
|
|
2700
|
+
};
|
|
2701
|
+
}
|
|
2702
|
+
function normalizeSubError(error) {
|
|
2703
|
+
if (!error || typeof error !== "object") {
|
|
2704
|
+
return void 0;
|
|
2705
|
+
}
|
|
2706
|
+
const e = error;
|
|
2707
|
+
return {
|
|
2708
|
+
code: e["code"] === void 0 || e["code"] === null ? "UNKNOWN" : String(e["code"]),
|
|
2709
|
+
msg: typeof e["msg"] === "string" ? e["msg"] : String(e["msg"] ?? "")
|
|
2710
|
+
};
|
|
2711
|
+
}
|
|
2712
|
+
function toIsoTimestamp(value, fallbackMs) {
|
|
2713
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
2714
|
+
return new Date(value).toISOString();
|
|
2715
|
+
}
|
|
2716
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
2717
|
+
return value;
|
|
2718
|
+
}
|
|
2719
|
+
return new Date(fallbackMs).toISOString();
|
|
2720
|
+
}
|
|
2721
|
+
function normalizeAggregate(agg, params, startTime) {
|
|
2722
|
+
const result = {};
|
|
2723
|
+
const trading = agg["trading"];
|
|
2724
|
+
if (trading) {
|
|
2725
|
+
result.trading = compactObject({
|
|
2726
|
+
available: trading["available"] ?? false,
|
|
2727
|
+
totalEq: trading["totalEq"],
|
|
2728
|
+
adjEq: trading["adjEq"],
|
|
2729
|
+
details: Array.isArray(trading["details"]) ? trading["details"] : [],
|
|
2730
|
+
error: normalizeSubError(trading["error"])
|
|
2731
|
+
});
|
|
2732
|
+
}
|
|
2733
|
+
const funding = agg["funding"];
|
|
2734
|
+
if (funding) {
|
|
2735
|
+
result.funding = compactObject({
|
|
2736
|
+
available: funding["available"] ?? false,
|
|
2737
|
+
details: Array.isArray(funding["details"]) ? funding["details"] : [],
|
|
2738
|
+
error: normalizeSubError(funding["error"])
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
const valuation = agg["valuation"];
|
|
2742
|
+
if (valuation) {
|
|
2743
|
+
result.valuation = compactObject({
|
|
2744
|
+
available: valuation["available"] ?? false,
|
|
2745
|
+
valuationCcy: valuation["valuationCcy"] ?? params.valuationCcy,
|
|
2746
|
+
totalBal: valuation["totalBal"] ?? "0",
|
|
2747
|
+
details: Array.isArray(valuation["details"]) ? valuation["details"] : [],
|
|
2748
|
+
error: normalizeSubError(valuation["error"])
|
|
2749
|
+
});
|
|
2750
|
+
}
|
|
2751
|
+
const meta = agg["meta"] ?? {};
|
|
2752
|
+
result.meta = compactObject({
|
|
2753
|
+
requestedAt: toIsoTimestamp(meta["requestedAt"], startTime),
|
|
2754
|
+
elapsedMs: typeof meta["elapsedMs"] === "number" ? meta["elapsedMs"] : Date.now() - startTime,
|
|
2755
|
+
partialFailure: Boolean(meta["partialFailure"]),
|
|
2756
|
+
site: typeof meta["site"] === "string" ? meta["site"] : void 0,
|
|
2757
|
+
source: "aggregate"
|
|
2758
|
+
});
|
|
2759
|
+
return result;
|
|
2760
|
+
}
|
|
2761
|
+
async function queryAggregate(context, params, startTime) {
|
|
2762
|
+
const resp = await context.client.privateGet(
|
|
2763
|
+
AGGREGATE_ENDPOINT,
|
|
2764
|
+
compactObject({
|
|
2765
|
+
ccy: params.ccy,
|
|
2766
|
+
accounts: params.accounts,
|
|
2767
|
+
showValuation: params.showValuation,
|
|
2768
|
+
valuationCcy: params.valuationCcy
|
|
2769
|
+
}),
|
|
2770
|
+
privateRateLimit("account_get_balance_all", 5)
|
|
2771
|
+
);
|
|
2772
|
+
const data = resp.data;
|
|
2773
|
+
const agg = Array.isArray(data) ? data[0] : void 0;
|
|
2774
|
+
if (!agg || agg["trading"] === void 0 && agg["funding"] === void 0) {
|
|
2775
|
+
throw new OkxApiError("Aggregate endpoint returned no usable data", {
|
|
2776
|
+
code: "AGG_EMPTY",
|
|
2777
|
+
endpoint: `GET ${AGGREGATE_ENDPOINT}`
|
|
2778
|
+
});
|
|
2779
|
+
}
|
|
2780
|
+
return normalizeAggregate(agg, params, startTime);
|
|
2781
|
+
}
|
|
2782
|
+
var REQUESTED_KEYS = /* @__PURE__ */ new Set(["trading", "funding"]);
|
|
2783
|
+
function buildBalanceTasks(context, params) {
|
|
2784
|
+
const { ccy, requestedAccounts, showValuation, valuationCcy } = params;
|
|
2785
|
+
const tasks = [];
|
|
2786
|
+
if (requestedAccounts.includes("trading")) {
|
|
2787
|
+
tasks.push({
|
|
2788
|
+
key: "trading",
|
|
2789
|
+
run: () => context.client.privateGet(TRADING_ENDPOINT, compactObject({ ccy }), privateRateLimit("account_get_balance", 10)).then((resp) => resp.data)
|
|
2790
|
+
});
|
|
2791
|
+
}
|
|
2792
|
+
if (requestedAccounts.includes("funding")) {
|
|
2793
|
+
tasks.push({
|
|
2794
|
+
key: "funding",
|
|
2795
|
+
run: () => context.client.privateGet(FUNDING_ENDPOINT, compactObject({ ccy }), privateRateLimit("account_get_asset_balance", 6)).then((resp) => resp.data)
|
|
2796
|
+
});
|
|
2797
|
+
}
|
|
2798
|
+
if (showValuation) {
|
|
2799
|
+
tasks.push({
|
|
2800
|
+
key: "valuation",
|
|
2801
|
+
run: () => context.client.privateGet(VALUATION_ENDPOINT, { ccy: valuationCcy }, privateRateLimit("account_get_asset_valuation", 1)).then((resp) => resp.data)
|
|
2802
|
+
});
|
|
2803
|
+
}
|
|
2804
|
+
return tasks;
|
|
2805
|
+
}
|
|
2806
|
+
async function settleBalanceTasks(tasks) {
|
|
2807
|
+
return Promise.all(
|
|
2808
|
+
tasks.map(async (task) => {
|
|
2809
|
+
try {
|
|
2810
|
+
return { key: task.key, data: await task.run() };
|
|
2811
|
+
} catch (error) {
|
|
2812
|
+
return { key: task.key, error };
|
|
2813
|
+
}
|
|
2814
|
+
})
|
|
2815
|
+
);
|
|
2816
|
+
}
|
|
2817
|
+
function buildSuccessSection(key, data, valuationCcy) {
|
|
2818
|
+
const rows = Array.isArray(data) ? data : [];
|
|
2819
|
+
const first = rows[0];
|
|
2820
|
+
if (key === "funding") {
|
|
2821
|
+
return { available: true, details: rows };
|
|
2822
|
+
}
|
|
2823
|
+
if (key === "valuation") {
|
|
2824
|
+
return { available: true, valuationCcy, totalBal: first?.["totalBal"] ?? "0", details: rows };
|
|
2825
|
+
}
|
|
2826
|
+
return {
|
|
2827
|
+
available: true,
|
|
2828
|
+
totalEq: first?.["totalEq"] ?? "0",
|
|
2829
|
+
adjEq: first?.["adjEq"] ?? "0",
|
|
2830
|
+
details: first && Array.isArray(first["details"]) ? first["details"] : []
|
|
2831
|
+
};
|
|
2832
|
+
}
|
|
2833
|
+
function buildErrorSection(error) {
|
|
2834
|
+
return {
|
|
2835
|
+
available: false,
|
|
2836
|
+
error: {
|
|
2837
|
+
code: error instanceof OkxApiError ? error.code ?? "UNKNOWN" : "UNKNOWN",
|
|
2838
|
+
msg: error.message
|
|
2839
|
+
}
|
|
2840
|
+
};
|
|
2841
|
+
}
|
|
2842
|
+
async function queryParallel(context, params, startTime) {
|
|
2843
|
+
const tasks = buildBalanceTasks(context, params);
|
|
2844
|
+
const outcomes = await settleBalanceTasks(tasks);
|
|
2845
|
+
const authFailure = outcomes.find((o) => o.error instanceof AuthenticationError);
|
|
2846
|
+
if (authFailure?.error) {
|
|
2847
|
+
throw authFailure.error;
|
|
2848
|
+
}
|
|
2849
|
+
const result = {};
|
|
2850
|
+
for (const outcome of outcomes) {
|
|
2851
|
+
result[outcome.key] = outcome.error ? buildErrorSection(outcome.error) : buildSuccessSection(outcome.key, outcome.data, params.valuationCcy);
|
|
2852
|
+
}
|
|
2853
|
+
const requestedCount = tasks.filter((t) => REQUESTED_KEYS.has(t.key)).length;
|
|
2854
|
+
const requestedFailures = outcomes.filter((o) => o.error && REQUESTED_KEYS.has(o.key)).length;
|
|
2855
|
+
if (requestedCount > 0 && requestedFailures >= requestedCount) {
|
|
2856
|
+
throw new OkxApiError("Both balance queries failed", { code: "-30001" });
|
|
2857
|
+
}
|
|
2858
|
+
const site = typeof context.config?.site === "string" ? context.config.site : void 0;
|
|
2859
|
+
result.meta = compactObject({
|
|
2860
|
+
requestedAt: new Date(startTime).toISOString(),
|
|
2861
|
+
elapsedMs: Date.now() - startTime,
|
|
2862
|
+
partialFailure: requestedFailures > 0,
|
|
2863
|
+
site,
|
|
2864
|
+
source: "fallback"
|
|
2865
|
+
});
|
|
2866
|
+
return result;
|
|
2867
|
+
}
|
|
2868
|
+
async function buildBalanceAll(rawArgs, context) {
|
|
2869
|
+
const params = parseParams(rawArgs);
|
|
2870
|
+
const startTime = Date.now();
|
|
2871
|
+
if (params.preferParallel) {
|
|
2872
|
+
return queryParallel(context, params, startTime);
|
|
2873
|
+
}
|
|
2874
|
+
try {
|
|
2875
|
+
return await queryAggregate(context, params, startTime);
|
|
2876
|
+
} catch (error) {
|
|
2877
|
+
if (error instanceof AuthenticationError) {
|
|
2878
|
+
throw error;
|
|
2879
|
+
}
|
|
2880
|
+
return queryParallel(context, params, startTime);
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2736
2883
|
function registerAccountTools() {
|
|
2737
2884
|
return [
|
|
2738
2885
|
{
|
|
@@ -3312,6 +3459,39 @@ function registerAccountTools() {
|
|
|
3312
3459
|
);
|
|
3313
3460
|
return normalizeResponse(response);
|
|
3314
3461
|
}
|
|
3462
|
+
},
|
|
3463
|
+
{
|
|
3464
|
+
name: "account_get_balance_all",
|
|
3465
|
+
title: "Get Aggregate Balance Snapshot",
|
|
3466
|
+
module: "account",
|
|
3467
|
+
description: "One-shot snapshot of all OKX assets: trading-account equity + funding-account balances + optional cross-account valuation. Use when the user asks for total assets / net worth / \u603B\u8D44\u4EA7 / all balances. Prefer this over calling account_get_balance + account_get_asset_balance separately. Returns {trading, funding, valuation, meta} with per-section error so partial failures don't block the rest.",
|
|
3468
|
+
isWrite: false,
|
|
3469
|
+
inputSchema: {
|
|
3470
|
+
type: "object",
|
|
3471
|
+
properties: {
|
|
3472
|
+
ccy: {
|
|
3473
|
+
type: "string",
|
|
3474
|
+
description: "Filter by currency, comma-separated (e.g. BTC,ETH). Omit for all. Applied to trading + funding queries only."
|
|
3475
|
+
},
|
|
3476
|
+
accounts: {
|
|
3477
|
+
type: "string",
|
|
3478
|
+
description: "Comma-separated accounts to query: 'trading','funding'. Default 'trading,funding'."
|
|
3479
|
+
},
|
|
3480
|
+
showValuation: {
|
|
3481
|
+
type: "boolean",
|
|
3482
|
+
description: "Include cross-account asset valuation. Default true."
|
|
3483
|
+
},
|
|
3484
|
+
valuationCcy: {
|
|
3485
|
+
type: "string",
|
|
3486
|
+
description: "Currency for valuation (e.g. USDT, BTC). Default USDT. Only effective when showValuation=true."
|
|
3487
|
+
},
|
|
3488
|
+
preferParallel: {
|
|
3489
|
+
type: "boolean",
|
|
3490
|
+
description: "Skip the server-side aggregate endpoint and query trading/funding/valuation directly in parallel. Default false. Use when you need the per-account valuation breakdown or a non-USD valuation currency."
|
|
3491
|
+
}
|
|
3492
|
+
}
|
|
3493
|
+
},
|
|
3494
|
+
handler: (rawArgs, context) => buildBalanceAll(rawArgs, context)
|
|
3315
3495
|
}
|
|
3316
3496
|
];
|
|
3317
3497
|
}
|
|
@@ -14491,7 +14671,7 @@ async function cmdDiagnoseMcp(options = {}) {
|
|
|
14491
14671
|
|
|
14492
14672
|
// src/commands/diagnose.ts
|
|
14493
14673
|
var CLI_VERSION = readCliVersion();
|
|
14494
|
-
var GIT_HASH = true ? "
|
|
14674
|
+
var GIT_HASH = true ? "9beb3ee8" : "dev";
|
|
14495
14675
|
function maskKey2(key) {
|
|
14496
14676
|
if (!key) return "(not set)";
|
|
14497
14677
|
if (key.length <= 8) return "****";
|
|
@@ -15101,6 +15281,11 @@ var CLI_REGISTRY = {
|
|
|
15101
15281
|
usage: "okx account balance [<ccy>]",
|
|
15102
15282
|
description: "Get trading account balance"
|
|
15103
15283
|
},
|
|
15284
|
+
"balance-all": {
|
|
15285
|
+
toolName: "account_get_balance_all",
|
|
15286
|
+
usage: "okx account balance-all [<ccy>] [--accounts trading,funding] [--no-valuation] [--no-aggregate] [--valuationCcy <ccy>]",
|
|
15287
|
+
description: "One-shot snapshot: trading + funding (+ valuation) via server aggregate, auto-fallback to parallel"
|
|
15288
|
+
},
|
|
15104
15289
|
"asset-balance": {
|
|
15105
15290
|
toolName: "account_get_asset_balance",
|
|
15106
15291
|
usage: "okx account asset-balance [--ccy <ccy>]",
|
|
@@ -16679,8 +16864,10 @@ var CLI_OPTIONS = {
|
|
|
16679
16864
|
quoteCcy: { type: "string" },
|
|
16680
16865
|
// account extras
|
|
16681
16866
|
archive: { type: "boolean", default: false },
|
|
16682
|
-
valuation: { type: "boolean"
|
|
16867
|
+
valuation: { type: "boolean" },
|
|
16868
|
+
aggregate: { type: "boolean" },
|
|
16683
16869
|
valuationCcy: { type: "string" },
|
|
16870
|
+
accounts: { type: "string" },
|
|
16684
16871
|
posMode: { type: "string" },
|
|
16685
16872
|
ccy: { type: "string" },
|
|
16686
16873
|
from: { type: "string" },
|
|
@@ -16898,7 +17085,6 @@ function parseCli(argv) {
|
|
|
16898
17085
|
}
|
|
16899
17086
|
|
|
16900
17087
|
// src/commands/market.ts
|
|
16901
|
-
var NO_INDICATOR_VALUES_HINT = "No indicator values returned. This indicator may require a period \u2014 try --params (e.g. --params 14).";
|
|
16902
17088
|
function getData2(result) {
|
|
16903
17089
|
return result.data;
|
|
16904
17090
|
}
|
|
@@ -17105,13 +17291,11 @@ function cmdMarketIndicatorList(json) {
|
|
|
17105
17291
|
}
|
|
17106
17292
|
async function cmdMarketIndicator(run, indicator, instId, opts) {
|
|
17107
17293
|
const params = opts.params ? opts.params.split(",").map((p) => Number(p.trim())).filter((n) => !Number.isNaN(n)) : void 0;
|
|
17108
|
-
const explicit = params && params.length > 0 ? params : void 0;
|
|
17109
|
-
const effectiveParams = explicit ?? getDefaultIndicatorParams(indicator);
|
|
17110
17294
|
const result = await run("market_get_indicator", {
|
|
17111
17295
|
instId,
|
|
17112
17296
|
indicator,
|
|
17113
17297
|
bar: opts.bar,
|
|
17114
|
-
params:
|
|
17298
|
+
params: params && params.length > 0 ? params : void 0,
|
|
17115
17299
|
returnList: opts.list ?? false,
|
|
17116
17300
|
limit: opts.limit,
|
|
17117
17301
|
backtestTime: opts.backtestTime
|
|
@@ -17119,7 +17303,7 @@ async function cmdMarketIndicator(run, indicator, instId, opts) {
|
|
|
17119
17303
|
const outerArray = getData2(result);
|
|
17120
17304
|
if (opts.json) return printJson(outerArray);
|
|
17121
17305
|
if (!outerArray?.length) {
|
|
17122
|
-
|
|
17306
|
+
process.stdout.write("No data\n");
|
|
17123
17307
|
return;
|
|
17124
17308
|
}
|
|
17125
17309
|
const apiCode = resolveIndicatorCode(indicator);
|
|
@@ -17128,18 +17312,16 @@ async function cmdMarketIndicator(run, indicator, instId, opts) {
|
|
|
17128
17312
|
const instData = innerArray?.[0];
|
|
17129
17313
|
const timeframes = instData?.["timeframes"];
|
|
17130
17314
|
if (!timeframes) {
|
|
17131
|
-
|
|
17315
|
+
process.stdout.write(JSON.stringify(outerArray, null, 2) + "\n");
|
|
17132
17316
|
return;
|
|
17133
17317
|
}
|
|
17134
|
-
let printed = false;
|
|
17135
17318
|
for (const [tf, tfData] of Object.entries(timeframes)) {
|
|
17136
17319
|
const indicators = tfData?.["indicators"];
|
|
17137
17320
|
const values = indicators?.[apiCode];
|
|
17138
17321
|
if (!values?.length) continue;
|
|
17139
|
-
|
|
17140
|
-
output(`${instId} | ${apiCode} | ${tf}
|
|
17322
|
+
process.stdout.write(`${instId} | ${apiCode} | ${tf}
|
|
17141
17323
|
`);
|
|
17142
|
-
|
|
17324
|
+
process.stdout.write("-".repeat(40) + "\n");
|
|
17143
17325
|
if (opts.list) {
|
|
17144
17326
|
const tableRows = values.map((entry) => ({
|
|
17145
17327
|
ts: new Date(Number(entry["ts"])).toLocaleString(),
|
|
@@ -17154,7 +17336,6 @@ async function cmdMarketIndicator(run, indicator, instId, opts) {
|
|
|
17154
17336
|
});
|
|
17155
17337
|
}
|
|
17156
17338
|
}
|
|
17157
|
-
if (!printed) outputLine(NO_INDICATOR_VALUES_HINT);
|
|
17158
17339
|
}
|
|
17159
17340
|
async function cmdMarketInstrumentsByCategory(run, opts) {
|
|
17160
17341
|
const result = await run("market_get_instruments_by_category", {
|
|
@@ -17228,9 +17409,8 @@ async function cmdMarketFilter(run, opts) {
|
|
|
17228
17409
|
sortOrder: opts.sortOrder,
|
|
17229
17410
|
limit: opts.limit
|
|
17230
17411
|
});
|
|
17231
|
-
const
|
|
17232
|
-
if (opts.json) return printJson(
|
|
17233
|
-
const data = Array.isArray(raw) ? raw[0] : raw;
|
|
17412
|
+
const data = getData2(result);
|
|
17413
|
+
if (opts.json) return printJson(data);
|
|
17234
17414
|
const rows = data?.["rows"] ?? [];
|
|
17235
17415
|
const total = data?.["total"] ?? rows.length;
|
|
17236
17416
|
outputLine(`Total: ${total}`);
|
|
@@ -17556,6 +17736,88 @@ async function cmdAccountTransfer(run, opts) {
|
|
|
17556
17736
|
const r = data?.[0];
|
|
17557
17737
|
outputLine(`Transfer: ${r?.["transId"]} (${r?.["ccy"]} ${r?.["amt"]})`);
|
|
17558
17738
|
}
|
|
17739
|
+
async function cmdAccountBalanceAll(run, ccy, opts) {
|
|
17740
|
+
const result = await run("account_get_balance_all", {
|
|
17741
|
+
...ccy ? { ccy } : {},
|
|
17742
|
+
...opts.accounts ? { accounts: opts.accounts } : {},
|
|
17743
|
+
showValuation: !opts.noValuation,
|
|
17744
|
+
...opts.preferParallel ? { preferParallel: true } : {},
|
|
17745
|
+
...opts.valuationCcy ? { valuationCcy: opts.valuationCcy } : {}
|
|
17746
|
+
});
|
|
17747
|
+
if (opts.json) return printJson(result);
|
|
17748
|
+
const meta = result.meta;
|
|
17749
|
+
if (meta?.partialFailure) {
|
|
17750
|
+
outputLine("[PARTIAL] Some balance queries failed \u2014 results may be incomplete.");
|
|
17751
|
+
outputLine("");
|
|
17752
|
+
}
|
|
17753
|
+
const trading = result.trading;
|
|
17754
|
+
if (trading) {
|
|
17755
|
+
if (trading.available) {
|
|
17756
|
+
outputLine("=== Trading Account ===");
|
|
17757
|
+
outputLine(`Total Equity: ${String(trading["totalEq"] ?? "0")}`);
|
|
17758
|
+
const details = trading.details ?? [];
|
|
17759
|
+
const rows = details.filter((d) => Number(d["eq"] ?? d["bal"] ?? 0) > 0).map((d) => ({
|
|
17760
|
+
ccy: d["ccy"],
|
|
17761
|
+
equity: d["eq"] ?? d["bal"],
|
|
17762
|
+
available: d["availEq"] ?? d["availBal"],
|
|
17763
|
+
frozen: d["frozenBal"]
|
|
17764
|
+
}));
|
|
17765
|
+
if (rows.length > 0) printTable(rows);
|
|
17766
|
+
} else {
|
|
17767
|
+
const error = trading.error;
|
|
17768
|
+
outputLine(`=== Trading Account === [ERROR: ${error?.msg ?? "unavailable"}]`);
|
|
17769
|
+
}
|
|
17770
|
+
outputLine("");
|
|
17771
|
+
}
|
|
17772
|
+
const funding = result.funding;
|
|
17773
|
+
if (funding) {
|
|
17774
|
+
if (funding.available) {
|
|
17775
|
+
outputLine("=== Funding Account ===");
|
|
17776
|
+
const details = funding.details ?? [];
|
|
17777
|
+
const rows = details.filter((d) => Number(d["bal"] ?? 0) > 0).map((d) => ({
|
|
17778
|
+
ccy: d["ccy"],
|
|
17779
|
+
balance: d["bal"],
|
|
17780
|
+
available: d["availBal"],
|
|
17781
|
+
frozen: d["frozenBal"]
|
|
17782
|
+
}));
|
|
17783
|
+
if (rows.length > 0) printTable(rows);
|
|
17784
|
+
else outputLine("(no non-zero balances)");
|
|
17785
|
+
} else {
|
|
17786
|
+
const error = funding.error;
|
|
17787
|
+
outputLine(`=== Funding Account === [ERROR: ${error?.msg ?? "unavailable"}]`);
|
|
17788
|
+
}
|
|
17789
|
+
outputLine("");
|
|
17790
|
+
}
|
|
17791
|
+
const valuation = result.valuation;
|
|
17792
|
+
if (valuation) {
|
|
17793
|
+
if (valuation.available) {
|
|
17794
|
+
outputLine(`=== Valuation (${String(valuation.valuationCcy ?? "USDT")}) ===`);
|
|
17795
|
+
printKv({ totalBal: valuation.totalBal });
|
|
17796
|
+
const details = valuation.details ?? [];
|
|
17797
|
+
if (details.length > 0) {
|
|
17798
|
+
const first = details[0];
|
|
17799
|
+
const breakdown = first?.["details"] ?? {};
|
|
17800
|
+
if (Object.keys(breakdown).length > 0) {
|
|
17801
|
+
printKv(breakdown);
|
|
17802
|
+
}
|
|
17803
|
+
}
|
|
17804
|
+
} else {
|
|
17805
|
+
const error = valuation.error;
|
|
17806
|
+
outputLine(`=== Valuation === [ERROR: ${error?.msg ?? "unavailable"}]`);
|
|
17807
|
+
}
|
|
17808
|
+
}
|
|
17809
|
+
const source = meta?.source;
|
|
17810
|
+
if (source) {
|
|
17811
|
+
const site = meta?.site;
|
|
17812
|
+
const elapsed = meta?.elapsedMs;
|
|
17813
|
+
let line = `[source: ${source}`;
|
|
17814
|
+
if (site) line += `, site: ${site}`;
|
|
17815
|
+
if (elapsed !== void 0) line += `, ${String(elapsed)}ms`;
|
|
17816
|
+
line += "]";
|
|
17817
|
+
outputLine("");
|
|
17818
|
+
outputLine(line);
|
|
17819
|
+
}
|
|
17820
|
+
}
|
|
17559
17821
|
function readAuditLogs(logDir, days = 7) {
|
|
17560
17822
|
const entries = [];
|
|
17561
17823
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -21205,7 +21467,7 @@ async function cmdEventCancel(run, opts) {
|
|
|
21205
21467
|
// src/index.ts
|
|
21206
21468
|
var _require3 = createRequire3(import.meta.url);
|
|
21207
21469
|
var CLI_VERSION2 = _require3("../package.json").version;
|
|
21208
|
-
var GIT_HASH2 = true ? "
|
|
21470
|
+
var GIT_HASH2 = true ? "9beb3ee8" : "dev";
|
|
21209
21471
|
function handlePilotCommand(action, json, force, binaryPath) {
|
|
21210
21472
|
if (action === "status") return cmdPilotStatus(json, binaryPath);
|
|
21211
21473
|
if (action === "install") return cmdPilotInstall(json, binaryPath);
|
|
@@ -21392,6 +21654,7 @@ function handleAccountWriteCommand(run, action, v, json) {
|
|
|
21392
21654
|
unknownSubcommand("account", action, [
|
|
21393
21655
|
"audit",
|
|
21394
21656
|
"balance",
|
|
21657
|
+
"balance-all",
|
|
21395
21658
|
"asset-balance",
|
|
21396
21659
|
"positions",
|
|
21397
21660
|
"positions-history",
|
|
@@ -21410,6 +21673,14 @@ function handleAccountCommand(run, action, rest, v, json) {
|
|
|
21410
21673
|
return cmdAccountAudit({ limit: v.limit, tool: v.tool, since: v.since, json });
|
|
21411
21674
|
const limit = v.limit !== void 0 ? Number(v.limit) : void 0;
|
|
21412
21675
|
if (action === "balance") return cmdAccountBalance(run, rest[0], json);
|
|
21676
|
+
if (action === "balance-all")
|
|
21677
|
+
return cmdAccountBalanceAll(run, v.ccy ?? rest[0], {
|
|
21678
|
+
accounts: v.accounts,
|
|
21679
|
+
noValuation: v.valuation === false,
|
|
21680
|
+
preferParallel: v.aggregate === false,
|
|
21681
|
+
valuationCcy: v.valuationCcy,
|
|
21682
|
+
json
|
|
21683
|
+
});
|
|
21413
21684
|
if (action === "asset-balance") return cmdAccountAssetBalance(run, v.ccy, json, v.valuation, v.valuationCcy);
|
|
21414
21685
|
if (action === "positions")
|
|
21415
21686
|
return cmdAccountPositions(run, { instType: v.instType, instId: v.instId, json });
|