Skip to content

Commit ff5e175

Browse files
Hiksangclaude
andcommitted
docs: add matched-size arb execution rules to skill docs
Both legs of a funding arb MUST have identical size to maintain delta-neutral. Added step-by-step: check orderbook depth on both sides, compute min fillable size, execute with same ORDER_SIZE, verify match after fill. Covers chunked orders and mismatch recovery. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7db6485 commit ff5e175

2 files changed

Lines changed: 111 additions & 36 deletions

File tree

skills/perp-cli/SKILL.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,32 @@ BEFORE ANY TRADE:
113113
9. perp --json -e <EX> account positions → verify result + check liquidation price
114114
```
115115

116+
### Arb order sizing (CRITICAL — both legs MUST match)
117+
```
118+
For funding arb, BOTH legs must have the EXACT SAME SIZE. Size mismatch = directional exposure.
119+
120+
1. Check orderbook depth on BOTH exchanges:
121+
perp --json -e <LONG_EX> market book <SYM> → asks (you're buying)
122+
perp --json -e <SHORT_EX> market book <SYM> → bids (you're selling)
123+
124+
2. Check market info for min order size and step size:
125+
perp --json -e <LONG_EX> market info <SYM>
126+
perp --json -e <SHORT_EX> market info <SYM>
127+
128+
3. Compute ORDER_SIZE = min(fillable_long, fillable_short, desired_size)
129+
Round to the coarser step size. Must be ≥ both exchanges' minOrderSize.
130+
131+
4. Execute BOTH legs with the SAME ORDER_SIZE:
132+
perp --json -e <LONG_EX> trade market <SYM> buy <ORDER_SIZE>
133+
→ verify fill
134+
perp --json -e <SHORT_EX> trade market <SYM> sell <ORDER_SIZE>
135+
→ verify fill
136+
137+
5. Confirm matched: both positions must show identical size.
138+
If mismatch (partial fill), adjust the larger to match the smaller.
139+
```
140+
See `references/strategies.md` for detailed execution strategy (chunked orders, limit orders, failure handling).
141+
116142
### Post-entry monitoring (MANDATORY while positions are open)
117143
```
118144
Every 15 minutes:

skills/perp-cli/references/strategies.md

Lines changed: 85 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -140,50 +140,99 @@ perp --json -e <EX> account positions # per-exchange positions
140140
perp --json arb scan --min 5 # are current rates still favorable?
141141
```
142142

143-
### Order Execution: Sequential Leg Management
143+
### Order Execution: Matched Size, Sequential Legs
144144

145-
**NEVER close or open both legs of an arb at once with market orders.** You must manage execution carefully.
145+
**The #1 rule of arb execution: BOTH LEGS MUST HAVE THE EXACT SAME SIZE.** A size mismatch means you have net directional exposure — the whole point of arb is to be delta-neutral.
146146

147-
#### Why This Matters
148-
Orderbooks have limited depth at each price level. A large market order will eat through multiple ticks and suffer heavy slippage. Worse, if you close one leg but fail to close the other (exchange error, rate limit, network issue), you are left with naked directional exposure.
147+
#### Step 1: Determine Matched Order Size
149148

150-
#### Pre-Execution: Check Orderbook Depth
151-
Before executing, verify that the orderbook can absorb your size at acceptable prices on BOTH sides:
149+
Before placing ANY order, compute a single `ORDER_SIZE` that BOTH exchanges can fill:
150+
151+
```bash
152+
# 1. Check orderbook depth on BOTH sides
153+
perp --json -e <LONG_EX> market book <SYM> # check asks (you're buying)
154+
perp --json -e <SHORT_EX> market book <SYM> # check bids (you're selling)
155+
156+
# 2. Find immediately fillable size at best 2-3 ticks
157+
# LONG side: sum ask sizes at best 2-3 ask levels → fillable_long
158+
# SHORT side: sum bid sizes at best 2-3 bid levels → fillable_short
159+
160+
# 3. ORDER_SIZE = min(fillable_long, fillable_short, desired_size)
161+
# The SMALLER side limits your matched size.
162+
```
163+
164+
**Example:**
165+
```
166+
LONG exchange asks: $85.00 × 0.5, $85.01 × 0.3 → fillable = 0.8
167+
SHORT exchange bids: $85.10 × 0.4, $85.09 × 0.2 → fillable = 0.6
168+
Desired size: 1.0
169+
170+
→ ORDER_SIZE = min(0.8, 0.6, 1.0) = 0.6
171+
→ Both legs get exactly 0.6
172+
```
173+
174+
**CRITICAL: Each exchange has its own minimum order size and step size.**
175+
```bash
176+
perp --json -e <EX> market info <SYM> # check minOrderSize, stepSize
177+
```
178+
Round `ORDER_SIZE` to the coarser step size of the two exchanges. If the matched size falls below either exchange's minimum, the arb is NOT executable at this size — reduce target or skip.
179+
180+
#### Step 2: Execute Legs Sequentially with Same Size
181+
182+
Once you have a single `ORDER_SIZE`, execute both legs using THAT EXACT SIZE:
183+
184+
```bash
185+
# Leg 1: Open on exchange A
186+
perp --json -e <LONG_EX> trade market <SYM> buy <ORDER_SIZE>
187+
188+
# Verify leg 1 filled
189+
perp --json -e <LONG_EX> account positions
190+
191+
# Leg 2: Open on exchange B with SAME size
192+
perp --json -e <SHORT_EX> trade market <SYM> sell <ORDER_SIZE>
193+
194+
# Verify leg 2 filled
195+
perp --json -e <SHORT_EX> account positions
196+
```
197+
198+
**After both legs, verify sizes match:**
152199
```bash
153-
perp --json -e <EX_A> market book <SYM> # check bids/asks depth
154-
perp --json -e <EX_B> market book <SYM> # check bids/asks depth
155-
```
156-
157-
Look at the size available at the best tick. If your order size exceeds what's available at the best 2-3 ticks, you MUST split the order.
158-
159-
#### Execution Strategy
160-
1. **Determine executable chunk size** — the largest size both orderbooks can absorb at the best tick without excessive slippage
161-
2. **Execute in sequential chunks:**
162-
```
163-
Chunk 1: close X on Exchange A → immediately open X on Exchange B
164-
Chunk 2: close X on Exchange A → immediately open X on Exchange B
165-
... repeat until full size is executed
166-
```
167-
3. **Verify each chunk** before proceeding to the next:
168-
```bash
169-
perp --json -e <EX_A> account positions # confirm partial close
170-
perp --json -e <EX_B> account positions # confirm partial open
171-
```
172-
4. **Re-check the orderbook** between chunks — liquidity may have changed
173-
174-
#### Paired Execution Rule
175-
Each chunk must be a **matched pair**: close on one side, open on the other. Never execute multiple closes without the corresponding opens. If one leg fails:
176-
- STOP immediately
177-
- Assess your current exposure
178-
- Decide whether to retry the failed leg or unwind the completed leg
179-
- Do NOT continue with remaining chunks
200+
perp --json -e <LONG_EX> account positions # size = X
201+
perp --json -e <SHORT_EX> account positions # size must = X
202+
```
203+
If sizes differ (partial fill, rounding), immediately adjust the larger position to match the smaller one.
204+
205+
#### Step 3: Split Large Orders into Matched Chunks
206+
207+
If your desired size exceeds what the orderbooks can absorb at best ticks, split into chunks — but **every chunk must be a matched pair with identical size on both sides**:
208+
209+
```
210+
Chunk 1: buy 0.3 on Exchange A → sell 0.3 on Exchange B → verify both
211+
Chunk 2: buy 0.3 on Exchange A → sell 0.3 on Exchange B → verify both
212+
... repeat until full size is executed
213+
```
214+
215+
**Rules:**
216+
1. Re-check orderbook depth between chunks — liquidity changes
217+
2. Each chunk: same size on both sides, no exceptions
218+
3. If one leg fails → STOP immediately, do NOT continue
219+
4. Assess exposure: retry the failed leg, or unwind the completed leg
220+
5. NEVER execute multiple orders on one side without matching the other
180221

181222
#### Using Limit Orders for Better Execution
182-
For non-urgent transitions, consider limit orders at the best bid/ask instead of market orders:
223+
For non-urgent entries, use limit orders at best bid/ask instead of market:
224+
```bash
225+
perp --json -e <EX> trade buy <SYM> <ORDER_SIZE> -p <PRICE> # limit order
226+
```
227+
This avoids crossing the spread but risks not getting filled. Set a timeout and fall back to market if unfilled. **Both legs must still use the same `ORDER_SIZE`.**
228+
229+
#### Closing Arb Positions: Same Rules Apply
230+
When exiting, close BOTH legs with the SAME size:
183231
```bash
184-
perp --json -e <EX> trade sell <SYM> <SIZE> -p <PRICE> # limit order
232+
perp --json -e <LONG_EX> trade close <SYM> # closes full position
233+
perp --json -e <SHORT_EX> trade close <SYM> # closes full position
185234
```
186-
This avoids crossing the spread, but you risk not getting filled. Set a reasonable timeout and fall back to market if not filled.
235+
If positions already have mismatched sizes, close to the smaller size first, then close the remaining delta on the larger side.
187236

188237
### When to Exit
189238
- Spread compressed below your breakeven (including fees)

0 commit comments

Comments
 (0)