| name | bitmex-alert-patterns |
| version | 1.0.0 |
| description | Price, funding, liquidation, and balance alerts using polling and WebSocket on bitmex-cli. |
| metadata | {"openclaw":{"category":"finance"},"requires":{"bins":["bitmex"]},"depends":["bitmex-shared","bitmex-rate-limits","bitmex-ws-streaming"]} |
bitmex-alert-patterns
Two approaches: REST polling (low-frequency) and WebSocket streaming (real-time). Use WebSocket wherever possible to stay within the 300 req/5min REST budget.
Native Price Alerts
BitMEX supports native price alerts via the notifications API:
bitmex notifications add-alert XBTUSD 55000 --above -o json 2>/dev/null
bitmex notifications add-alert XBTUSD 45000 -o json 2>/dev/null
bitmex notifications alerts -o json 2>/dev/null
bitmex notifications delete-alert <id> -o json 2>/dev/null
WebSocket Price Alert
Real-time price monitoring with no REST cost:
THRESHOLD=55000
bitmex ws instrument:XBTUSD -o json 2>/dev/null | \
jq -c --argjson t "$THRESHOLD" '
.data[]? | select(.lastPrice != null) |
if .lastPrice > $t then "ALERT: XBTUSD above \($t): \(.lastPrice)"
else empty end
'
REST Polling Alert
For lower-frequency checks (e.g., hourly funding):
THRESHOLD=0.001
while true; do
RATE=$(bitmex market funding --symbol XBTUSD -o json 2>/dev/null | \
jq -r '.[0].fundingRate // 0')
if [ "$(echo "$RATE > $THRESHOLD" | bc -l)" = "1" ]; then
echo "ALERT: XBTUSD funding rate $RATE exceeds threshold $THRESHOLD"
fi
sleep 300
done
Funding Rate Alert
bitmex ws funding -o json 2>/dev/null | \
jq -c '.data[]? | select(.fundingRate != null and (.fundingRate | fabs) > 0.001) |
"ALERT: \(.symbol) funding \(.fundingRate) at \(.timestamp)"'
Liquidation Alert
Monitor large liquidations as a market signal:
bitmex ws liquidation -o json 2>/dev/null | \
jq -c '.data[]? | "LIQUIDATION: \(.side) \(.leavesQty) \(.symbol) @ \(.price)"'
bitmex ws liquidation -o json 2>/dev/null | \
jq -c '.data[]? | select(.leavesQty > 100000) |
"LARGE LIQ: \(.side) \(.leavesQty) \(.symbol) @ \(.price)"'
Balance Change Alert (Authenticated)
bitmex ws --auth wallet margin -o json 2>/dev/null | \
jq -c '
if .table == "margin" then
.data[]? | "MARGIN: available=\(.availableMargin) balance=\(.marginBalance)"
elif .table == "wallet" then
.data[]? | "WALLET: \(.currency) balance=\(.amount)"
else empty end
'
Position Unrealised PnL Alert
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.
PNL_THRESHOLD=-50000
bitmex ws --auth position -o json 2>/dev/null | \
jq -c --argjson t "$PNL_THRESHOLD" '
.data[]? | select(.unrealisedPnl != null and .unrealisedPnl < $t) |
"ALERT: \(.symbol) unrealised PnL \(.unrealisedPnl) below threshold"
'
Order Fill Notification
bitmex ws --auth execution -o json 2>/dev/null | \
jq -c '.data[]? | select(.execType == "Trade") |
"FILL: \(.side) \(.lastQty) \(.symbol) @ \(.lastPx) [\(.ordStatus)]"'
Announcement Monitoring
bitmex announce urgent -o json 2>/dev/null | jq '[.[] | {date, title, content}]'
while true; do
bitmex announce urgent -o json 2>/dev/null | jq -r '.[] | "\(.date): \(.title)"'
sleep 600
done