Skip to content

Commit 3f06dad

Browse files
authored
Merge pull request #7 from BitMEX-private/fix/skills-accuracy-review
fix: address skill accuracy issues from Kris' review
2 parents b3060bc + 6365af0 commit 3f06dad

12 files changed

Lines changed: 51 additions & 20 deletions

File tree

skills/bitmex-alert-patterns/SKILL.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ bitmex ws --auth wallet margin -o json 2>/dev/null | \
101101
'
102102
```
103103

104-
## Position PnL Alert
104+
## Position Unrealised PnL Alert
105+
106+
> **Note:** This monitors `unrealisedPnl` only — mark-to-market movement. Funding costs accumulate separately every 8 hours and are not reflected until charged. For a full position P&L view, also monitor the funding rate.
105107
106108
```bash
107-
PNL_THRESHOLD=-50000 # in satoshis
109+
PNL_THRESHOLD=-50000 # in satoshis (XBt instruments); use appropriate units for USDT instruments
108110
bitmex ws --auth position -o json 2>/dev/null | \
109111
jq -c --argjson t "$PNL_THRESHOLD" '
110112
.data[]? | select(.unrealisedPnl != null and .unrealisedPnl < $t) |

skills/bitmex-basis-trading/SKILL.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,6 @@ echo "scale=4; $BASIS / $DAYS * 365" | bc -l
130130
- Margin risk: each leg consumes margin independently
131131
- Roll risk: if the future expires before exit, roll the position
132132
- Basis can widen before converging — maintain margin buffer
133+
- Funding risk: the perpetual leg accrues funding every 8 hours; in positive-funding environments the long perp leg pays, eroding carry — model funding into your breakeven calculation
134+
- Instrument scope: this guide uses inverse pairs (XBTUSD/XBTM25); linear-linear pairs (e.g. XBTUSDT/XBTUSDTM26) work similarly provided lot sizes and multipliers match, but P&L is denominated in USDT rather than XBT
135+
- Spot-future basis: the classic version uses spot BTC (off-exchange) vs a fixed-date future rather than a perpetual; this eliminates funding risk but requires managing spot custody separately and is not covered here

skills/bitmex-dca-strategy/SKILL.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,21 @@ done
8686

8787
## Track Average Entry Price
8888

89+
> For **inverse** instruments (e.g. XBTUSD), the correct average entry is a cost-weighted harmonic mean: `total_qty / sum(qty/price)`. Standard VWAP (`sum(qty*price) / total_qty`) overstates the average slightly and diverges from the exchange-reported figure.
90+
> For **linear** instruments (e.g. XBTUSDT), standard VWAP is correct.
91+
8992
```bash
93+
# Inverse instruments (XBTUSD, etc.)
9094
bitmex execution trade-history --symbol XBTUSD --reverse --count 100 -o json 2>/dev/null | \
9195
jq '
9296
[.[] | select(.side == "Buy" and .execType == "Trade")] |
9397
{
9498
count: length,
9599
total_qty: (map(.lastQty) | add),
96100
avg_entry: (
97-
(map(.lastQty * .lastPx) | add) /
98-
(map(.lastQty) | add)
99-
| round / 100
101+
(map(.lastQty) | add) /
102+
(map(.lastQty / .lastPx) | add)
103+
| (. * 100 | round) / 100
100104
)
101105
}
102106
'

skills/bitmex-fee-optimization/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ metadata:
1212

1313
# bitmex-fee-optimization
1414

15-
BitMEX charges taker fees and pays maker rebates. The difference is meaningful at scale. Always default to limit orders with `ParticipateDoNotInitiate`.
15+
BitMEX charges taker fees and pays maker rebates. The difference is meaningful at scale. Default to limit orders with `ParticipateDoNotInitiate` for passive entries. For aggressive fills where immediate execution matters more than fee savings, use a limit order at the ask/bid price without this flag — see *Avoid Market Orders* below.
1616

1717
## Fee Structure
1818

skills/bitmex-liquidation-guard/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bitmex position list -o json 2>/dev/null | jq '
3737
symbol,
3838
markPrice,
3939
liquidationPrice,
40-
buffer_pct: (((.markPrice - .liquidationPrice) / .markPrice * 100) | round / 100)
40+
buffer_pct: (((.markPrice - .liquidationPrice) / .markPrice * 100) | fabs | (. * 100 | round) / 100)
4141
}]
4242
'
4343
```

skills/bitmex-order-types/SKILL.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ bitmex order buy XBTUSD 100 --price 50000 --order-type Limit \
122122
--tif ImmediateOrCancel --validate -o json 2>/dev/null
123123
```
124124

125+
## Contingency / Linked Orders
126+
127+
BitMEX supports paired order logic via `contingencyType` and a shared `clOrdLinkID`. The CLI does not currently expose these as flags; use the REST API for these order types.
128+
129+
| Type | Behavior |
130+
|---|---|
131+
| `OneCancelsTheOther` | OCO: when one order fills or triggers, the linked order is cancelled |
132+
| `OneTriggersTheOther` | OTO: when the first order fills, the linked order becomes active |
133+
| `OneUpdatesTheOtherAbsolute` | OUO: amending one order propagates the change to the linked order |
134+
135+
Typical use: a stop-loss + take-profit pair as OCO so that one filling automatically cancels the other. These must currently be submitted directly via the BitMEX REST API with matching `clOrdLinkID` values.
136+
125137
## Amending Orders
126138

127139
Change price or qty on an open order without cancelling and re-placing:

skills/bitmex-position-risk/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ bitmex position list --symbol XBTUSD -o json 2>/dev/null | jq '
117117
if .markPrice == null or .liquidationPrice == null then
118118
{symbol, markPrice, liquidationPrice, gap_pct: null}
119119
else
120-
((.markPrice - .liquidationPrice) / .markPrice * 100) as $pct |
121-
{symbol, markPrice, liquidationPrice, gap_pct: ($pct | round / 100)}
120+
((.markPrice - .liquidationPrice) / .markPrice * 100 | fabs) as $pct |
121+
{symbol, markPrice, liquidationPrice, gap_pct: (($pct * 100 | round) / 100)}
122122
end
123123
'
124124
```

skills/bitmex-recipe-basis-trade-entry/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,5 @@ Exit both legs when basis narrows to under 0.1% or at futures expiry.
8282

8383
- Size both legs equally in USD notional to maintain delta neutrality.
8484
- Account for maker/taker fees on both entry and exit when calculating the net carry.
85+
- The perpetual leg exposes you to funding rate volatility; net carry = basis − cumulative funding over hold period. Check `bitmex market funding --symbol XBTUSD` before entering.
86+
- For carry estimates, exit logic, and roll procedures, see the `bitmex-basis-trading` skill.

skills/bitmex-recipe-daily-pnl-report/SKILL.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ bitmex execution trade-history --reverse --count 500 -o json \
2727
> /tmp/trades_today.json
2828
```
2929

30-
### 2. Sum realised P&L (in satoshis)
30+
### 2. Sum realised P&L by currency
31+
32+
> P&L units depend on the instrument's settlement currency. XBt-settled instruments (e.g. XBTUSD) report in satoshis; divide by 1e8 for XBT. USDT-settled instruments (e.g. XBTUSDT) report in USDT units. Always group by `homeNotional` currency rather than summing across all symbols.
3133
3234
```bash
33-
jq '[.[].realisedPnl] | add // 0' /tmp/trades_today.json
35+
jq 'group_by(.currency) | map({
36+
currency: .[0].currency,
37+
realisedPnl: ([.[].realisedPnl] | add // 0)
38+
})' /tmp/trades_today.json
3439
```
3540

36-
Convert to XBT: divide by `100000000`.
37-
3841
### 3. Total fees paid today
3942

4043
```bash
@@ -76,4 +79,4 @@ bitmex position list -o json \
7679
## Tips
7780

7881
- Automate with a cron at 23:55 UTC and append to a CSV for trend analysis.
79-
- BitMEX P&L is denominated in XBt (satoshis). Always divide by 1e8 before displaying in XBT.
82+
- XBt-settled instruments (inverse, e.g. XBTUSD) report P&L in satoshis; divide by 1e8 for XBT. USDT-settled instruments report in USDT. Never sum across currencies.

skills/bitmex-recipe-drawdown-circuit-breaker/SKILL.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Halt trading when portfolio drawdown exceeds threshold.
55

66
# Drawdown Circuit Breaker
77

8-
Monitor wallet balance against a high-water mark and automatically flatten all positions when drawdown exceeds your configured threshold.
8+
Monitor margin balance against a high-water mark and automatically flatten all positions when drawdown exceeds your configured threshold.
99

1010
## Prerequisites
1111

@@ -17,10 +17,10 @@ Monitor wallet balance against a high-water mark and automatically flatten all p
1717

1818
### 1. Record the high-water mark
1919

20-
Capture wallet balance at the start of each session or daily:
20+
Capture margin balance at the start of each session or daily. `marginBalance` (not `walletBalance`) is used here because it includes `unrealisedPnl`, so a large adverse price move will trigger the breaker even before positions are closed.
2121

2222
```bash
23-
HIGH_WATER=$(bitmex wallet balance -o json | jq '.amount')
23+
HIGH_WATER=$(bitmex account margin --currency XBt -o json | jq '.marginBalance')
2424
echo "$HIGH_WATER" > /tmp/bitmex_hwm.txt
2525
```
2626

@@ -30,12 +30,14 @@ On subsequent checks, load it:
3030
HIGH_WATER=$(cat /tmp/bitmex_hwm.txt)
3131
```
3232

33-
### 2. Get current wallet balance
33+
### 2. Get current margin balance
3434

3535
```bash
36-
CURRENT=$(bitmex wallet balance -o json | jq '.amount')
36+
CURRENT=$(bitmex account margin --currency XBt -o json | jq '.marginBalance')
3737
```
3838

39+
> **Note:** This circuit breaker covers XBt-denominated positions only. USDT positions require a separate check using `--currency USDt`.
40+
3941
### 3. Calculate drawdown percentage
4042

4143
```bash

0 commit comments

Comments
 (0)