jaspervault_cli 1.0.26 → 1.0.28
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/README.md +25 -24
- package/dist/bin/jv.js +6 -2
- package/dist/bin/jv.js.map +1 -1
- package/dist/src/client.js +28 -1
- package/dist/src/client.js.map +1 -1
- package/dist/src/commands/deposit.js +129 -125
- package/dist/src/commands/deposit.js.map +1 -1
- package/dist/src/commands/install.d.ts +2 -0
- package/dist/src/commands/install.js +184 -0
- package/dist/src/commands/install.js.map +1 -0
- package/dist/src/commands/limit-order.js +7 -0
- package/dist/src/commands/limit-order.js.map +1 -1
- package/dist/src/commands/mcp.d.ts +2 -0
- package/dist/src/commands/mcp.js +10 -0
- package/dist/src/commands/mcp.js.map +1 -0
- package/dist/src/commands/sl.js +12 -2
- package/dist/src/commands/sl.js.map +1 -1
- package/dist/src/commands/tp.js +12 -2
- package/dist/src/commands/tp.js.map +1 -1
- package/dist/src/commands/vault.js +111 -87
- package/dist/src/commands/vault.js.map +1 -1
- package/dist/src/commands/withdraw.d.ts +2 -0
- package/dist/src/commands/withdraw.js +114 -0
- package/dist/src/commands/withdraw.js.map +1 -0
- package/dist/src/mcp/executor.d.ts +23 -0
- package/dist/src/mcp/executor.js +75 -0
- package/dist/src/mcp/executor.js.map +1 -0
- package/dist/src/mcp/index.d.ts +1 -0
- package/dist/src/mcp/index.js +58 -0
- package/dist/src/mcp/index.js.map +1 -0
- package/dist/src/mcp/installer.d.ts +9 -0
- package/dist/src/mcp/installer.js +66 -0
- package/dist/src/mcp/installer.js.map +1 -0
- package/dist/src/mcp/tools.d.ts +15 -0
- package/dist/src/mcp/tools.js +250 -0
- package/dist/src/mcp/tools.js.map +1 -0
- package/dist/src/services/order-signer.js +1 -1
- package/dist/src/services/order-signer.js.map +1 -1
- package/dist/src/services/session-poller.d.ts +12 -0
- package/dist/src/services/session-poller.js +57 -0
- package/dist/src/services/session-poller.js.map +1 -0
- package/dist/src/templates/skill-body.d.ts +3 -1
- package/dist/src/templates/skill-body.js +30 -497
- package/dist/src/templates/skill-body.js.map +1 -1
- package/dist/src/templates/skill-content/SKILL.core.md +51 -0
- package/dist/src/templates/skill-content/frontmatter/claude.md +4 -0
- package/dist/src/templates/skill-content/frontmatter/cursor.md +0 -0
- package/dist/src/templates/skill-content/frontmatter/openclaw.md +11 -0
- package/dist/src/templates/skill-content/references/onboarding.md +124 -0
- package/dist/src/templates/skill-content/references/queries.md +294 -0
- package/dist/src/templates/skill-content/references/trading.md +274 -0
- package/dist/src/templates/skill-content/scripts/check-init.sh +4 -0
- package/dist/src/types.d.ts +13 -6
- package/dist/src/utils/config.d.ts +1 -1
- package/dist/src/utils/config.js +1 -1
- package/dist/src/utils/config.js.map +1 -1
- package/dist/src/utils/endpoints.d.ts +3 -0
- package/dist/src/utils/endpoints.js +5 -0
- package/dist/src/utils/endpoints.js.map +1 -1
- package/package.json +4 -6
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Onboarding Reference
|
|
2
|
+
|
|
3
|
+
## 1. Wallet Initialization (`jv vault setup`)
|
|
4
|
+
|
|
5
|
+
Initialize the JasperVault delegation wallet via hosted web page. The user signs in their browser — no private key needed.
|
|
6
|
+
|
|
7
|
+
### Syntax
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
jv vault setup [--network <name>] [--vault-types <types>] [--timeout <seconds>] [--pretty]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Options
|
|
14
|
+
|
|
15
|
+
| Option | Required | Default | Description |
|
|
16
|
+
|--------|----------|---------|-------------|
|
|
17
|
+
| `--network <name>` | No | `base_uat` | Network name |
|
|
18
|
+
| `--vault-types <types>` | No | `33,37` | Comma-separated vault types |
|
|
19
|
+
| `--timeout <seconds>` | No | `900` | Polling timeout |
|
|
20
|
+
| `--pretty` | No | — | Pretty-print JSON output |
|
|
21
|
+
|
|
22
|
+
### Step-by-Step Flow
|
|
23
|
+
|
|
24
|
+
1. Run the command:
|
|
25
|
+
```
|
|
26
|
+
jv vault setup --pretty
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
2. The **first JSON output** contains the session URL:
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"status": "session_created",
|
|
33
|
+
"sessionId": "abc123",
|
|
34
|
+
"url": "https://trading.jaspervault.pro/cli-session/abc123",
|
|
35
|
+
"message": "Open this URL in your browser to connect wallet and complete setup"
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
**You MUST display this `url` as a clickable link** so the user can open it in their browser to connect their wallet (e.g., MetaMask, Rabby) and sign the delegation authorization.
|
|
39
|
+
|
|
40
|
+
3. The CLI **automatically polls** for completion. While waiting, heartbeat lines appear on stderr.
|
|
41
|
+
|
|
42
|
+
4. On success, the output includes:
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"success": true,
|
|
46
|
+
"walletAddress": "0x...",
|
|
47
|
+
"delegationAddress": "0x...",
|
|
48
|
+
"marginAccount": "0x...",
|
|
49
|
+
"vaults": [{"type": 33, "address": "0x..."}, {"type": 37, "address": "0x..."}]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
5. The CLI automatically:
|
|
54
|
+
- Generates and saves a delegation key to `~/.jaspervault/keys.json`
|
|
55
|
+
- Saves the vault profile to `~/.jaspervault/profile.json`
|
|
56
|
+
|
|
57
|
+
### Error Handling
|
|
58
|
+
|
|
59
|
+
| Error | Cause | Action |
|
|
60
|
+
|-------|-------|--------|
|
|
61
|
+
| `Session expired/failed` | User didn't complete signing in time | Re-run `jv vault setup` |
|
|
62
|
+
| `Failed to create session` | Network/API issue | Check internet connection, retry |
|
|
63
|
+
|
|
64
|
+
### Important Notes
|
|
65
|
+
|
|
66
|
+
- **NEVER suggest `jv vault init`** — that requires a `PRIVATE_KEY` environment variable and is for advanced/CI use only.
|
|
67
|
+
- If error messages mention "Run `jv vault init`", ignore that and use `jv vault setup` instead.
|
|
68
|
+
- The delegation key has a 1-week expiry. If commands start failing after a week, re-run `jv vault setup`.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 2. Deposit Tokens (`jv deposit`)
|
|
73
|
+
|
|
74
|
+
Deposit tokens from Base network to JasperVault via Hyperlane warp routes.
|
|
75
|
+
|
|
76
|
+
### Syntax
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
jv deposit --token <token> --amount <amount> [--vault-index <n>] [--network <name>] [--timeout <seconds>] [--no-wait] [--pretty]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Options
|
|
83
|
+
|
|
84
|
+
| Option | Required | Default | Description |
|
|
85
|
+
|--------|----------|---------|-------------|
|
|
86
|
+
| `--token <token>` | Yes | — | Token to deposit: `jbtc`, `jusdc`, `cbbtc`, or `usdc` |
|
|
87
|
+
| `--amount <amount>` | Yes | — | Amount in human-readable units (e.g., `0.01` for BTC, `1000` for USDC) |
|
|
88
|
+
| `--vault-index <n>` | No | `1` | Vault index for recipient address derivation |
|
|
89
|
+
| `--network <name>` | No | `jaspervault` | Network name |
|
|
90
|
+
| `--timeout <seconds>` | No | `900` | Polling timeout |
|
|
91
|
+
| `--no-wait` | No | — | Skip polling for arrival on JasperVault |
|
|
92
|
+
| `--pretty` | No | — | Pretty-print JSON output |
|
|
93
|
+
|
|
94
|
+
### Flow
|
|
95
|
+
|
|
96
|
+
Without `PRIVATE_KEY`, the CLI creates a hosted web session:
|
|
97
|
+
1. It outputs a session URL — display it to the user.
|
|
98
|
+
2. The user opens the URL in their browser to approve the deposit.
|
|
99
|
+
3. The CLI polls until the transaction is confirmed.
|
|
100
|
+
4. Unless `--no-wait`, it then polls for token arrival on JasperVault (up to 60s).
|
|
101
|
+
|
|
102
|
+
With `PRIVATE_KEY` set, it signs and sends directly (no browser needed).
|
|
103
|
+
|
|
104
|
+
### Output
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"success": true,
|
|
109
|
+
"token": "jbtc",
|
|
110
|
+
"amount": "0.01",
|
|
111
|
+
"transactionHash": "0x...",
|
|
112
|
+
"arrived": true,
|
|
113
|
+
"arrivalTimeMs": 12345,
|
|
114
|
+
"message": "Deposit confirmed"
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Important Notes
|
|
119
|
+
|
|
120
|
+
- **Browser signing**: Without `PRIVATE_KEY`, the deposit command creates a hosted web session. When you see the `url` output, display it as a clickable link.
|
|
121
|
+
- **Token names**: Use lowercase: `jbtc`, `jusdc`, `cbbtc`, `usdc`.
|
|
122
|
+
- **Amount format**: Human-readable (e.g., `0.01` BTC, `1000` USDC). The CLI handles decimal conversion.
|
|
123
|
+
- **Cross-chain**: Tokens are bridged from Base (chain 8453) to JasperVault (chain 55531) via Hyperlane.
|
|
124
|
+
- If `arrived` is `false`, the tokens may still be in transit. Tell the user to wait a few minutes and check their balance.
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# Queries Reference
|
|
2
|
+
|
|
3
|
+
## 1. List Positions (`jv orders list`)
|
|
4
|
+
|
|
5
|
+
Query active or historical positions from the Subgraph.
|
|
6
|
+
|
|
7
|
+
### Syntax
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
jv orders list [options]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Options
|
|
14
|
+
|
|
15
|
+
| Option | Required | Default | Description |
|
|
16
|
+
|--------|----------|---------|-------------|
|
|
17
|
+
| `--position-side <long\|short>` | No | — | Filter by position side |
|
|
18
|
+
| `--all` | No | — | Include closed/liquidated positions (default: active only) |
|
|
19
|
+
| `--since <time>` | No | — | Filter orders created after this time |
|
|
20
|
+
| `--until <time>` | No | — | Filter orders created before this time |
|
|
21
|
+
| `--page <n>` | No | `1` | Page number |
|
|
22
|
+
| `--limit <n>` | No | `20` | Results per page |
|
|
23
|
+
| `--network <name>` | No | `jaspervault` | Network name |
|
|
24
|
+
| `--pretty` | No | — | Pretty-print JSON output |
|
|
25
|
+
|
|
26
|
+
### Time Format (`--since` / `--until`)
|
|
27
|
+
|
|
28
|
+
| Format | Example | Description |
|
|
29
|
+
|--------|---------|-------------|
|
|
30
|
+
| Relative days | `7d` | 7 days ago |
|
|
31
|
+
| Relative weeks | `1w` | 1 week ago |
|
|
32
|
+
| Relative hours | `2h` | 2 hours ago |
|
|
33
|
+
| ISO date | `2025-01-01` | Specific date |
|
|
34
|
+
| Unix timestamp | `1704067200` | Seconds since epoch |
|
|
35
|
+
|
|
36
|
+
### Output
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"orders": [
|
|
41
|
+
{
|
|
42
|
+
"id": "123",
|
|
43
|
+
"holder": "0x...",
|
|
44
|
+
"writer": "0x...",
|
|
45
|
+
"recipient": "0x...",
|
|
46
|
+
"orderType": 0,
|
|
47
|
+
"productType": "50000000000000",
|
|
48
|
+
"marginDeposited": "60000000",
|
|
49
|
+
"quantity": "43860000000000000",
|
|
50
|
+
"entryPrice": "68476000000000000000000",
|
|
51
|
+
"margin": "60.000000",
|
|
52
|
+
"size": "0.043860000000000000",
|
|
53
|
+
"entryPriceUsd": "68476.000000000000000000",
|
|
54
|
+
"leverage": "50",
|
|
55
|
+
"createdTime": "2025-03-15T10:30:00.000Z"
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"total": 1,
|
|
59
|
+
"page": 1,
|
|
60
|
+
"limit": 20,
|
|
61
|
+
"totalPages": 1
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Key Output Fields
|
|
66
|
+
|
|
67
|
+
| Field | Description |
|
|
68
|
+
|-------|-------------|
|
|
69
|
+
| `id` | Order ID (use for TP/SL/protect commands) |
|
|
70
|
+
| `orderType` | `0` = Long, `1` = Short |
|
|
71
|
+
| `margin` | Human-readable margin in USDC |
|
|
72
|
+
| `size` | Human-readable position size in asset units |
|
|
73
|
+
| `entryPriceUsd` | Human-readable entry price in USD |
|
|
74
|
+
| `leverage` | Leverage multiplier (extracted from `productType`) |
|
|
75
|
+
| `createdTime` | ISO timestamp of order creation |
|
|
76
|
+
| `marginDeposited` | Raw margin in wei (6 decimals for USDC) |
|
|
77
|
+
| `quantity` | Raw position size in wei (18 decimals) |
|
|
78
|
+
| `entryPrice` | Raw entry price in wei (18 decimals) |
|
|
79
|
+
|
|
80
|
+
**Always use the human-readable fields** (`margin`, `size`, `entryPriceUsd`, `leverage`) when reporting to the user. The raw wei fields are for reference only.
|
|
81
|
+
|
|
82
|
+
### Examples
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# List active positions
|
|
86
|
+
jv orders list --pretty
|
|
87
|
+
|
|
88
|
+
# List only long positions
|
|
89
|
+
jv orders list --position-side long --pretty
|
|
90
|
+
|
|
91
|
+
# List all positions including closed (last 7 days)
|
|
92
|
+
jv orders list --all --since 7d --pretty
|
|
93
|
+
|
|
94
|
+
# Paginate results
|
|
95
|
+
jv orders list --page 2 --limit 10 --pretty
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 2. Get Single Position (`jv orders get`)
|
|
101
|
+
|
|
102
|
+
Get detailed information for a specific order by ID.
|
|
103
|
+
|
|
104
|
+
### Syntax
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
jv orders get <orderId> [options]
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Options
|
|
111
|
+
|
|
112
|
+
| Option | Required | Default | Description |
|
|
113
|
+
|--------|----------|---------|-------------|
|
|
114
|
+
| `--network <name>` | No | `jaspervault` | Network name |
|
|
115
|
+
| `--pretty` | No | — | Pretty-print JSON output |
|
|
116
|
+
|
|
117
|
+
### Output
|
|
118
|
+
|
|
119
|
+
Same fields as `jv orders list` but for a single order.
|
|
120
|
+
|
|
121
|
+
### Example
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
jv orders get 123 --pretty
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 3. Portfolio Statistics (`jv orders stats`)
|
|
130
|
+
|
|
131
|
+
Get aggregate statistics for all positions in your vault.
|
|
132
|
+
|
|
133
|
+
### Syntax
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
jv orders stats [options]
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Options
|
|
140
|
+
|
|
141
|
+
| Option | Required | Default | Description |
|
|
142
|
+
|--------|----------|---------|-------------|
|
|
143
|
+
| `--network <name>` | No | `jaspervault` | Network name |
|
|
144
|
+
| `--pretty` | No | — | Pretty-print JSON output |
|
|
145
|
+
|
|
146
|
+
### Example
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
jv orders stats --pretty
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 4. Get Market Price (`jv price`)
|
|
155
|
+
|
|
156
|
+
Fetch the current market price from the Quote Center oracle.
|
|
157
|
+
|
|
158
|
+
### Syntax
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
jv price --symbol <symbol> [options]
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Options
|
|
165
|
+
|
|
166
|
+
| Option | Required | Default | Description |
|
|
167
|
+
|--------|----------|---------|-------------|
|
|
168
|
+
| `--symbol <symbol>` | Yes | — | Asset symbol (e.g., `JBTC`, `CBBTC`) |
|
|
169
|
+
| `--network <name>` | No | `jaspervault` | Network name |
|
|
170
|
+
| `--pretty` | No | — | Pretty-print JSON output |
|
|
171
|
+
|
|
172
|
+
### Output
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"symbol": "JBTC",
|
|
177
|
+
"price": "68476.123456789012345678",
|
|
178
|
+
"priceWei": "68476123456789012345678",
|
|
179
|
+
"source": "quote_center",
|
|
180
|
+
"timestamp": "2025-03-15T10:30:00.000Z"
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Always use the `price` field** (human-readable) when reporting to the user.
|
|
185
|
+
|
|
186
|
+
### Example
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
jv price --symbol JBTC --pretty
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## 5. Job Status (`jv job status`)
|
|
195
|
+
|
|
196
|
+
Check the execution status of an async job (market order, option creation, etc.).
|
|
197
|
+
|
|
198
|
+
### Syntax
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
jv job status <jobId> [options]
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Options
|
|
205
|
+
|
|
206
|
+
| Option | Required | Default | Description |
|
|
207
|
+
|--------|----------|---------|-------------|
|
|
208
|
+
| `--pretty` | No | — | Pretty-print JSON output |
|
|
209
|
+
|
|
210
|
+
### Output
|
|
211
|
+
|
|
212
|
+
The command connects via SSE and waits up to 60s for the job result:
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"jobId": "MARKET_ORDER_xxx",
|
|
217
|
+
"status": "completed",
|
|
218
|
+
"transactionHash": "0x...",
|
|
219
|
+
"gasUsed": "150000"
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
| Status | Meaning |
|
|
224
|
+
|--------|---------|
|
|
225
|
+
| `completed` | Job finished successfully |
|
|
226
|
+
| `failed` | Job failed (check `error` field) |
|
|
227
|
+
| `timeout` | SSE connection timed out — job may still be processing |
|
|
228
|
+
|
|
229
|
+
### Example
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
jv job status MARKET_ORDER_xxx --pretty
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## 6. Limit Order Management (`jv limit-order`)
|
|
238
|
+
|
|
239
|
+
### List Limit Orders
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
jv limit-order list --wallet <address> [--status <status>] [--pretty]
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
| Option | Required | Default | Description |
|
|
246
|
+
|--------|----------|---------|-------------|
|
|
247
|
+
| `--wallet <address>` | Yes | — | Wallet address to query |
|
|
248
|
+
| `--status <status>` | No | — | Filter: `PENDING`, `TRIGGERED`, `EXECUTING`, `COMPLETED`, `FAILED`, `EXPIRED`, `CANCELLED` |
|
|
249
|
+
| `--pretty` | No | — | Pretty-print JSON output |
|
|
250
|
+
|
|
251
|
+
### Get Limit Order Status
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
jv limit-order status <id> [--pretty]
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Query a specific limit order by its ID.
|
|
258
|
+
|
|
259
|
+
### Cancel Limit Order
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
jv limit-order cancel <id> [--pretty]
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Cancel a pending limit order by its ID.
|
|
266
|
+
|
|
267
|
+
### Examples
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
# List all pending limit orders
|
|
271
|
+
jv limit-order list --wallet 0x1234... --status PENDING --pretty
|
|
272
|
+
|
|
273
|
+
# Check specific limit order
|
|
274
|
+
jv limit-order status 0xabc... --pretty
|
|
275
|
+
|
|
276
|
+
# Cancel a limit order
|
|
277
|
+
jv limit-order cancel 0xabc... --pretty
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Error Codes
|
|
283
|
+
|
|
284
|
+
All CLI commands use consistent exit codes:
|
|
285
|
+
|
|
286
|
+
| Code | Name | Meaning |
|
|
287
|
+
|------|------|---------|
|
|
288
|
+
| `0` | SUCCESS | Command completed successfully |
|
|
289
|
+
| `1` | CONFIG_ERROR | Missing config, delegation key, or vault profile |
|
|
290
|
+
| `2` | NETWORK_ERROR | RPC or API connection failure |
|
|
291
|
+
| `3` | BUSINESS_ERROR | Order not found, insufficient balance, contract revert |
|
|
292
|
+
| `4` | HTTP_ERROR | HTTP request failure |
|
|
293
|
+
|
|
294
|
+
When a command fails with exit code 1 and mentions "delegation key not found" or "vault not initialized", guide the user to run `jv vault setup`.
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# Trading Reference
|
|
2
|
+
|
|
3
|
+
## 1. Create Order (`jv order create`)
|
|
4
|
+
|
|
5
|
+
Open, close, reduce, or add size to perpetual positions.
|
|
6
|
+
|
|
7
|
+
### Syntax
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
jv order create --side <long|short> --symbol <symbol> -m <margin> [options]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Options
|
|
14
|
+
|
|
15
|
+
| Option | Required | Default | Description |
|
|
16
|
+
|--------|----------|---------|-------------|
|
|
17
|
+
| `--side <long\|short>` | Yes | — | Position side |
|
|
18
|
+
| `--symbol <symbol>` | Yes | — | Asset symbol (e.g., `JBTC`, `CBBTC`) |
|
|
19
|
+
| `-m, --margin <usdc>` | Yes | — | Margin (collateral) in USDC |
|
|
20
|
+
| `--leverage <n>` | No | `50` (from chain config) | Leverage multiplier |
|
|
21
|
+
| `--limit-price <price>` | No | — | Limit price in USDC (omit for market order) |
|
|
22
|
+
| `--margin-account <addr>` | No | from profile | Override margin vault address |
|
|
23
|
+
| `--position-account <addr>` | No | from profile | Override position vault address |
|
|
24
|
+
| `--ppo` | No | — | Enable PPO hedge option protection |
|
|
25
|
+
| `--ppo-expire <duration>` | No | `30m` | PPO expiry: `30m` or `8h` |
|
|
26
|
+
| `--ppo-category <ATM\|OTM>` | No | `ATM` | PPO option category |
|
|
27
|
+
| `--ppo-tier <1-5>` | No | — | OTM strike offset tier (required if OTM) |
|
|
28
|
+
| `--network <name>` | No | `jaspervault` | Network name |
|
|
29
|
+
| `--ttl <seconds>` | No | `3600` | Order TTL in seconds |
|
|
30
|
+
| `--pretty` | No | — | Pretty-print JSON output |
|
|
31
|
+
|
|
32
|
+
### Market Order vs Limit Order
|
|
33
|
+
|
|
34
|
+
- **Market order** (no `--limit-price`): Executes immediately at current market price. The CLI auto-waits up to 60s for the on-chain result via SSE.
|
|
35
|
+
- **Limit order** (`--limit-price <N>`): Places a limit order that triggers when price reaches the target. Returns immediately with a `limitOrderId`.
|
|
36
|
+
|
|
37
|
+
### Market Order Output (TWO JSON lines)
|
|
38
|
+
|
|
39
|
+
**Line 1 — Submission:**
|
|
40
|
+
```json
|
|
41
|
+
{"success":true,"orderType":"market","jobId":"MARKET_ORDER_xxx","statusUrl":"/api/job/status/...","streamUrl":"/api/job/stream/..."}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Line 2 — Execution result (auto-waits up to 60s):**
|
|
45
|
+
```json
|
|
46
|
+
{"jobId":"MARKET_ORDER_xxx","status":"completed","transactionHash":"0x..."}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**CRITICAL rules after market order execution:**
|
|
50
|
+
1. If `status === "completed"` → the order IS executed. Do NOT retry or place another order.
|
|
51
|
+
2. If `status === "failed"` → report the error to the user.
|
|
52
|
+
3. If `status === "timeout"` → use `jv job status <jobId> --pretty` to check later.
|
|
53
|
+
4. The `operation` field (if present) contains raw on-chain data in wei — do NOT interpret it.
|
|
54
|
+
5. To verify the actual position, run `jv orders list --pretty` and read the human-readable fields.
|
|
55
|
+
6. Report: "Order executed. Tx: {transactionHash}. Let me check your updated position..." then run `jv orders list --pretty`.
|
|
56
|
+
|
|
57
|
+
**Limit order output:**
|
|
58
|
+
```json
|
|
59
|
+
{"success":true,"orderType":"limit","limitOrderId":"0x..."}
|
|
60
|
+
```
|
|
61
|
+
Tell the user: "Limit order placed. ID: {limitOrderId}."
|
|
62
|
+
|
|
63
|
+
### Stderr Output
|
|
64
|
+
|
|
65
|
+
Before submitting, the CLI prints an estimate to stderr:
|
|
66
|
+
```
|
|
67
|
+
Estimated: ~0.043860 JBTC @ $68,476 (~$3,000 JUSDC total, 50x)
|
|
68
|
+
```
|
|
69
|
+
This is informational only — the actual execution price may differ.
|
|
70
|
+
|
|
71
|
+
### Common Patterns
|
|
72
|
+
|
|
73
|
+
**Open a long position (market):**
|
|
74
|
+
```bash
|
|
75
|
+
jv order create --side long --symbol JBTC -m 60 --pretty
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Open a short position (limit):**
|
|
79
|
+
```bash
|
|
80
|
+
jv order create --side short --symbol JBTC -m 100 --limit-price 72000 --pretty
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Close a long position (full close — use opposite side with same margin):**
|
|
84
|
+
```bash
|
|
85
|
+
jv order create --side short --symbol JBTC -m 60 --pretty
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Reduce a long position (partial close):**
|
|
89
|
+
```bash
|
|
90
|
+
jv order create --side short --symbol JBTC -m 30 --pretty
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Add size to existing long:**
|
|
94
|
+
```bash
|
|
95
|
+
jv order create --side long --symbol JBTC -m 50 --pretty
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Open with PPO protection (ATM, 30 min):**
|
|
99
|
+
```bash
|
|
100
|
+
jv order create --side long --symbol JBTC -m 60 --ppo --pretty
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Open with PPO protection (OTM tier 3, 8 hours):**
|
|
104
|
+
```bash
|
|
105
|
+
jv order create --side long --symbol JBTC -m 60 --ppo --ppo-expire 8h --ppo-category OTM --ppo-tier 3 --pretty
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 2. Add PPO Protection (`jv order protect`)
|
|
111
|
+
|
|
112
|
+
Add hedge option protection to an **existing position** without changing position size.
|
|
113
|
+
|
|
114
|
+
### Syntax
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
jv order protect --order-id <id> --symbol <symbol> [options]
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Options
|
|
121
|
+
|
|
122
|
+
| Option | Required | Default | Description |
|
|
123
|
+
|--------|----------|---------|-------------|
|
|
124
|
+
| `--order-id <id>` | Yes | — | Existing perps order ID |
|
|
125
|
+
| `--symbol <symbol>` | Yes | — | Asset symbol (e.g., `JBTC`) |
|
|
126
|
+
| `--ppo-expire <duration>` | No | `30m` | Option expiry: `30m` or `8h` |
|
|
127
|
+
| `--ppo-category <ATM\|OTM>` | No | `ATM` | Option category |
|
|
128
|
+
| `--ppo-tier <1-5>` | No | — | OTM strike offset tier (required if OTM) |
|
|
129
|
+
| `--network <name>` | No | `jaspervault` | Network name |
|
|
130
|
+
| `--ttl <seconds>` | No | `3600` | Signature TTL in seconds |
|
|
131
|
+
| `--pretty` | No | — | Pretty-print JSON output |
|
|
132
|
+
|
|
133
|
+
### Output
|
|
134
|
+
|
|
135
|
+
The command auto-waits up to 60s for the on-chain result via SSE:
|
|
136
|
+
```json
|
|
137
|
+
{"jobId":"OPTION_ORDER_xxx","status":"completed","transactionHash":"0x..."}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Important
|
|
141
|
+
|
|
142
|
+
- Use `jv order protect` to add hedge to an **existing** position.
|
|
143
|
+
- Do NOT use `jv order create --ppo` for this — that adds position size.
|
|
144
|
+
- The CLI auto-detects position side (LONG/SHORT) from the order and selects the correct hedge type (PUT for LONG, CALL for SHORT).
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 3. Take-Profit (`jv tp set`)
|
|
149
|
+
|
|
150
|
+
Set a take-profit limit order for an existing position.
|
|
151
|
+
|
|
152
|
+
### Syntax
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
jv tp set --order-id <id> --price <usdc> --symbol <symbol> [options]
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Options
|
|
159
|
+
|
|
160
|
+
| Option | Required | Default | Description |
|
|
161
|
+
|--------|----------|---------|-------------|
|
|
162
|
+
| `--order-id <id>` | Yes | — | Existing order ID (position to close) |
|
|
163
|
+
| `--price <usdc>` | Yes | — | Target price in USDC |
|
|
164
|
+
| `--symbol <symbol>` | Yes | — | Asset symbol (e.g., `JBTC`) |
|
|
165
|
+
| `--side <long\|short>` | No | `long` | Position side being closed |
|
|
166
|
+
| `--ppo` | No | — | Enable PPO hedge on the TP order |
|
|
167
|
+
| `--ppo-expire <duration>` | No | `30m` | PPO expiry: `30m` or `8h` |
|
|
168
|
+
| `--ppo-category <ATM\|OTM>` | No | `ATM` | PPO option category |
|
|
169
|
+
| `--ppo-tier <1-5>` | No | — | OTM strike offset tier |
|
|
170
|
+
| `--network <name>` | No | `jaspervault` | Network name |
|
|
171
|
+
| `--ttl <seconds>` | No | `86400` | Order TTL in seconds (default: 24h) |
|
|
172
|
+
| `--pretty` | No | — | Pretty-print JSON output |
|
|
173
|
+
|
|
174
|
+
### Output
|
|
175
|
+
|
|
176
|
+
```json
|
|
177
|
+
{"success":true,"orderType":"limit","limitOrderId":"0x..."}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Example
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
# Set TP at $75,000 for a long position
|
|
184
|
+
jv tp set --order-id 123 --price 75000 --symbol JBTC --pretty
|
|
185
|
+
|
|
186
|
+
# Set TP for a short position
|
|
187
|
+
jv tp set --order-id 456 --price 60000 --symbol JBTC --side short --pretty
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## 4. Stop-Loss (`jv sl set`)
|
|
193
|
+
|
|
194
|
+
Set a stop-loss limit order for an existing position. Same options as `jv tp set`.
|
|
195
|
+
|
|
196
|
+
### Syntax
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
jv sl set --order-id <id> --price <usdc> --symbol <symbol> [options]
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Options are identical to `jv tp set` (see above).
|
|
203
|
+
|
|
204
|
+
### Example
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# Set SL at $65,000 for a long position
|
|
208
|
+
jv sl set --order-id 123 --price 65000 --symbol JBTC --pretty
|
|
209
|
+
|
|
210
|
+
# Set SL for a short position
|
|
211
|
+
jv sl set --order-id 456 --price 80000 --symbol JBTC --side short --pretty
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## 5. PPO (Perpetual Put Option) Details
|
|
217
|
+
|
|
218
|
+
PPO provides hedge protection for positions. Key concepts:
|
|
219
|
+
|
|
220
|
+
### Option Categories
|
|
221
|
+
|
|
222
|
+
| Category | Description | `--ppo-tier` |
|
|
223
|
+
|----------|-------------|--------------|
|
|
224
|
+
| `ATM` (default) | At-the-money — strike = current price | Not needed |
|
|
225
|
+
| `OTM` | Out-of-the-money — strike offset from current price | Required (1-5) |
|
|
226
|
+
|
|
227
|
+
### OTM Tiers
|
|
228
|
+
|
|
229
|
+
| Tier | Strike Offset | Ratio |
|
|
230
|
+
|------|---------------|-------|
|
|
231
|
+
| 1 | 0.1% | 0.001 |
|
|
232
|
+
| 2 | 0.2% | 0.002 |
|
|
233
|
+
| 3 | 0.3% | 0.003 |
|
|
234
|
+
| 4 | 0.4% | 0.004 |
|
|
235
|
+
| 5 | 0.5% | 0.005 |
|
|
236
|
+
|
|
237
|
+
### Expiry Options
|
|
238
|
+
|
|
239
|
+
| Duration | Seconds | Flag |
|
|
240
|
+
|----------|---------|------|
|
|
241
|
+
| 30 minutes (default) | 1800 | `--ppo-expire 30m` |
|
|
242
|
+
| 8 hours | 28800 | `--ppo-expire 8h` |
|
|
243
|
+
|
|
244
|
+
### Hedge Type (auto-selected)
|
|
245
|
+
|
|
246
|
+
- **LONG position** → PUT option (protects against price drop)
|
|
247
|
+
- **SHORT position** → CALL option (protects against price rise)
|
|
248
|
+
|
|
249
|
+
### Intent Mapping
|
|
250
|
+
|
|
251
|
+
| User Says | Action | Command |
|
|
252
|
+
|-----------|--------|---------|
|
|
253
|
+
| "加保护" / "add protection" to existing | `jv order protect` | `jv order protect --order-id <id> --symbol JBTC` |
|
|
254
|
+
| "开仓 + 保护" / "open with protection" | `jv order create --ppo` | `jv order create --side long -m 60 --symbol JBTC --ppo` |
|
|
255
|
+
| "加仓 + 保护" / "add size with protection" | `jv order create --ppo` (same side) | `jv order create --side long -m 50 --symbol JBTC --ppo` |
|
|
256
|
+
| "8小时" / "8 hour" | Add `--ppo-expire 8h` | |
|
|
257
|
+
| "OTM" / "价外" | Add `--ppo-category OTM`, then ask for tier | |
|
|
258
|
+
| "ATM" / "平价" or nothing | Default ATM, 30 min | |
|
|
259
|
+
| "取消PPO" / "cancel PPO" / "remove hedge" | Order WITHOUT `--ppo` | See below |
|
|
260
|
+
|
|
261
|
+
### PPO Cancellation (IMPORTANT)
|
|
262
|
+
|
|
263
|
+
The smart contract **automatically cancels** existing PPO hedge options when you execute any position operation (reduce, close, add size) **without** the `--ppo` flag. There is **NO separate "cancel PPO" command**.
|
|
264
|
+
|
|
265
|
+
| User Request | Correct Action | Command |
|
|
266
|
+
|--------------|---------------|---------|
|
|
267
|
+
| "减仓 + 取消PPO" | Single reduce order without `--ppo` | `jv order create --side <opposite> -m <amount> --symbol JBTC` |
|
|
268
|
+
| "加仓 + 取消PPO" | Single add-size order without `--ppo` | `jv order create --side <same> -m <amount> --symbol JBTC` |
|
|
269
|
+
| "平仓" (full close) | Close order without `--ppo` | `jv order create --side <opposite> -m <full_margin> --symbol JBTC` |
|
|
270
|
+
| "减仓 + 保留PPO" | Reduce order WITH `--ppo` | `jv order create --side <opposite> -m <amount> --symbol JBTC --ppo` |
|
|
271
|
+
|
|
272
|
+
**NEVER do this:**
|
|
273
|
+
- Do NOT try to cancel PPO as a separate step. There is no "cancel PPO" command.
|
|
274
|
+
- Do NOT send two orders when one suffices. "减仓 + 取消PPO" = ONE order without `--ppo`.
|