@bitget-ai/bitget-agent-skill 1.2.0 → 3.0.0
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/CHANGELOG.md +23 -0
- package/README.md +189 -57
- package/VERSION +1 -1
- package/package.json +5 -3
- package/references/auth-setup.md +37 -9
- package/references/commands.md +1903 -774
- package/references/demo-trading.md +31 -28
- package/references/discover-guide.md +112 -0
- package/references/error-codes.md +111 -46
- package/references/trading-safety.md +163 -0
- package/scripts/gen-references.js +241 -45
- package/scripts/install.js +8 -1
- package/skills/SKILL.md +158 -139
- package/references/trading/README.md +0 -36
- package/references/trading/futures-cancel-orders.md +0 -113
- package/references/trading/futures-get-orders.md +0 -155
- package/references/trading/futures-leverage-config.md +0 -184
- package/references/trading/futures-modify-order.md +0 -173
- package/references/trading/futures-place-order.md +0 -429
- package/references/trading/futures-positions.md +0 -154
- package/references/trading/spot-cancel-orders.md +0 -87
- package/references/trading/spot-get-orders.md +0 -120
- package/references/trading/spot-modify-order.md +0 -95
- package/references/trading/spot-place-order.md +0 -166
- package/references/trading/spot-plan-orders.md +0 -160
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Generates references/commands.md from @bitget-ai/bitget-agent-sdk
|
|
2
|
+
// Generates references/commands.md from @bitget-ai/bitget-agent-sdk by walking
|
|
3
|
+
// the SDK's own `discover` surface — the same progressive disclosure an agent
|
|
4
|
+
// uses at runtime. Driving discover (not raw catalog reads) guarantees the
|
|
5
|
+
// static catalog never drifts from what `bgc` actually exposes.
|
|
6
|
+
//
|
|
7
|
+
// Output is the v3 intent surface: 16 curated verbs (incl. the hidden to-B
|
|
8
|
+
// broker/inst_loan), each action's required/optional contract, plus the meta
|
|
9
|
+
// tools. The CLI grammar / global-flags block is the stable `bgc` contract.
|
|
3
10
|
import { writeFileSync, mkdirSync } from "node:fs";
|
|
4
11
|
import { join, dirname } from "node:path";
|
|
5
12
|
import { fileURLToPath } from "node:url";
|
|
@@ -8,63 +15,252 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
8
15
|
const refsDir = join(__dirname, "..", "references");
|
|
9
16
|
mkdirSync(refsDir, { recursive: true });
|
|
10
17
|
|
|
11
|
-
const {
|
|
18
|
+
const {
|
|
19
|
+
loadConfig,
|
|
20
|
+
buildTools,
|
|
21
|
+
MODULES,
|
|
22
|
+
HIDDEN_MODULES,
|
|
23
|
+
HIGH_RISK_OPERATIONS,
|
|
24
|
+
DISCOVER_TOOL_NAME,
|
|
25
|
+
RAW_TOOL_NAME,
|
|
26
|
+
SERVER_VERSION,
|
|
27
|
+
CATALOG_SPEC_VERSION,
|
|
28
|
+
CATALOG_OPERATION_COUNT,
|
|
29
|
+
API_VARIANT,
|
|
30
|
+
} = await import("@bitget-ai/bitget-agent-sdk");
|
|
12
31
|
|
|
13
|
-
|
|
32
|
+
// All modules incl. hidden to-B verbs, intent surface — exactly what `bgc`
|
|
33
|
+
// exposes with `--modules all` plus the explicitly-named hidden ones.
|
|
34
|
+
const config = loadConfig({ modules: MODULES.join(","), surface: "intent", readOnly: false });
|
|
14
35
|
const tools = buildTools(config);
|
|
36
|
+
const discover = tools.find((t) => t.name === DISCOVER_TOOL_NAME);
|
|
37
|
+
const call = async (args) => (await discover.handler(args, {})).data;
|
|
15
38
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
""
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
const hidden = new Set(HIDDEN_MODULES);
|
|
40
|
+
const highRisk = new Set(HIGH_RISK_OPERATIONS);
|
|
41
|
+
const DESC_CAP = 220;
|
|
42
|
+
|
|
43
|
+
// Collapse OpenAPI paragraph descriptions to a single, table-safe line.
|
|
44
|
+
function cell(text) {
|
|
45
|
+
if (text === undefined || text === null) return "";
|
|
46
|
+
let s = String(text).replace(/\s+/g, " ").trim().replace(/\|/g, "\\|");
|
|
47
|
+
if (s.length > DESC_CAP) s = s.slice(0, DESC_CAP - 1) + "…";
|
|
48
|
+
return s;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function enumCell(param) {
|
|
52
|
+
if (!Array.isArray(param.enum) || param.enum.length === 0) return "";
|
|
53
|
+
return param.enum.map((v) => `\`${v}\``).join(" \\| ");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function paramTable(params) {
|
|
57
|
+
if (!params || params.length === 0) return ["_No parameters._", ""];
|
|
58
|
+
const out = ["| Param | Type | Enum | Description |", "|-------|------|------|-------------|"];
|
|
59
|
+
for (const p of params) {
|
|
60
|
+
out.push(`| \`${p.name}\` | ${p.type ?? "any"} | ${enumCell(p)} | ${cell(p.description)} |`);
|
|
61
|
+
}
|
|
62
|
+
out.push("");
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function anchor(name) {
|
|
67
|
+
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function exampleFor(verb, action, required) {
|
|
71
|
+
const parts = [`bgc ${verb}`];
|
|
72
|
+
if (action) parts.push(`--action ${action}`);
|
|
73
|
+
for (const p of required) {
|
|
74
|
+
if (p.name === "action") continue;
|
|
75
|
+
parts.push(`--${p.name} <${p.name}>`);
|
|
76
|
+
}
|
|
77
|
+
return parts.join(" ");
|
|
33
78
|
}
|
|
34
79
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
80
|
+
const lines = [];
|
|
81
|
+
lines.push("# bgc Command Reference (UTA / v3)");
|
|
82
|
+
lines.push("");
|
|
83
|
+
lines.push(
|
|
84
|
+
`Auto-generated from \`@bitget-ai/bitget-agent-sdk\` v${SERVER_VERSION} ` +
|
|
85
|
+
`(OpenAPI spec ${CATALOG_SPEC_VERSION}, ${CATALOG_OPERATION_COUNT} operations, ${API_VARIANT}).`,
|
|
86
|
+
);
|
|
87
|
+
lines.push("Do not edit by hand — run `npm run gen-references`.");
|
|
88
|
+
lines.push("");
|
|
89
|
+
lines.push(
|
|
90
|
+
"This catalog is the **static** mirror of the live surface. For a verb's exact, " +
|
|
91
|
+
"doc-grounded contract at any moment, run `bgc discover --tool <verb> --action <name>`.",
|
|
92
|
+
);
|
|
93
|
+
lines.push("");
|
|
94
|
+
|
|
95
|
+
// ── CLI grammar (the stable `bgc` contract) ─────────────────────────────
|
|
96
|
+
lines.push("## Grammar");
|
|
97
|
+
lines.push("");
|
|
98
|
+
lines.push("```");
|
|
99
|
+
lines.push("bgc <tool> [--action <name>] [--<param> <value> ...] [global flags]");
|
|
100
|
+
lines.push("bgc discover [--domain <d> | --tool <t> [--action <a>] | --search <q>]");
|
|
101
|
+
lines.push("bgc raw --operationId <id> [--args '<json>']");
|
|
102
|
+
lines.push("```");
|
|
103
|
+
lines.push("");
|
|
104
|
+
lines.push(
|
|
105
|
+
"One verb per call. `--action` selects the intent for action-routed verbs. " +
|
|
106
|
+
"Values coerce by shape: `true`/`false` → boolean, a value starting with `[` or `{` → JSON " +
|
|
107
|
+
"(e.g. `--orders '[{...}]'`), everything else stays a string. Output is JSON on stdout " +
|
|
108
|
+
"(exit 0); errors are a JSON payload on stderr (exit 1).",
|
|
109
|
+
);
|
|
110
|
+
lines.push("");
|
|
111
|
+
|
|
112
|
+
// ── Global flags ─────────────────────────────────────────────────────────
|
|
113
|
+
lines.push("## Global flags");
|
|
114
|
+
lines.push("");
|
|
115
|
+
lines.push("| Flag | Effect |");
|
|
116
|
+
lines.push("|------|--------|");
|
|
117
|
+
lines.push("| `--action <name>` | Action for an action-routed verb |");
|
|
118
|
+
lines.push("| `--modules <list>` | Modules to enable (CLI default: `all`). Name a hidden to-B module to expose it, e.g. `--modules broker` |");
|
|
119
|
+
lines.push("| `--surface <mode>` | `intent` (default) or `full` (also expose the 1:1 generated operations) |");
|
|
120
|
+
lines.push("| `--full` | Shorthand for `--surface full` |");
|
|
121
|
+
lines.push("| `--read-only` | Block all writes (mutually exclusive with `--paper-trading`) |");
|
|
122
|
+
lines.push("| `--paper-trading` | Route writes to the Bitget demo environment (needs demo credentials) |");
|
|
123
|
+
lines.push("| `--dry-run` | Preview a write without sending it (maps to `dryRun`) |");
|
|
124
|
+
lines.push("| `--confirm` | Required to execute destructive (high-risk) writes |");
|
|
125
|
+
lines.push("| `--base-url <url>` | Override API base URL (else `BITGET_API_BASE_URL`) |");
|
|
126
|
+
lines.push("| `--timeout <ms>` | Per-request timeout (else `BITGET_TIMEOUT_MS`, default 15000) |");
|
|
127
|
+
lines.push("| `--pretty` | Pretty-print JSON output |");
|
|
128
|
+
lines.push("| `--help`, `--version` | Help / version |");
|
|
129
|
+
lines.push("");
|
|
130
|
+
|
|
131
|
+
// ── Write safety ───────────────────────────────────────────────────────
|
|
132
|
+
lines.push("## Write safety");
|
|
133
|
+
lines.push("");
|
|
134
|
+
lines.push(
|
|
135
|
+
"Every operation is graded **read** < **write** < **high**. Reads run freely. Writes honor " +
|
|
136
|
+
"`--dry-run`, `--read-only`, and `--paper-trading`. **High-risk** operations refuse to run " +
|
|
137
|
+
"without `--confirm` — without it the call returns `{ confirmationRequired: true }` (a normal " +
|
|
138
|
+
"result on stdout, not an error).",
|
|
139
|
+
);
|
|
140
|
+
lines.push("");
|
|
141
|
+
lines.push(`High-risk operations (require \`--confirm\`): ${[...highRisk].map((o) => `\`${o}\``).join(", ")}.`);
|
|
142
|
+
lines.push("");
|
|
143
|
+
lines.push(
|
|
144
|
+
"Common params available on most verbs (not repeated in the tables below): `dryRun`, `confirm` " +
|
|
145
|
+
"(writes); `view` (`summary`|`full`) and `fields` (read normalization / token economy); " +
|
|
146
|
+
"`fetchAll`, `cursor`, `limit` (paginated reads).",
|
|
147
|
+
);
|
|
148
|
+
lines.push("");
|
|
149
|
+
|
|
150
|
+
// ── Walk the surface ─────────────────────────────────────────────────────
|
|
151
|
+
const overview = await call({});
|
|
152
|
+
const verbsByDomain = new Map();
|
|
153
|
+
for (const d of overview.domains) {
|
|
154
|
+
const list = await call({ domain: d.domain });
|
|
155
|
+
verbsByDomain.set(d.domain, list.tools);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Table of contents
|
|
159
|
+
lines.push("## Domains");
|
|
160
|
+
lines.push("");
|
|
161
|
+
for (const d of overview.domains) {
|
|
162
|
+
const verbs = verbsByDomain.get(d.domain);
|
|
163
|
+
const names = verbs.map((v) => `[\`${v.name}\`](#${anchor(v.name)})`).join(", ");
|
|
164
|
+
lines.push(`- **${d.domain}** — ${names}`);
|
|
165
|
+
}
|
|
166
|
+
lines.push(`- **meta** — [\`${RAW_TOOL_NAME}\`](#raw), [\`${DISCOVER_TOOL_NAME}\`](#discover)`);
|
|
167
|
+
lines.push("");
|
|
168
|
+
|
|
169
|
+
// Per domain → per verb
|
|
170
|
+
for (const d of overview.domains) {
|
|
171
|
+
lines.push(`## Domain: ${d.domain}`);
|
|
172
|
+
lines.push("");
|
|
173
|
+
for (const v of verbsByDomain.get(d.domain)) {
|
|
174
|
+
const tool = await call({ tool: v.name });
|
|
175
|
+
lines.push(`### \`${v.name}\``);
|
|
39
176
|
lines.push("");
|
|
40
|
-
|
|
177
|
+
const badges = [`risk: **${v.riskLevel}**`, `write: ${v.isWrite ? "yes" : "no"}`, `auth: ${tool.auth}`];
|
|
178
|
+
lines.push(badges.join(" · "));
|
|
41
179
|
lines.push("");
|
|
42
|
-
|
|
180
|
+
// Hidden to-B modules have domain === module id (broker, instloan); name the
|
|
181
|
+
// module id in the opt-in hint, not the verb name (inst_loan ≠ instloan).
|
|
182
|
+
if (hidden.has(d.domain)) {
|
|
183
|
+
lines.push(`> Hidden to-B verb — opt in with \`--modules ${d.domain}\` (not in \`--modules all\`).`);
|
|
184
|
+
lines.push("");
|
|
185
|
+
}
|
|
186
|
+
lines.push(cell(tool.description));
|
|
43
187
|
lines.push("");
|
|
44
188
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
lines.push(
|
|
189
|
+
if (tool.actions) {
|
|
190
|
+
lines.push(`**Actions:** ${tool.actions.map((a) => `\`${a}\``).join(", ")}`);
|
|
191
|
+
lines.push("");
|
|
192
|
+
for (const action of tool.actions) {
|
|
193
|
+
const c = await call({ tool: v.name, action });
|
|
194
|
+
const danger = highRisk.has(c.operationId) ? " — **[DANGER] requires `--confirm`**" : "";
|
|
195
|
+
lines.push(`#### \`bgc ${v.name} --action ${action}\`${danger}`);
|
|
196
|
+
lines.push("");
|
|
197
|
+
lines.push(`\`${c.method} ${c.path}\` · ${c.auth}${c.isWrite ? " · write" : ""}`);
|
|
198
|
+
lines.push("");
|
|
199
|
+
if (c.summary) {
|
|
200
|
+
lines.push(cell(c.summary));
|
|
201
|
+
lines.push("");
|
|
202
|
+
}
|
|
203
|
+
if (c.required.length > 0) {
|
|
204
|
+
lines.push("Required:");
|
|
205
|
+
lines.push("");
|
|
206
|
+
lines.push(...paramTable(c.required));
|
|
207
|
+
}
|
|
208
|
+
if (c.optional.length > 0) {
|
|
209
|
+
lines.push("Optional:");
|
|
210
|
+
lines.push("");
|
|
211
|
+
lines.push(...paramTable(c.optional));
|
|
212
|
+
}
|
|
213
|
+
if (c.required.length === 0 && c.optional.length === 0) {
|
|
214
|
+
lines.push("_No business parameters._");
|
|
215
|
+
lines.push("");
|
|
216
|
+
}
|
|
217
|
+
lines.push("```bash");
|
|
218
|
+
lines.push(exampleFor(v.name, action, c.required));
|
|
219
|
+
lines.push("```");
|
|
220
|
+
lines.push("");
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
// Action-less verb (composite fan-out or 1:1 op): explicit param split.
|
|
224
|
+
if (tool.params.required.length > 0) {
|
|
225
|
+
lines.push("Required:");
|
|
226
|
+
lines.push("");
|
|
227
|
+
lines.push(...paramTable(tool.params.required));
|
|
55
228
|
}
|
|
229
|
+
lines.push("Optional:");
|
|
230
|
+
lines.push("");
|
|
231
|
+
lines.push(...paramTable(tool.params.optional));
|
|
232
|
+
lines.push("```bash");
|
|
233
|
+
lines.push(exampleFor(v.name, null, tool.params.required));
|
|
234
|
+
lines.push("```");
|
|
56
235
|
lines.push("");
|
|
57
236
|
}
|
|
58
|
-
|
|
59
|
-
lines.push("**Example:**", "```bash");
|
|
60
|
-
const exampleArgs = Object.entries(props)
|
|
61
|
-
.slice(0, 2)
|
|
62
|
-
.map(([k]) => `--${k} <value>`)
|
|
63
|
-
.join(" ");
|
|
64
|
-
lines.push(`bgc ${module} ${tool.name}${exampleArgs ? " " + exampleArgs : ""}`);
|
|
65
|
-
lines.push("```", "");
|
|
66
237
|
}
|
|
67
238
|
}
|
|
68
239
|
|
|
240
|
+
// ── Meta tools ─────────────────────────────────────────────────────────
|
|
241
|
+
lines.push("## Meta tools");
|
|
242
|
+
lines.push("");
|
|
243
|
+
lines.push("### `discover`");
|
|
244
|
+
lines.push("");
|
|
245
|
+
lines.push(
|
|
246
|
+
"Progressive introspection of the live surface. `bgc discover` lists domains; " +
|
|
247
|
+
"`--domain <d>` lists a domain's verbs; `--tool <t>` returns one verb's full schema; " +
|
|
248
|
+
"`--tool <t> --action <a>` returns one action's exact required/optional contract; " +
|
|
249
|
+
"`--search <q>` keyword-searches the whole surface.",
|
|
250
|
+
);
|
|
251
|
+
lines.push("");
|
|
252
|
+
lines.push("### `raw`");
|
|
253
|
+
lines.push("");
|
|
254
|
+
lines.push(
|
|
255
|
+
"Escape hatch to any catalog operation by id, bypassing the intent layer: " +
|
|
256
|
+
"`bgc raw --operationId <id> --args '<json>'`. Use when no verb fronts the operation you need.",
|
|
257
|
+
);
|
|
258
|
+
lines.push("");
|
|
259
|
+
|
|
69
260
|
writeFileSync(join(refsDir, "commands.md"), lines.join("\n"), "utf8");
|
|
70
|
-
|
|
261
|
+
|
|
262
|
+
const verbCount = [...verbsByDomain.values()].reduce((n, v) => n + v.length, 0);
|
|
263
|
+
console.log(
|
|
264
|
+
`Generated references/commands.md — ${overview.domains.length} domains, ${verbCount} verbs ` +
|
|
265
|
+
`(SDK ${SERVER_VERSION}, spec ${CATALOG_SPEC_VERSION}, ${CATALOG_OPERATION_COUNT} ops).`,
|
|
266
|
+
);
|
package/scripts/install.js
CHANGED
|
@@ -38,7 +38,14 @@ const TARGETS = {
|
|
|
38
38
|
},
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
const REF_FILES = [
|
|
41
|
+
const REF_FILES = [
|
|
42
|
+
"commands.md",
|
|
43
|
+
"discover-guide.md",
|
|
44
|
+
"trading-safety.md",
|
|
45
|
+
"error-codes.md",
|
|
46
|
+
"auth-setup.md",
|
|
47
|
+
"demo-trading.md",
|
|
48
|
+
];
|
|
42
49
|
|
|
43
50
|
function installTo(targetKey) {
|
|
44
51
|
const target = TARGETS[targetKey];
|