perp-cli 0.3.3 → 0.3.5
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 +12 -8
- package/dist/__tests__/risk-assessment.test.js +124 -3
- package/dist/commands/manage.js +7 -5
- package/dist/commands/risk.js +106 -3
- package/dist/commands/wallet.js +29 -1
- package/dist/index.js +3 -3
- package/dist/mcp-server.js +1 -1
- package/dist/risk.d.ts +20 -0
- package/dist/risk.js +65 -0
- package/package.json +1 -1
- package/skills/perp-cli/SKILL.md +20 -11
- package/skills/perp-cli/references/agent-operations.md +260 -0
- package/skills/perp-cli/references/commands.md +5 -2
- package/skills/perp-cli/references/strategies.md +377 -0
- package/skills/perp-cli/templates/arb-scan.sh +19 -0
- package/skills/perp-cli/templates/open-position.sh +38 -0
- package/skills/perp-cli/templates/wallet-setup.sh +17 -0
package/skills/perp-cli/SKILL.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: perp-cli
|
|
3
3
|
description: "Multi-DEX perpetual futures trading CLI for Pacifica (Solana), Hyperliquid (EVM), and Lighter (Ethereum). Use when user asks to trade perps, check funding rates, bridge USDC, manage positions, scan arbitrage opportunities, or mentions perp-cli, hypurrquant, Pacifica, Hyperliquid, or Lighter exchanges. Also use when user says 'set up perp trading', 'check my positions', 'buy BTC perps', 'funding rate arb', 'bridge USDC', or 'deposit to exchange'."
|
|
4
|
+
allowed-tools: "Bash(perp:*), Bash(npx perp-cli:*), Bash(npx -y perp-cli:*)"
|
|
4
5
|
license: MIT
|
|
5
6
|
metadata:
|
|
6
7
|
author: hypurrquant
|
|
7
|
-
version: "0.3.
|
|
8
|
+
version: "0.3.5"
|
|
8
9
|
mcp-server: perp-cli
|
|
9
10
|
---
|
|
10
11
|
|
|
@@ -14,10 +15,14 @@ Multi-DEX perpetual futures CLI — Pacifica (Solana), Hyperliquid (HyperEVM), L
|
|
|
14
15
|
|
|
15
16
|
## Critical Rules
|
|
16
17
|
|
|
17
|
-
1. **
|
|
18
|
-
2. **
|
|
19
|
-
3. **
|
|
20
|
-
4. **
|
|
18
|
+
1. **RISK MANAGEMENT IS YOUR #1 PRIORITY.** A single liquidation wipes out months of profit. Always check `perp --json risk status` before and during any operation. See `references/strategies.md` for the full risk framework.
|
|
19
|
+
2. **NEVER use interactive commands.** Do NOT run `perp init`. Always use non-interactive commands with `--json`.
|
|
20
|
+
3. **Always use `--json`** on every command for structured output.
|
|
21
|
+
4. **NEVER trade without user confirmation.** Show order details and wait for explicit approval.
|
|
22
|
+
5. **Verify wallet before any operation.** Run `perp --json wallet show` first.
|
|
23
|
+
6. **Use ISOLATED margin for arb.** Set `perp --json manage margin <SYM> isolated` before opening positions. Cross margin can cascade liquidations.
|
|
24
|
+
7. **Monitor positions continuously.** Run `perp --json risk status` and `perp --json -e <EX> account positions` every 15 minutes while positions are open.
|
|
25
|
+
8. **NEVER read ~/.perp/.env or any key files directly.** Private keys are managed by the CLI internally. Use `perp --json wallet show` to check wallet status. Never attempt to read, cat, or access key files — this is a security violation.
|
|
21
26
|
|
|
22
27
|
## Step 1: Install
|
|
23
28
|
|
|
@@ -74,15 +79,19 @@ perp --json portfolio # unified multi-exchange view
|
|
|
74
79
|
|
|
75
80
|
### Trade execution (MANDATORY checklist)
|
|
76
81
|
```
|
|
77
|
-
1. perp --json
|
|
78
|
-
2. perp --json -e <EX>
|
|
79
|
-
3. perp --json -e <EX>
|
|
80
|
-
4.
|
|
81
|
-
5. perp --json -e <EX> trade
|
|
82
|
-
6.
|
|
82
|
+
1. perp --json risk status → check risk level (STOP if critical)
|
|
83
|
+
2. perp --json -e <EX> account info → verify balance
|
|
84
|
+
3. perp --json -e <EX> market mid <SYM> → current price
|
|
85
|
+
4. perp --json risk check --notional <$> --leverage <L> → risk pre-check
|
|
86
|
+
5. perp --json -e <EX> trade check <SYM> <SIDE> <SIZE> → trade validation
|
|
87
|
+
6. [Show order details + risk assessment to user, get explicit confirmation]
|
|
88
|
+
7. perp --json -e <EX> trade market <SYM> <SIDE> <SIZE> → execute
|
|
89
|
+
8. perp --json -e <EX> account positions → verify result + check liquidation price
|
|
83
90
|
```
|
|
84
91
|
|
|
85
92
|
For full command reference, see `references/commands.md`.
|
|
93
|
+
For agent-specific operations (setup flows, deposit/withdraw, order types, idempotency), see `references/agent-operations.md`.
|
|
94
|
+
For autonomous strategies (funding rate arb, risk management, opportunity cost), see `references/strategies.md`.
|
|
86
95
|
|
|
87
96
|
## Response Format
|
|
88
97
|
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# Agent Operations Guide
|
|
2
|
+
|
|
3
|
+
Complete reference for non-interactive CLI operations. Every command here is safe for agents — no prompts, no hangs.
|
|
4
|
+
|
|
5
|
+
## Interactive vs Non-Interactive Commands
|
|
6
|
+
|
|
7
|
+
### NEVER use these (interactive, will hang):
|
|
8
|
+
```
|
|
9
|
+
perp init # interactive wizard — asks questions via stdin
|
|
10
|
+
perp wallet setup # removed, but may appear in old docs
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### ALWAYS use these (non-interactive, agent-safe):
|
|
14
|
+
```bash
|
|
15
|
+
perp --json wallet set <exchange> <key> # set private key
|
|
16
|
+
perp --json wallet generate evm # generate EVM wallet
|
|
17
|
+
perp --json wallet generate solana # generate Solana wallet
|
|
18
|
+
perp --json wallet show # check configured wallets
|
|
19
|
+
perp --json wallet balance # on-chain USDC balances
|
|
20
|
+
perp --json -e <EX> account info # exchange account info
|
|
21
|
+
perp --json -e <EX> account positions # open positions
|
|
22
|
+
perp --json -e <EX> market list # available markets
|
|
23
|
+
perp --json -e <EX> trade market ... # execute trade
|
|
24
|
+
perp --json -e <EX> trade buy ... # alias for market buy
|
|
25
|
+
perp --json -e <EX> trade sell ... # alias for market sell
|
|
26
|
+
perp --json risk status # risk assessment
|
|
27
|
+
perp --json risk liquidation-distance # % from liquidation for all positions
|
|
28
|
+
perp --json risk limits # view/set risk limits
|
|
29
|
+
perp --json risk check --notional <$> --leverage <L> # pre-trade risk check
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Rule: every command MUST include `--json`.** Without it, output is human-formatted and harder to parse.
|
|
33
|
+
|
|
34
|
+
## Zero to Trading: Complete Setup Flow
|
|
35
|
+
|
|
36
|
+
### Single Exchange Setup
|
|
37
|
+
```bash
|
|
38
|
+
# 1. Install
|
|
39
|
+
npm install -g perp-cli
|
|
40
|
+
|
|
41
|
+
# 2. Register wallet (user provides key)
|
|
42
|
+
perp --json wallet set hl 0xUSER_PRIVATE_KEY
|
|
43
|
+
|
|
44
|
+
# 3. Verify
|
|
45
|
+
perp --json wallet show
|
|
46
|
+
# → check "ok": true and address appears
|
|
47
|
+
|
|
48
|
+
# 4. Check balance
|
|
49
|
+
perp --json -e hl account info
|
|
50
|
+
# → if balance is 0, tell user to deposit USDC
|
|
51
|
+
|
|
52
|
+
# 5. Ready to trade
|
|
53
|
+
perp --json -e hl market list
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Multi-Exchange Setup (for Funding Rate Arb)
|
|
57
|
+
To run arb, you need wallets on AT LEAST 2 exchanges. Each exchange needs:
|
|
58
|
+
- A configured wallet with a private key
|
|
59
|
+
- USDC balance deposited on-exchange
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# 1. Register both wallets
|
|
63
|
+
perp --json wallet set hl 0xEVM_KEY
|
|
64
|
+
perp --json wallet set pac SOLANA_BASE58_KEY
|
|
65
|
+
|
|
66
|
+
# 2. Verify both
|
|
67
|
+
perp --json wallet show
|
|
68
|
+
# → should show both exchanges with addresses
|
|
69
|
+
|
|
70
|
+
# 3. Check balances on both
|
|
71
|
+
perp --json -e hl account info
|
|
72
|
+
perp --json -e pac account info
|
|
73
|
+
|
|
74
|
+
# 4. If one side needs funding, bridge USDC
|
|
75
|
+
perp --json bridge quote --from solana --to arbitrum --amount 500
|
|
76
|
+
# → show quote to user, get confirmation
|
|
77
|
+
perp --json bridge send --from solana --to arbitrum --amount 500
|
|
78
|
+
perp --json bridge status <orderId> # wait for completion
|
|
79
|
+
|
|
80
|
+
# 5. Verify both sides have balance, then start arb
|
|
81
|
+
perp --json arb rates
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Lighter API Key Setup
|
|
85
|
+
Lighter requires a separate API key in addition to the EVM private key. **`wallet set` handles this automatically:**
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# wallet set automatically generates & registers API key + saves to .env
|
|
89
|
+
perp --json wallet set lt 0xEVM_KEY
|
|
90
|
+
# → saves LIGHTER_PRIVATE_KEY, LIGHTER_API_KEY, LIGHTER_ACCOUNT_INDEX to ~/.perp/.env
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
If auto-setup failed (e.g. no ETH for gas), retry manually:
|
|
94
|
+
```bash
|
|
95
|
+
perp --json -e lighter manage setup-api-key
|
|
96
|
+
# → generates API key, registers on-chain, auto-saves to ~/.perp/.env
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Note:** On-chain registration requires a small amount of ETH on the Lighter chain for gas.
|
|
100
|
+
|
|
101
|
+
### Using the Same EVM Key for Multiple Exchanges
|
|
102
|
+
One EVM private key works for both Hyperliquid and Lighter:
|
|
103
|
+
```bash
|
|
104
|
+
perp --json wallet set hl 0xKEY
|
|
105
|
+
perp --json wallet set lt 0xKEY # same key, different exchange binding
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Wallet Key Types
|
|
109
|
+
|
|
110
|
+
| Exchange | Chain | Key Format | Example |
|
|
111
|
+
|----------|-------|-----------|---------|
|
|
112
|
+
| Hyperliquid | EVM | Hex with 0x prefix, 66 chars | `0x4c0883a69102937d...` |
|
|
113
|
+
| Lighter | EVM | Hex with 0x prefix, 66 chars | `0x4c0883a69102937d...` |
|
|
114
|
+
| Pacifica | Solana | Base58 string | `5KQwrPbwdL6PhXu...` |
|
|
115
|
+
|
|
116
|
+
Aliases for exchange names:
|
|
117
|
+
- `hl` or `hyperliquid`
|
|
118
|
+
- `pac` or `pacifica`
|
|
119
|
+
- `lt` or `lighter`
|
|
120
|
+
|
|
121
|
+
## Deposit & Withdraw Flows
|
|
122
|
+
|
|
123
|
+
### Check On-Chain vs Exchange Balance
|
|
124
|
+
```bash
|
|
125
|
+
perp --json wallet balance # on-chain USDC in your wallet
|
|
126
|
+
perp --json -e hl account info # USDC deposited on exchange
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**On-chain balance ≠ exchange balance.** USDC in your wallet must be deposited to the exchange before trading.
|
|
130
|
+
|
|
131
|
+
### Deposit to Exchange
|
|
132
|
+
```bash
|
|
133
|
+
# Hyperliquid (from Arbitrum wallet)
|
|
134
|
+
perp --json deposit hyperliquid 100
|
|
135
|
+
|
|
136
|
+
# Pacifica (from Solana wallet)
|
|
137
|
+
perp --json deposit pacifica 100
|
|
138
|
+
|
|
139
|
+
# Lighter (multiple routes)
|
|
140
|
+
perp --json deposit lighter info # show all available routes
|
|
141
|
+
perp --json deposit lighter cctp arb 100 # via CCTP from Arbitrum
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Withdraw from Exchange
|
|
145
|
+
```bash
|
|
146
|
+
perp --json withdraw hyperliquid 100
|
|
147
|
+
perp --json withdraw pacifica 100
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Bridge Between Chains
|
|
151
|
+
When you need to move USDC between exchanges on different chains:
|
|
152
|
+
```bash
|
|
153
|
+
# 1. Withdraw from source exchange
|
|
154
|
+
perp --json withdraw pacifica 500
|
|
155
|
+
|
|
156
|
+
# 2. Quote the bridge
|
|
157
|
+
perp --json bridge quote --from solana --to arbitrum --amount 500
|
|
158
|
+
|
|
159
|
+
# 3. Send (after user confirmation)
|
|
160
|
+
perp --json bridge send --from solana --to arbitrum --amount 500
|
|
161
|
+
|
|
162
|
+
# 4. Wait for completion
|
|
163
|
+
perp --json bridge status <orderId>
|
|
164
|
+
|
|
165
|
+
# 5. Deposit to destination exchange
|
|
166
|
+
perp --json deposit hyperliquid 500
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Order Types & Execution
|
|
170
|
+
|
|
171
|
+
### Market Orders (immediate execution)
|
|
172
|
+
```bash
|
|
173
|
+
perp --json -e hl trade market BTC buy 0.01 # market buy
|
|
174
|
+
perp --json -e hl trade market BTC sell 0.01 # market sell
|
|
175
|
+
perp --json -e hl trade buy BTC 0.01 # shorthand
|
|
176
|
+
perp --json -e hl trade sell BTC 0.01 # shorthand
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Limit Orders (execute at specific price)
|
|
180
|
+
```bash
|
|
181
|
+
perp --json -e hl trade buy BTC 0.01 -p 60000 # buy at $60,000
|
|
182
|
+
perp --json -e hl trade sell BTC 0.01 -p 70000 # sell at $70,000
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Close Position
|
|
186
|
+
```bash
|
|
187
|
+
perp --json -e hl trade close BTC # close entire position
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Stop Loss / Take Profit
|
|
191
|
+
```bash
|
|
192
|
+
perp --json -e hl trade sl BTC 58000 # stop loss at $58k
|
|
193
|
+
perp --json -e hl trade tp BTC 65000 # take profit at $65k
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Cancel Orders
|
|
197
|
+
```bash
|
|
198
|
+
perp --json -e hl account orders # list open orders
|
|
199
|
+
perp --json -e hl trade cancel <orderId> # cancel specific order
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Pre-Flight Validation
|
|
203
|
+
ALWAYS run before executing a trade:
|
|
204
|
+
```bash
|
|
205
|
+
perp --json -e hl trade check BTC buy 0.01
|
|
206
|
+
```
|
|
207
|
+
This returns estimated fees, slippage, and whether the trade can execute.
|
|
208
|
+
|
|
209
|
+
## Parsing JSON Output
|
|
210
|
+
|
|
211
|
+
Every command returns this envelope:
|
|
212
|
+
```json
|
|
213
|
+
{
|
|
214
|
+
"ok": true,
|
|
215
|
+
"data": { ... },
|
|
216
|
+
"meta": { "timestamp": "2026-03-11T..." }
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Error case:
|
|
221
|
+
```json
|
|
222
|
+
{
|
|
223
|
+
"ok": false,
|
|
224
|
+
"error": {
|
|
225
|
+
"code": "INSUFFICIENT_BALANCE",
|
|
226
|
+
"message": "Not enough USDC",
|
|
227
|
+
"retryable": false
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**Always check `ok` field first.** If `ok` is `false`, read `error.code` to decide next action. If `error.retryable` is `true`, wait 5 seconds and retry once.
|
|
233
|
+
|
|
234
|
+
## Idempotency & Safety
|
|
235
|
+
|
|
236
|
+
### Safe to retry (idempotent):
|
|
237
|
+
- `wallet show`, `wallet balance` — read-only
|
|
238
|
+
- `account info`, `account positions`, `account orders` — read-only
|
|
239
|
+
- `market list`, `market mid`, `market book` — read-only
|
|
240
|
+
- `arb rates`, `arb scan` — read-only
|
|
241
|
+
- `portfolio`, `risk overview` — read-only
|
|
242
|
+
- `bridge quote` — read-only
|
|
243
|
+
- `bridge status` — read-only
|
|
244
|
+
|
|
245
|
+
### NOT safe to retry blindly:
|
|
246
|
+
- `trade market`, `trade buy`, `trade sell` — will open duplicate positions
|
|
247
|
+
- `trade close` — may error if already closed, but harmless
|
|
248
|
+
- `bridge send` — will send duplicate transfers
|
|
249
|
+
- `deposit`, `withdraw` — will move funds twice
|
|
250
|
+
|
|
251
|
+
**For non-idempotent commands:** always verify the result before retrying. Check positions or balances to confirm whether the first attempt succeeded.
|
|
252
|
+
|
|
253
|
+
## Common Agent Mistakes
|
|
254
|
+
|
|
255
|
+
1. **Using `perp init`** — interactive, will hang forever. Use `wallet set` instead.
|
|
256
|
+
2. **Forgetting `--json`** — output becomes unparseable human text.
|
|
257
|
+
3. **Trading with zero balance** — check `account info` first, tell user to deposit.
|
|
258
|
+
4. **Retrying a trade without checking** — leads to double positions. Always check `account positions` after a trade, even if it seemed to fail.
|
|
259
|
+
5. **Bridging without quoting** — always run `bridge quote` first to show the user fees and estimated time.
|
|
260
|
+
6. **Assuming deposit is instant** — after `bridge send`, wait for `bridge status` to confirm completion before depositing to the destination exchange.
|
|
@@ -108,8 +108,11 @@ perp --json wallet balance # on-chain balance
|
|
|
108
108
|
|
|
109
109
|
## Risk & Analytics
|
|
110
110
|
```bash
|
|
111
|
-
perp --json risk status # portfolio risk overview
|
|
112
|
-
perp --json risk
|
|
111
|
+
perp --json risk status # portfolio risk overview (level, violations, canTrade)
|
|
112
|
+
perp --json risk liquidation-distance # % distance from liquidation for ALL positions
|
|
113
|
+
perp --json risk limits # view current risk limits
|
|
114
|
+
perp --json risk limits --min-liq-distance 30 --max-leverage 5 # set risk limits
|
|
115
|
+
perp --json risk check --notional 1000 --leverage 3 # pre-trade risk check
|
|
113
116
|
perp --json health # exchange connectivity & latency
|
|
114
117
|
perp --json analytics summary # trading performance
|
|
115
118
|
perp --json analytics pnl # P&L breakdown
|