toobit-trade-cli 1.0.0 → 1.0.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 +2260 -16
- package/package.json +2 -2
- package/src/commands/market.ts +10 -1
- package/src/formatter.ts +39 -1
- package/tsup.config.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toobit-trade-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"toobit": "dist/index.js"
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"clean": "rm -rf dist"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@toobit_agent/agent-toobitkit-core": "workspace:*",
|
|
23
22
|
"smol-toml": "^1.3.0"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
25
|
+
"@toobit_agent/agent-toobitkit-core": "workspace:*",
|
|
26
26
|
"@types/node": "^22.0.0",
|
|
27
27
|
"tsup": "^8.0.0",
|
|
28
28
|
"typescript": "^5.5.0"
|
package/src/commands/market.ts
CHANGED
|
@@ -62,8 +62,17 @@ export async function handleMarketCommand(cli: CliParsed, run: ToolRunner): Prom
|
|
|
62
62
|
case "long-short-ratio":
|
|
63
63
|
result = await run("market_get_long_short_ratio", { symbol: f.symbol, period: f.period ?? "1h" });
|
|
64
64
|
break;
|
|
65
|
+
case "contract-ticker-price":
|
|
66
|
+
result = await run("market_get_contract_ticker_price", { symbol: f.symbol });
|
|
67
|
+
break;
|
|
68
|
+
case "insurance-fund":
|
|
69
|
+
result = await run("market_get_insurance_fund", { symbol: f.symbol });
|
|
70
|
+
break;
|
|
71
|
+
case "risk-limits":
|
|
72
|
+
result = await run("market_get_risk_limits", { symbol: f.symbol });
|
|
73
|
+
break;
|
|
65
74
|
default:
|
|
66
|
-
process.stdout.write(`Unknown market subcommand: ${cli.subcommand}\nAvailable: time, info, ticker, ticker-24hr, depth, trades, klines, candles, book-ticker, mark-price, funding-rate, funding-rate-history, open-interest, index, contract-ticker, long-short-ratio\n`);
|
|
75
|
+
process.stdout.write(`Unknown market subcommand: ${cli.subcommand}\nAvailable: time, info, ticker, ticker-24hr, depth, trades, klines, candles, book-ticker, mark-price, funding-rate, funding-rate-history, open-interest, index, contract-ticker, contract-ticker-price, long-short-ratio, insurance-fund, risk-limits\n`);
|
|
67
76
|
return;
|
|
68
77
|
}
|
|
69
78
|
|
package/src/formatter.ts
CHANGED
|
@@ -1,8 +1,46 @@
|
|
|
1
|
+
function extractRows(value: unknown): unknown[] | null {
|
|
2
|
+
if (Array.isArray(value)) return value;
|
|
3
|
+
if (typeof value === "object" && value !== null) {
|
|
4
|
+
const entries = Object.values(value as Record<string, unknown>);
|
|
5
|
+
for (const v of entries) {
|
|
6
|
+
if (Array.isArray(v)) return v;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
export function formatJson(data: unknown, json: boolean): string {
|
|
2
13
|
if (json) return JSON.stringify(data, null, 2);
|
|
3
14
|
if (data === null || data === undefined) return "No data.";
|
|
4
15
|
if (typeof data !== "object") return String(data);
|
|
5
|
-
|
|
16
|
+
|
|
17
|
+
const record = data as Record<string, unknown>;
|
|
18
|
+
const inner = record.data ?? record;
|
|
19
|
+
|
|
20
|
+
const rows = extractRows(inner);
|
|
21
|
+
if (rows) {
|
|
22
|
+
if (rows.length === 0) return "No data.";
|
|
23
|
+
if (typeof rows[0] === "object" && rows[0] !== null) {
|
|
24
|
+
return formatTable(rows as Record<string, unknown>[]);
|
|
25
|
+
}
|
|
26
|
+
return rows.map(String).join("\n");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof inner === "object" && inner !== null) {
|
|
30
|
+
return formatKv(inner as Record<string, unknown>);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return String(inner);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function formatKv(data: Record<string, unknown>): string {
|
|
37
|
+
const entries = Object.entries(data).filter(([, v]) => v !== undefined && v !== null);
|
|
38
|
+
if (entries.length === 0) return "No data.";
|
|
39
|
+
const maxKey = Math.max(...entries.map(([k]) => k.length));
|
|
40
|
+
return entries.map(([k, v]) => {
|
|
41
|
+
if (typeof v === "object") return `${k.padEnd(maxKey)} ${JSON.stringify(v)}`;
|
|
42
|
+
return `${k.padEnd(maxKey)} ${String(v)}`;
|
|
43
|
+
}).join("\n");
|
|
6
44
|
}
|
|
7
45
|
|
|
8
46
|
export function formatTable(rows: Record<string, unknown>[], columns?: string[]): string {
|