@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,55 +1,58 @@
|
|
|
1
|
-
# Bitget Demo Trading
|
|
1
|
+
# Bitget Demo / Paper Trading
|
|
2
2
|
|
|
3
|
-
Demo Trading lets you trade with virtual funds
|
|
4
|
-
|
|
3
|
+
Demo Trading lets you trade with virtual funds against real market data. Use it to
|
|
4
|
+
test strategies without risking real money.
|
|
5
5
|
|
|
6
6
|
## Prerequisites
|
|
7
7
|
|
|
8
8
|
1. Log in to https://www.bitget.com
|
|
9
|
-
2. Switch to Demo Trading mode (toggle in the top navigation bar)
|
|
9
|
+
2. Switch to **Demo Trading** mode (toggle in the top navigation bar)
|
|
10
10
|
3. Go to **Personal Center → API Key Management**
|
|
11
11
|
4. Create a **Demo API Key** with Trade permissions
|
|
12
|
-
5.
|
|
12
|
+
5. Demo API Keys are completely separate from live keys
|
|
13
13
|
|
|
14
|
-
## Using
|
|
14
|
+
## Using demo mode with `bgc`
|
|
15
15
|
|
|
16
|
-
Set your
|
|
16
|
+
Set your **demo** credentials as the environment variables, then add `--paper-trading`
|
|
17
|
+
to route writes to the Bitget demo environment:
|
|
17
18
|
|
|
18
19
|
```bash
|
|
19
20
|
export BITGET_API_KEY="your-demo-api-key"
|
|
20
21
|
export BITGET_SECRET_KEY="your-demo-secret-key"
|
|
21
22
|
export BITGET_PASSPHRASE="your-demo-passphrase"
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Then add `--paper-trading` flag to any bgc command:
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
bgc --paper-trading account get_account_assets
|
|
24
|
+
# Demo account snapshot
|
|
25
|
+
bgc --paper-trading account_overview
|
|
29
26
|
|
|
30
|
-
#
|
|
31
|
-
bgc --paper-trading
|
|
27
|
+
# Demo spot market buy (qty is quote coin = USDT for a spot market buy)
|
|
28
|
+
bgc --paper-trading order --action place \
|
|
29
|
+
--category SPOT --symbol BTCUSDT --side buy --orderType market --qty 50
|
|
32
30
|
|
|
33
|
-
#
|
|
34
|
-
bgc --paper-trading
|
|
31
|
+
# Demo futures positions
|
|
32
|
+
bgc --paper-trading position --action info --category USDT-FUTURES --symbol BTCUSDT
|
|
35
33
|
|
|
36
|
-
#
|
|
37
|
-
bgc --paper-trading
|
|
34
|
+
# Demo futures order
|
|
35
|
+
bgc --paper-trading order --action place \
|
|
36
|
+
--category USDT-FUTURES --symbol BTCUSDT --side buy --orderType market --qty 0.01
|
|
38
37
|
```
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
`--paper-trading` is mutually exclusive with `--read-only`.
|
|
40
|
+
|
|
41
|
+
## Using demo mode with the MCP server
|
|
41
42
|
|
|
42
|
-
Start the MCP server with
|
|
43
|
+
Start the MCP server with `--paper-trading`; every tool in that session runs in demo mode:
|
|
43
44
|
|
|
44
45
|
```bash
|
|
45
|
-
bitget-mcp --paper-trading --modules
|
|
46
|
+
bitget-agent-mcp --paper-trading --modules market,trade,account
|
|
46
47
|
```
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
(Install: `npm install -g @bitget-ai/bitget-agent-mcp`.)
|
|
49
50
|
|
|
50
|
-
## Important
|
|
51
|
+
## Important caveats
|
|
51
52
|
|
|
52
|
-
- **Demo keys ≠
|
|
53
|
-
- **
|
|
54
|
-
|
|
55
|
-
- **
|
|
53
|
+
- **Demo keys ≠ live keys.** Never mix them. Demo keys only work with `--paper-trading`.
|
|
54
|
+
- **Keep the whole session in one mode.** Don't interleave live and `--paper-trading`
|
|
55
|
+
commands — decide up front and stay consistent.
|
|
56
|
+
- **Virtual funds only.** No real money; reset balances from the Bitget demo dashboard.
|
|
57
|
+
- **Real market data.** Prices reflect live conditions.
|
|
58
|
+
- **All categories supported.** SPOT, MARGIN, and the futures categories all work in demo.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Discovering the Surface with `bgc discover`
|
|
2
|
+
|
|
3
|
+
`bgc` introspects its own live tool surface. Use `discover` instead of guessing
|
|
4
|
+
parameters — it returns the exact, doc-grounded contract for whatever is callable
|
|
5
|
+
right now (it respects `--modules`, `--surface`, and `--read-only`, so it shows
|
|
6
|
+
exactly what you can run).
|
|
7
|
+
|
|
8
|
+
All `discover` output is read-only and needs no credentials.
|
|
9
|
+
|
|
10
|
+
## The four rungs of disclosure
|
|
11
|
+
|
|
12
|
+
Climb only as far as you need.
|
|
13
|
+
|
|
14
|
+
### 1. Map — `bgc discover`
|
|
15
|
+
|
|
16
|
+
Lists the business **domains** and how many verbs each has, plus the `meta` tools
|
|
17
|
+
(`raw`, `discover`). Start here when you don't know where a capability lives.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
bgc discover
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 2. Domain — `bgc discover --domain <d>`
|
|
24
|
+
|
|
25
|
+
Lists the verbs in one domain with one-line descriptions, their risk level, write
|
|
26
|
+
flag, and the catalog operations each one fronts.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
bgc discover --domain trade
|
|
30
|
+
bgc discover --domain funds
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 3. Verb — `bgc discover --tool <verb>`
|
|
34
|
+
|
|
35
|
+
Returns one verb's full input schema and metadata. Two shapes:
|
|
36
|
+
|
|
37
|
+
- **Action-routed verb** (most verbs): you get an `actions` list and a hint to drill
|
|
38
|
+
into a specific action. The top-level schema is the *union* across all actions —
|
|
39
|
+
don't assemble a call from it; go to rung 4 for the exact per-action contract.
|
|
40
|
+
- **Action-less verb** (e.g. `account_overview`): you get an explicit
|
|
41
|
+
`required` / `optional` param split directly — ready to call.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
bgc discover --tool order # action-routed → see actions list
|
|
45
|
+
bgc discover --tool account_overview # action-less → ready-to-call params
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 4. Action — `bgc discover --tool <verb> --action <name>`
|
|
49
|
+
|
|
50
|
+
The authoritative contract: this action's `required` and `optional` params, each
|
|
51
|
+
with `type`, `enum` (allowed values), and a doc-grounded `description`, plus the
|
|
52
|
+
underlying `method`, `path`, `operationId`, `isWrite`, `riskLevel`
|
|
53
|
+
(`read`|`write`|`high`), and `requiresConfirm` (`true` only for the high-risk ops
|
|
54
|
+
that need `--confirm`). **Read this before constructing any non-trivial or any
|
|
55
|
+
trading command.**
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
bgc discover --tool order --action place
|
|
59
|
+
bgc discover --tool position --action closeAll
|
|
60
|
+
bgc discover --tool withdraw --action submit
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Keyword search — `bgc discover --search <q>`
|
|
64
|
+
|
|
65
|
+
When you don't know the domain or verb, search the whole surface (verb names,
|
|
66
|
+
actions, fronts, descriptions). Returns ranked matches and which verb to open next.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bgc discover --search "funding rate"
|
|
70
|
+
bgc discover --search leverage
|
|
71
|
+
bgc discover --search withdraw
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Widening the surface
|
|
75
|
+
|
|
76
|
+
By default the CLI exposes `--modules all` at the **intent** surface (the 16 curated
|
|
77
|
+
verbs). Two ways to see more:
|
|
78
|
+
|
|
79
|
+
- **Hidden to-B modules** (`broker`, `inst_loan`) are NOT in `all` — name them
|
|
80
|
+
explicitly to make them discoverable and callable:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
bgc discover --modules broker --domain broker
|
|
84
|
+
bgc broker --action listSubs --modules broker
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- **`--full` / `--surface full`** also exposes the 1:1 generated tool per catalog
|
|
88
|
+
operation (one tool per raw endpoint) for power/debug use. The intent verbs cover
|
|
89
|
+
every operation, so you rarely need this.
|
|
90
|
+
|
|
91
|
+
## When no verb fits: `raw`
|
|
92
|
+
|
|
93
|
+
Every catalog operation is reachable by id through the `raw` escape hatch, bypassing
|
|
94
|
+
the intent layer. Find the `operationId` from rung 4 (or `commands.md`) and call:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
bgc raw --operationId getTickers --args '{"category":"SPOT","symbol":"BTCUSDT"}'
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`raw` still flows through the same write-safety gate, so high-risk operations via
|
|
101
|
+
`raw` also require `confirm: true` in `--args`.
|
|
102
|
+
|
|
103
|
+
## Typical flow
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# "What can I do with orders, and how do I place one?"
|
|
107
|
+
bgc discover --domain trade # find the `order` verb
|
|
108
|
+
bgc discover --tool order # see its actions
|
|
109
|
+
bgc discover --tool order --action place # get the exact params
|
|
110
|
+
bgc order --action place --category SPOT --symbol BTCUSDT \
|
|
111
|
+
--side buy --orderType market --qty 0.001 --dry-run # preview first
|
|
112
|
+
```
|
|
@@ -1,53 +1,118 @@
|
|
|
1
|
-
# Bitget
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
|
30
|
-
|
|
31
|
-
| `
|
|
32
|
-
| `
|
|
33
|
-
| `
|
|
34
|
-
| `
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
# Bitget Errors (UTA / v3)
|
|
2
|
+
|
|
3
|
+
## Error payload shape
|
|
4
|
+
|
|
5
|
+
On failure, `bgc` writes this JSON to **stderr** and exits **1**:
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{
|
|
9
|
+
"ok": false,
|
|
10
|
+
"error": {
|
|
11
|
+
"type": "ValidationError",
|
|
12
|
+
"category": "param",
|
|
13
|
+
"message": "human-readable what-went-wrong",
|
|
14
|
+
"suggestion": "the concrete next step",
|
|
15
|
+
"retryable": false
|
|
16
|
+
},
|
|
17
|
+
"timestamp": "2026-06-18T09:38:09.514Z"
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
> A high-risk write run without `--confirm` is **not** an error — it returns
|
|
22
|
+
> `{ confirmationRequired: true, ... }` on stdout (exit 0). Likewise `--dry-run`
|
|
23
|
+
> returns `{ dryRun: true, wouldSend, ... }` on stdout. Don't treat these as failures.
|
|
24
|
+
|
|
25
|
+
## Branch on `error.category`
|
|
26
|
+
|
|
27
|
+
The category tells you how to recover without parsing the message:
|
|
28
|
+
|
|
29
|
+
| Category | Meaning | What to do |
|
|
30
|
+
|----------|---------|-----------|
|
|
31
|
+
| `auth` | Bad/missing credentials, signature, permission, IP | Fix credentials/permissions; do **not** retry blindly |
|
|
32
|
+
| `param` | Invalid/missing parameter, bad order/price/qty | Fix the request and resend |
|
|
33
|
+
| `balance` | Insufficient balance or margin | Surface to user — cannot self-heal |
|
|
34
|
+
| `risk` | Account at risk / liquidating | Surface to user — reduce risk first |
|
|
35
|
+
| `rate` | Throttled (too frequent / HTTP 429) | Back off and retry |
|
|
36
|
+
| `network` | Transient server/transport error (5xx, timeout) | Back off and retry |
|
|
37
|
+
| `region` | Geo-restricted | Fall back to another surface |
|
|
38
|
+
| `config` | Account not in UTA mode, unsupported mode switch | Check account mode / config |
|
|
39
|
+
| `unknown` | Uncategorized | Show message + suggestion to user |
|
|
40
|
+
|
|
41
|
+
`error.retryable` is the authoritative retry signal: only retry the identical call
|
|
42
|
+
when it is `true` (rate/network). Everything else needs a change first.
|
|
43
|
+
|
|
44
|
+
## Error types (`error.type`)
|
|
45
|
+
|
|
46
|
+
- `ValidationError` — bad input or a blocked write (category `param`).
|
|
47
|
+
- `ConfigError` — bad configuration / partial credentials (category `config`/`auth`).
|
|
48
|
+
- `AuthenticationError` — signature/key/permission failure (category `auth`).
|
|
49
|
+
- `RateLimitError` — throttled (category `rate`, retryable).
|
|
50
|
+
- `NetworkError` — transport failure/timeout (category `network`, retryable).
|
|
51
|
+
- `BitgetApiError` — a Bitget API error code (see table below).
|
|
52
|
+
|
|
53
|
+
## Curated Bitget API codes
|
|
54
|
+
|
|
55
|
+
A high-confidence subset; uncatalogued codes fall back to type-based classification.
|
|
56
|
+
|
|
57
|
+
### Transport (HTTP status)
|
|
58
|
+
|
|
59
|
+
| Code | Category | Retry | Meaning |
|
|
60
|
+
|------|----------|-------|---------|
|
|
61
|
+
| `429` | rate | yes | Rate limit exceeded — back off and retry |
|
|
62
|
+
| `500`/`502`/`503`/`504` | network | yes | Transient server/upstream error — retry after backoff |
|
|
63
|
+
|
|
64
|
+
### Account & trading (UTA `25xxx`)
|
|
65
|
+
|
|
66
|
+
| Code | Category | Retry | Meaning / fix |
|
|
67
|
+
|------|----------|-------|---------------|
|
|
68
|
+
| `25000` | network | yes | System error — retry |
|
|
69
|
+
| `25001` | network | yes | Operation timed out — retry |
|
|
70
|
+
| `25003` | network | yes | Concurrent operation conflict — retry |
|
|
71
|
+
| `25004` | rate | yes | Operations too frequent — slow down |
|
|
72
|
+
| `25008` | risk | no | Account in liquidation — cannot trade |
|
|
73
|
+
| `25009` | config | no | Unsupported account-mode switch |
|
|
74
|
+
| `25010` | config | no | Unsupported position-mode switch |
|
|
75
|
+
| `25012` | risk | no | Account at risk — add margin / close exposure first |
|
|
76
|
+
| `25110` | config | no | Coin can't be moved into the unified account |
|
|
77
|
+
| `25200` | param | no | Parameter validation failed — re-check the schema |
|
|
78
|
+
| `25202` | balance | no | Insufficient balance — fund the account or reduce size |
|
|
79
|
+
| `25203` | balance | no | Insufficient margin — add margin / lower leverage / reduce size |
|
|
80
|
+
| `25204` | param | no | Order not found — verify orderId/clientOid |
|
|
81
|
+
| `25207` | param | no | Quantity below the minimum — increase `qty` |
|
|
82
|
+
| `25212` | param | no | Duplicate `clientOid` — use a fresh idempotency key |
|
|
83
|
+
| `25236` | param | no | Incorrect open type — check `posSide`/`reduceOnly` vs position mode |
|
|
84
|
+
| `25244` | param | no | Price not a multiple of tick size — round to the price step |
|
|
85
|
+
| `25245` | config | no | Account not in unified (UTA) mode — switch to unified |
|
|
86
|
+
| `25620` | auth | no | No permission for this resource — enable it on the API key |
|
|
87
|
+
|
|
88
|
+
### Auth (`40xxx`) & risk
|
|
89
|
+
|
|
90
|
+
| Code | Category | Retry | Meaning / fix |
|
|
91
|
+
|------|----------|-------|---------------|
|
|
92
|
+
| `40001` | auth | no | ACCESS_KEY empty — set `BITGET_API_KEY` |
|
|
93
|
+
| `40002` | auth | no | SECRET_KEY empty — set `BITGET_SECRET_KEY` |
|
|
94
|
+
| `40003` | auth | no | Signature empty — request not signed |
|
|
95
|
+
| `40006` | auth | no | Invalid ACCESS_KEY — verify the key |
|
|
96
|
+
| `40008` | auth | no | Timestamp expired — sync the local clock |
|
|
97
|
+
| `40009` | auth | no | Signature verification failed — check secret/payload |
|
|
98
|
+
| `40017` | auth | no | Signature parameter check failed — check key/secret/passphrase |
|
|
99
|
+
| `40018` | auth | no | Permission or IP restriction — check perms & IP whitelist |
|
|
100
|
+
| `40034` | param | no | A parameter is invalid/missing — re-check names and values |
|
|
101
|
+
| `40036` | auth | no | API key invalid/revoked — regenerate and update creds |
|
|
102
|
+
| `40042` | auth | no | Restricted institutional sub-account — use a different account |
|
|
103
|
+
| `95001` | risk | no | User being liquidated — wait until it completes |
|
|
104
|
+
|
|
105
|
+
## Missing credentials
|
|
106
|
+
|
|
39
107
|
```bash
|
|
40
108
|
export BITGET_API_KEY="your-key"
|
|
41
109
|
export BITGET_SECRET_KEY="your-secret"
|
|
42
110
|
export BITGET_PASSPHRASE="your-passphrase"
|
|
43
111
|
```
|
|
44
112
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- Funding account: `mix_usdt`
|
|
113
|
+
All three are required together; providing a partial set is a `config` error.
|
|
114
|
+
|
|
115
|
+
## `category` values (the v3 model)
|
|
49
116
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
- Coin-margined perpetuals: `COIN-FUTURES`
|
|
53
|
-
- USDC-margined perpetuals: `USDC-FUTURES`
|
|
117
|
+
`SPOT`, `MARGIN`, `USDT-FUTURES`, `COIN-FUTURES`, `USDC-FUTURES`. There are no
|
|
118
|
+
separate spot/futures modules and no `productType` — one `--category` selects the market.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Trading Safety (UTA / v3)
|
|
2
|
+
|
|
3
|
+
Read this before constructing futures close, TP/SL, cancel-all, or withdrawal
|
|
4
|
+
commands. For the exact parameter contract of any action, always confirm with
|
|
5
|
+
`bgc discover --tool <verb> --action <name>`.
|
|
6
|
+
|
|
7
|
+
## Always preview a risky write
|
|
8
|
+
|
|
9
|
+
Run with `--dry-run` first to see the exact would-send payload, show it to the user,
|
|
10
|
+
then execute. For high-risk operations, the real run also needs `--confirm`.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
bgc order --action place --category USDT-FUTURES --symbol BTCUSDT \
|
|
14
|
+
--side sell --orderType market --qty 0.01 --reduceOnly yes --dry-run
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Closing a position (the #1 mistake)
|
|
18
|
+
|
|
19
|
+
Two ways to close, by whether you want a **market** close (fastest) or to exit **at your
|
|
20
|
+
own price**. Either way, check the position first so you get the side and mode right:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bgc position --action info --category USDT-FUTURES --symbol BTCUSDT
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Market-close ONE position — `position --action close`
|
|
27
|
+
|
|
28
|
+
The direct way to flatten a single position at market. It **hard-requires `--symbol`**
|
|
29
|
+
(so it can never close the whole category by omission), is **high-risk → requires
|
|
30
|
+
`--confirm`**, and in hedge mode also needs `--posSide`:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# one-way mode
|
|
34
|
+
bgc position --action close --category USDT-FUTURES --symbol BTCUSDT --confirm
|
|
35
|
+
|
|
36
|
+
# hedge mode — name the book you're closing
|
|
37
|
+
bgc position --action close --category USDT-FUTURES --symbol BTCUSDT --posSide long --confirm
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
> Omitting `--symbol` is rejected with a clear error — use `closeAll` if you really mean
|
|
41
|
+
> the whole category.
|
|
42
|
+
|
|
43
|
+
### Close at YOUR price — opposite-side `order --action place`
|
|
44
|
+
|
|
45
|
+
To exit at a chosen price (or with a limit) instead of at market, place an order on the
|
|
46
|
+
**opposite side** of the position with `--reduceOnly`. There is no `close` action on the
|
|
47
|
+
`order` verb itself — this is how you close through `order`.
|
|
48
|
+
|
|
49
|
+
#### One-way mode
|
|
50
|
+
|
|
51
|
+
A symbol holds one net position. Close it with the opposite `side` + `--reduceOnly yes`:
|
|
52
|
+
|
|
53
|
+
| Position | `--side` to close | Extra |
|
|
54
|
+
|----------|-------------------|-------|
|
|
55
|
+
| Long | `sell` | `--reduceOnly yes` |
|
|
56
|
+
| Short | `buy` | `--reduceOnly yes` |
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Close a long in one-way mode, at a limit price
|
|
60
|
+
bgc order --action place --category USDT-FUTURES --symbol BTCUSDT \
|
|
61
|
+
--side sell --orderType limit --price 70000 --qty 0.01 --reduceOnly yes
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### Hedge mode
|
|
65
|
+
|
|
66
|
+
Long and short books coexist. Set `--posSide` to the book you are closing and use the
|
|
67
|
+
opposite `--side`:
|
|
68
|
+
|
|
69
|
+
| Position book | `--posSide` | `--side` to close |
|
|
70
|
+
|---------------|-------------|-------------------|
|
|
71
|
+
| Long | `long` | `sell` |
|
|
72
|
+
| Short | `short` | `buy` |
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Close the short book in hedge mode
|
|
76
|
+
bgc order --action place --category USDT-FUTURES --symbol BTCUSDT \
|
|
77
|
+
--side buy --orderType market --qty 0.01 --posSide short
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
> **Selling to "close" a short opens MORE short.** Confirm the position's side before
|
|
81
|
+
> choosing `--side`.
|
|
82
|
+
|
|
83
|
+
### Close EVERYTHING in a category — `position --action closeAll`
|
|
84
|
+
|
|
85
|
+
`position --action closeAll` flattens every position (optionally narrowed by
|
|
86
|
+
`--category` / `--symbol`). It is **high-risk and requires `--confirm`**. When you mean
|
|
87
|
+
just one position, prefer `--action close --symbol`:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
bgc position --action closeAll --category USDT-FUTURES --confirm
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Limit vs market: `--price` is conditionally required
|
|
94
|
+
|
|
95
|
+
- **Limit** orders **require `--price`** — omitting it is rejected.
|
|
96
|
+
- **Market** orders take **no `--price`** (the price is the market).
|
|
97
|
+
- In **hedge mode**, `--posSide` is required on the order.
|
|
98
|
+
|
|
99
|
+
`bgc discover --tool order --action place` reports these under `conditionalRequired` (and
|
|
100
|
+
`requiredWhen` on each field), so you can see the obligation before you send.
|
|
101
|
+
|
|
102
|
+
## Take-profit / stop-loss
|
|
103
|
+
|
|
104
|
+
**Preset at entry** — attach to the opening `order --action place`:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
bgc order --action place --category USDT-FUTURES --symbol BTCUSDT \
|
|
108
|
+
--side buy --orderType limit --price 60000 --qty 0.01 \
|
|
109
|
+
--takeProfit 66000 --stopLoss 57000
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Fine-tune with `--tpTriggerBy` / `--slTriggerBy` (`market`|`mark`), `--tpOrderType` /
|
|
113
|
+
`--slOrderType` (`limit`|`market`), and `--tpLimitPrice` / `--slLimitPrice` (for limit
|
|
114
|
+
TP/SL). Confirm exact fields with `bgc discover --tool order --action place`.
|
|
115
|
+
|
|
116
|
+
**Manage after entry** — use the `strategy_order` verb (trigger/plan orders):
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
bgc discover --tool strategy_order # place | cancel | modify | open | history
|
|
120
|
+
bgc strategy_order --action open --category USDT-FUTURES --symbol BTCUSDT
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Order quantity (`qty`) units — easy to get wrong
|
|
124
|
+
|
|
125
|
+
`qty` means different things by category and side:
|
|
126
|
+
|
|
127
|
+
| Market | `qty` unit |
|
|
128
|
+
|--------|-----------|
|
|
129
|
+
| Spot/Margin — **market BUY** | **quote coin (e.g. USDT)** |
|
|
130
|
+
| Spot/Margin — limit, or market SELL | base coin |
|
|
131
|
+
| USDT-FUTURES / USDC-FUTURES | base coin |
|
|
132
|
+
| COIN-FUTURES | quote coin |
|
|
133
|
+
|
|
134
|
+
> For a spot market buy, `--qty 100` means **100 USDT of BTC**, not 100 BTC. Confirm
|
|
135
|
+
> the user's intent before sizing a market buy.
|
|
136
|
+
|
|
137
|
+
## Cancelling
|
|
138
|
+
|
|
139
|
+
- `order --action cancel` — cancel one order (needs `--orderId` or `--clientOid`).
|
|
140
|
+
- `order --action cancelAll` — **high-risk, requires `--confirm`**. Scope it with
|
|
141
|
+
`--category` / `--symbol` to avoid wiping unrelated orders.
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
bgc order --action cancelAll --category SPOT --symbol BTCUSDT --confirm
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Withdrawals
|
|
148
|
+
|
|
149
|
+
`withdraw --action submit` is **high-risk and requires `--confirm`**. Withdrawals are
|
|
150
|
+
**irreversible**:
|
|
151
|
+
|
|
152
|
+
- Always show the **coin, chain, destination address, and amount** in the confirmation prompt.
|
|
153
|
+
- If the user hasn't named a chain, do not assume one — confirm it explicitly. A wrong
|
|
154
|
+
chain loses the funds.
|
|
155
|
+
- Preview with `--dry-run` and show the `wouldSend` payload before the real `--confirm` run.
|
|
156
|
+
|
|
157
|
+
## High-risk operations (require `--confirm`)
|
|
158
|
+
|
|
159
|
+
`closeAllPositions` · `cancelAllOrders` · `withdrawal` · `brokerSubaccountWithdrawal`
|
|
160
|
+
|
|
161
|
+
Without `--confirm`, these return `{ confirmationRequired: true }` and send nothing —
|
|
162
|
+
that is a normal result, not an error. Surface it to the user, get a yes, then re-run
|
|
163
|
+
with `--confirm`.
|