perp-cli 0.4.12 → 0.5.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/README.md +34 -10
- package/dist/cli-spec.js +2 -2
- package/dist/commands/account.js +183 -27
- package/dist/commands/agent.js +5 -5
- package/dist/commands/arb/index.js +217 -24
- package/dist/commands/arb-auto.d.ts +9 -0
- package/dist/commands/arb-auto.js +577 -382
- package/dist/commands/arb.d.ts +44 -0
- package/dist/commands/arb.js +239 -514
- package/dist/commands/market.js +108 -73
- package/dist/commands/trade.js +60 -20
- package/dist/exchanges/hyperliquid.d.ts +11 -2
- package/dist/exchanges/hyperliquid.js +165 -32
- package/dist/exchanges/lighter.js +22 -8
- package/dist/liquidity.js +3 -1
- package/dist/mcp-server.js +53 -50
- package/package.json +1 -1
- package/skills/perp-cli/SKILL.md +90 -189
package/skills/perp-cli/SKILL.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: perp-cli
|
|
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, scan arbitrage (perp-perp or spot-perp), delta-neutral strategies, bridge USDC, manage positions/orders, deposit/withdraw, spot+perp hedge, or mentions perp-cli, hypurrquant, Pacifica, Hyperliquid, Lighter, HyperEVM, funding arb, U-token (UBTC/UETH/USOL)."
|
|
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, scan arbitrage (perp-perp or spot-perp), delta-neutral strategies, bridge USDC, manage positions/orders, deposit/withdraw, spot+perp hedge, HIP-3 DEX trading, or mentions perp-cli, hypurrquant, Pacifica, Hyperliquid, Lighter, HyperEVM, funding arb, U-token (UBTC/UETH/USOL)."
|
|
4
4
|
allowed-tools: "Bash(perp:*), Bash(npx perp-cli:*), Bash(npx -y perp-cli:*)"
|
|
5
5
|
license: MIT
|
|
6
6
|
metadata:
|
|
7
7
|
author: hypurrquant
|
|
8
|
-
version: "0.
|
|
8
|
+
version: "0.5.1"
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
# perp-cli Agent Guide
|
|
@@ -21,21 +21,18 @@ Multi-DEX perpetual futures CLI — Pacifica (Solana), Hyperliquid (HyperEVM), L
|
|
|
21
21
|
5. **NEVER trade without user confirmation.**
|
|
22
22
|
6. **NEVER read ~/.perp/.env or key files.**
|
|
23
23
|
|
|
24
|
-
## Install
|
|
24
|
+
## Install
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
#
|
|
28
|
-
perp --version 2>/dev/null
|
|
29
|
-
|
|
30
|
-
# 2. If not found or outdated:
|
|
27
|
+
perp --version 2>/dev/null # check if exists (must be >= 0.5.1)
|
|
31
28
|
npm install -g perp-cli@latest 2>/dev/null || npx -y perp-cli@latest --json --version
|
|
32
|
-
|
|
33
|
-
# 3. If version is still old (npx cache), clear cache first:
|
|
34
|
-
npx -y clear-npx-cache 2>/dev/null; npx -y perp-cli@latest --json --version
|
|
35
29
|
```
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
Use `perp` if global install works, otherwise `npx -y perp-cli@latest` as prefix.
|
|
32
|
+
|
|
33
|
+
## Global Flags
|
|
34
|
+
|
|
35
|
+
`--json` (required) | `-e hl/pac/lt` (exchange) | `--dex <name>` (HIP-3) | `-w <wallet>` | `--dry-run` | `--fields <f1,f2>` | `--ndjson`
|
|
39
36
|
|
|
40
37
|
## Wallet Setup
|
|
41
38
|
|
|
@@ -45,227 +42,131 @@ perp --json wallet set pac <SOLANA_KEY> # Pacifica
|
|
|
45
42
|
perp --json wallet set lt <EVM_KEY> # Lighter (API key auto-generated)
|
|
46
43
|
perp --json wallet show # verify
|
|
47
44
|
```
|
|
48
|
-
Same EVM key works for both HL and Lighter.
|
|
49
45
|
|
|
50
|
-
##
|
|
46
|
+
## Core Workflow: Arb
|
|
51
47
|
|
|
52
|
-
```
|
|
53
|
-
#
|
|
54
|
-
perp --json
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
perp --json arb
|
|
58
|
-
perp --json arb
|
|
59
|
-
|
|
60
|
-
# Single exchange trading (when not doing arb)
|
|
61
|
-
perp --json -e <EX> trade market <SYM> buy <SIZE>
|
|
62
|
-
perp --json -e <EX> trade market <SYM> buy <SIZE> --smart # IOC limit at best ask + 1 tick (less slippage)
|
|
63
|
-
perp --json -e <EX> trade market <SYM> buy <SIZE> --split # orderbook-aware split for large orders
|
|
64
|
-
perp --json -e <EX> trade split <SYM> buy 5000 # dedicated split command (USD notional)
|
|
65
|
-
perp --json -e <EX> trade close <SYM>
|
|
66
|
-
perp --json -e <EX> trade close <SYM> --smart # smart close at best bid/ask
|
|
67
|
-
|
|
68
|
-
# Risk (only if you need to set limits — portfolio already includes risk)
|
|
69
|
-
perp --json risk limits --max-leverage 5
|
|
48
|
+
```
|
|
49
|
+
1. perp --json arb scan # scan opportunities (perp-perp + spot-perp + HIP-3)
|
|
50
|
+
2. perp --json account balance # check balances across all exchanges
|
|
51
|
+
3. perp --json --dry-run arb exec <SYM> <longEx> <shortEx> <$> # dry-run (auto-sizes)
|
|
52
|
+
4. [show result to user, get confirmation]
|
|
53
|
+
5. perp --json arb exec <SYM> <longEx> <shortEx> <$> # execute
|
|
54
|
+
6. perp --json arb status # monitor PnL + funding income
|
|
55
|
+
7. perp --json arb close <SYM> # close both legs
|
|
70
56
|
```
|
|
71
57
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
## Agent Tools
|
|
75
|
-
|
|
76
|
-
```bash
|
|
77
|
-
# Discover all commands and parameters at runtime (don't guess — query this)
|
|
78
|
-
perp --json agent schema
|
|
79
|
-
|
|
80
|
-
# Pre-validate a trade before execution (checks balance, liquidity, risk limits)
|
|
81
|
-
perp --json -e <EX> trade check <SYM> <SIDE> <SIZE>
|
|
82
|
-
|
|
83
|
-
# Dry-run: simulate trade without executing
|
|
84
|
-
perp --json --dry-run -e <EX> trade market <SYM> buy <SIZE>
|
|
85
|
-
|
|
86
|
-
# Filter output to specific fields (saves tokens)
|
|
87
|
-
perp --json --fields totalEquity,positions portfolio
|
|
58
|
+
### Scan Modes
|
|
88
59
|
|
|
89
|
-
|
|
90
|
-
|
|
60
|
+
| Flag | Description |
|
|
61
|
+
|------|-------------|
|
|
62
|
+
| _(default)_ | All modes combined (perp-perp + spot-perp) |
|
|
63
|
+
| `--rates` | Funding rates across exchanges |
|
|
64
|
+
| `--basis [symbol]` | Cross-exchange basis/price diff |
|
|
65
|
+
| `--gaps` | Price gaps |
|
|
66
|
+
| `--hip3` | HIP-3 on-chain dex opportunities |
|
|
67
|
+
| `--history [symbol]` | Historical funding data |
|
|
68
|
+
| `--compare <symbol>` | Compare symbol across exchanges |
|
|
69
|
+
| `--positions` | Existing position exit signals |
|
|
70
|
+
| `--live` | Continuous monitoring |
|
|
91
71
|
|
|
92
|
-
|
|
93
|
-
perp --json -e <EX> trade market <SYM> buy <SIZE> --client-id <UNIQUE_ID>
|
|
72
|
+
### Spot+Perp Arb
|
|
94
73
|
|
|
95
|
-
|
|
96
|
-
# Fills only at top-of-book price — no multi-level sweep slippage
|
|
97
|
-
perp --json -e <EX> trade market <SYM> buy <SIZE> --smart
|
|
98
|
-
perp --json -e <EX> trade close <SYM> --smart
|
|
99
|
-
perp --json arb exec <SYM> <longEx> <shortEx> <$> --smart # smart arb entry
|
|
100
|
-
perp --json arb close <SYM> --smart # smart arb close
|
|
74
|
+
Spot has 0 funding cost. Use `spot:<exch>` prefix for the long leg:
|
|
101
75
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
perp --json
|
|
105
|
-
perp --json
|
|
106
|
-
perp --json -e <EX> trade market <SYM> buy <SIZE> --split # split via market command flag
|
|
76
|
+
```bash
|
|
77
|
+
perp --json arb exec ETH spot:hl hl 100 # spot buy(HL) + perp short(HL)
|
|
78
|
+
perp --json arb exec BTC spot:lt pac 50 # spot buy(LT) + perp short(PAC)
|
|
79
|
+
perp --json arb close ETH # sells spot + buys back perp
|
|
107
80
|
```
|
|
108
81
|
|
|
109
|
-
|
|
82
|
+
Spot exchanges: HL, LT. Pacifica is perp-only.
|
|
110
83
|
|
|
111
|
-
##
|
|
84
|
+
## Core Workflow: Single Trade
|
|
112
85
|
|
|
86
|
+
```bash
|
|
87
|
+
perp --json -e <EX> trade buy <SYM> <SIZE> # market buy (SIZE = token units)
|
|
88
|
+
perp --json -e <EX> trade sell <SYM> <SIZE> # market sell
|
|
89
|
+
perp --json -e <EX> trade buy <SYM> <SIZE> --smart # IOC limit at best ask
|
|
90
|
+
perp --json -e <EX> trade split <SYM> buy <USD> # orderbook-aware split
|
|
91
|
+
perp --json -e <EX> trade limit <SYM> buy <PRICE> <SIZE>
|
|
92
|
+
perp --json -e <EX> trade tpsl <SYM> buy --tp <P> --sl <P>
|
|
93
|
+
perp --json -e <EX> trade close <SYM>
|
|
94
|
+
perp --json -e <EX> trade flatten # close ALL + cancel ALL
|
|
95
|
+
perp --json -e <EX> trade cancel <SYM> # cancel all orders for symbol
|
|
113
96
|
```
|
|
114
|
-
1. perp --json portfolio → check balances across all exchanges
|
|
115
|
-
2. perp --json arb scan --min 5 → find opportunity (longExch, shortExch, netSpread)
|
|
116
|
-
3. [Show opportunity to user, get confirmation]
|
|
117
|
-
4. perp --json arb exec <SYM> <longEx> <shortEx> <$> --leverage 2 --isolated
|
|
118
|
-
→ validates orderbook depth on both sides
|
|
119
|
-
→ rounds size to each exchange's lot size
|
|
120
|
-
→ executes BOTH legs simultaneously
|
|
121
|
-
→ verifies positions exist after execution
|
|
122
|
-
→ auto-rollback if one leg fails
|
|
123
|
-
5. perp --json arb status → monitor: PnL, funding income, daily estimate, breakeven
|
|
124
|
-
6. perp --json arb funding-earned → actual funding payments received/paid + APR
|
|
125
|
-
7. perp --json arb close <SYM> → close both legs simultaneously (retry + verify)
|
|
126
|
-
→ --dry-run: preview without executing
|
|
127
|
-
→ --pair <longEx>:<shortEx>: specify which pair if multiple
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## Spot+Perp Arb Workflow
|
|
131
|
-
|
|
132
|
-
Spot has 0 funding cost → spread = |perp funding rate|. Only needs 1 exchange with spot + any exchange with perp.
|
|
133
97
|
|
|
134
|
-
|
|
135
|
-
**U-token mapping:** HL spot uses Unit protocol bridged tokens — UBTC=BTC, UETH=ETH, USOL=SOL, UFART=FARTCOIN. Resolved automatically.
|
|
98
|
+
## Agent Tools
|
|
136
99
|
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
Examples:
|
|
143
|
-
perp --json arb spot-exec ETH hl hl 100 # ETH spot(HL/UETH) + perp(HL)
|
|
144
|
-
perp --json arb spot-exec BTC hl lt 50 # BTC spot(HL/UBTC) + perp(LT)
|
|
145
|
-
perp --json arb spot-exec LINK lt hl 100 # LINK spot(LT) + perp(HL)
|
|
146
|
-
→ cross-validates spot vs perp price (>5% deviation = abort, wrong token)
|
|
147
|
-
→ sequential execution if same exchange (nonce collision avoidance)
|
|
148
|
-
→ parallel execution if different exchanges
|
|
149
|
-
→ auto-rollback if one leg fails
|
|
150
|
-
Options:
|
|
151
|
-
--leverage <N> set perp leverage before entry
|
|
152
|
-
--isolated use isolated margin on perp side
|
|
153
|
-
4. perp --json arb status → shows spot-perp positions (spot leg labeled)
|
|
154
|
-
5. perp --json arb spot-close <SYM> --spot-exch <hl|lt>
|
|
155
|
-
→ sells spot + buys back perp simultaneously
|
|
100
|
+
```bash
|
|
101
|
+
perp --json agent schema # discover all commands (don't guess)
|
|
102
|
+
perp --json -e <EX> trade check <SYM> <SIDE> <SIZE> # pre-validate trade
|
|
103
|
+
perp --json portfolio # balances + positions + risk level
|
|
104
|
+
perp --json --fields totalEquity,positions portfolio # filtered output
|
|
156
105
|
```
|
|
157
106
|
|
|
158
|
-
|
|
159
|
-
- HL spot: BTC (UBTC), ETH (UETH), SOL (USOL), FARTCOIN (UFART), HYPE, AZTEC, STABLE
|
|
160
|
-
- LT spot: ETH, AZTEC, AAVE, LINK, UNI, LIT, LDO, SKY
|
|
161
|
-
- All have perps on HL and LT. Pacifica perps available when API is up.
|
|
162
|
-
|
|
163
|
-
## Position Sizing
|
|
107
|
+
## Position Sizing & Safety
|
|
164
108
|
|
|
165
109
|
- Single position < **80%** of that exchange's available balance
|
|
166
110
|
- Leverage 1-3x for arb, max 5x
|
|
167
111
|
- `arb exec` auto-matches both legs to the same size
|
|
112
|
+
- ALWAYS follow `longExch`/`shortExch` from scan — NEVER reverse direction
|
|
113
|
+
- NEVER enter if `netSpread <= 0` or `netSpread < estimated round-trip slippage`
|
|
114
|
+
- Check `portfolio.risk.canTrade` — if `false`, do NOT trade
|
|
168
115
|
|
|
169
|
-
##
|
|
170
|
-
|
|
171
|
-
`arb scan` returns `longExch`, `shortExch`, `netSpread`.
|
|
172
|
-
ALWAYS follow exactly. NEVER reverse. NEVER enter if `netSpread <= 0`.
|
|
173
|
-
|
|
174
|
-
## Slippage Check (CRITICAL)
|
|
175
|
-
|
|
176
|
-
`arb scan` returns `netSpread` in bps (already fee-adjusted).
|
|
177
|
-
Before executing, compare against estimated slippage:
|
|
178
|
-
```
|
|
179
|
-
Slippage ≈ 2-5 bps per leg for top pairs (BTC, ETH, SOL)
|
|
180
|
-
≈ 5-15 bps per leg for low-liquidity (altcoins)
|
|
181
|
-
Total round-trip slippage = (entry + exit) × 2 legs
|
|
182
|
-
```
|
|
183
|
-
**NEVER enter if:** `netSpread < total round-trip slippage`
|
|
184
|
-
Example: netSpread=12 bps, estimated slippage=4 bps/leg × 4 = 16 bps → SKIP.
|
|
185
|
-
|
|
186
|
-
## Portfolio Response
|
|
187
|
-
|
|
188
|
-
`portfolio` includes `risk: { level, canTrade, violations[] }` — no need for separate `risk status`.
|
|
189
|
-
Check `canTrade` before any order. If `false`, do NOT trade.
|
|
116
|
+
## HIP-3 Support
|
|
190
117
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
Daily: perp --json arb funding-earned → verify actual funding payments
|
|
197
|
-
Exit if: spread < breakeven or one leg closed unexpectedly.
|
|
198
|
-
Close: perp --json arb close <SYM> → close both legs with retry + verification
|
|
118
|
+
```bash
|
|
119
|
+
perp --json -e hl --dex km market list # dex-specific markets
|
|
120
|
+
perp --json market list --hip3 # all HIP-3 markets
|
|
121
|
+
perp --json account positions --hip3 # HIP-3 positions
|
|
122
|
+
perp --json arb scan --hip3 # HIP-3 arb opportunities
|
|
199
123
|
```
|
|
200
124
|
|
|
201
125
|
## Error Handling
|
|
202
126
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
If `error.retryable` is `false`, do NOT retry — fix the cause first.
|
|
127
|
+
Response format: `{ "ok": true, "data": {...} }` or `{ "ok": false, "error": { "code": "...", "retryable": true/false } }`
|
|
206
128
|
|
|
207
129
|
| Error | Action |
|
|
208
130
|
|-------|--------|
|
|
209
|
-
| `RATE_LIMITED` | wait
|
|
210
|
-
| `EXCHANGE_UNREACHABLE` | wait 10s, retry. 3x fail → skip
|
|
211
|
-
| `
|
|
212
|
-
| `
|
|
213
|
-
| `
|
|
214
|
-
| `
|
|
215
|
-
| `
|
|
216
|
-
| `MARGIN_INSUFFICIENT` | reduce leverage or close existing positions |
|
|
217
|
-
| `DUPLICATE_ORDER` | already submitted — check positions, don't retry |
|
|
218
|
-
| Lighter `invalid signature` | check ~/.perp/.env or `perp --json -e lighter manage setup-api-key` |
|
|
219
|
-
| Lighter `invalid account index` | rate limit caused init failure — wait 10s and retry the command |
|
|
220
|
-
| Lighter `--smart` not filling | Lighter IOC limit orders may not fill — use regular market order (without `--smart`) |
|
|
131
|
+
| `RATE_LIMITED` | wait 5s, retry (max 3). Lighter: space 3s+ apart |
|
|
132
|
+
| `EXCHANGE_UNREACHABLE` | wait 10s, retry. 3x fail → skip exchange |
|
|
133
|
+
| `INSUFFICIENT_BALANCE` | reduce size or bridge funds |
|
|
134
|
+
| `SYMBOL_NOT_FOUND` | `market list` to verify symbol |
|
|
135
|
+
| `SIZE_TOO_SMALL` | `market info <SYM>` for min size |
|
|
136
|
+
| `DUPLICATE_ORDER` | already submitted — check positions |
|
|
137
|
+
| Lighter `invalid signature` | `manage setup-api-key` to regenerate |
|
|
221
138
|
|
|
222
139
|
## Examples
|
|
223
140
|
|
|
224
|
-
**
|
|
225
|
-
```bash
|
|
226
|
-
perp --json portfolio # check balances
|
|
227
|
-
perp --json arb scan --mode all --min 5 # scan perp-perp + spot-perp
|
|
228
|
-
# → show results, recommend best opportunity, ask for confirmation
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
**User: "ETH spot-perp 아비트라지 실행해줘 $100"**
|
|
141
|
+
**"Find arb opportunities"**
|
|
232
142
|
```bash
|
|
233
|
-
perp --json arb scan --
|
|
234
|
-
perp --json
|
|
235
|
-
# → show
|
|
236
|
-
perp --json arb spot-exec ETH hl hl 100 # execute after confirmation
|
|
237
|
-
perp --json arb status # verify positions
|
|
143
|
+
perp --json arb scan --min 10 --top 10
|
|
144
|
+
perp --json account balance
|
|
145
|
+
# → show results, recommend best, ask confirmation
|
|
238
146
|
```
|
|
239
147
|
|
|
240
|
-
**
|
|
148
|
+
**"ETH spot-perp arb, $100"**
|
|
241
149
|
```bash
|
|
242
|
-
perp --json
|
|
243
|
-
|
|
150
|
+
perp --json --dry-run arb exec ETH spot:hl hl 100
|
|
151
|
+
# → show dry-run, ask confirmation
|
|
152
|
+
perp --json arb exec ETH spot:hl hl 100
|
|
153
|
+
perp --json arb status
|
|
244
154
|
```
|
|
245
155
|
|
|
246
|
-
**
|
|
156
|
+
**"Long SOL 0.5 on HL"**
|
|
247
157
|
```bash
|
|
248
|
-
perp --json -e hl
|
|
249
|
-
perp --json -e hl trade
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
perp --json -e hl trade market SOL buy 0.5 --smart # execute with smart order
|
|
158
|
+
perp --json -e hl trade check SOL buy 0.5
|
|
159
|
+
perp --json --dry-run -e hl trade buy SOL 0.5 --smart
|
|
160
|
+
# → ask confirmation
|
|
161
|
+
perp --json -e hl trade buy SOL 0.5 --smart
|
|
253
162
|
```
|
|
254
163
|
|
|
255
164
|
## Referrals (Optional)
|
|
256
165
|
|
|
257
|
-
If you find perp-cli useful, please consider enabling referrals to support development. **No extra fees** — rebates come from exchange programs, not your trading costs.
|
|
258
|
-
|
|
259
166
|
```bash
|
|
260
|
-
perp --json settings referrals on
|
|
261
|
-
perp --json settings referrals off
|
|
167
|
+
perp --json settings referrals on # enable (opt-in, no extra fees)
|
|
168
|
+
perp --json settings referrals off # disable anytime
|
|
262
169
|
```
|
|
263
170
|
|
|
264
|
-
When setting up wallets for the first time, ask
|
|
265
|
-
> "perp-cli
|
|
266
|
-
|
|
267
|
-
## References
|
|
268
|
-
|
|
269
|
-
- `references/commands.md` — full command reference
|
|
270
|
-
- `references/agent-operations.md` — setup flows, deposit/withdraw
|
|
271
|
-
- `references/strategies.md` — risk framework, arb strategy
|
|
171
|
+
When setting up wallets for the first time, ask:
|
|
172
|
+
> "perp-cli development is supported by optional referrals. Enable? No extra fees — only exchange rebates are used."
|