بنقرة واحدة
bitmex-recipe-drawdown-circuit-breaker
Halt trading when portfolio drawdown exceeds threshold.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Halt trading when portfolio drawdown exceeds threshold.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Price, funding, liquidation, and balance alerts using polling and WebSocket on bitmex-cli.
Autonomy progression for bitmex-cli agents: from read-only market data to autonomous fund management.
Delta-neutral basis trading between BitMEX perpetuals and fixed-date futures: entry, monitoring, and exit.
Dollar cost averaging on bitmex-cli: testnet-first, fixed qty per interval, limit orders, and position cap enforcement.
Error category handling, duplicate order prevention, retry logic, and partial fill management for bitmex-cli.
Minimize trading fees on bitmex-cli: maker vs taker, post-only orders, commission tiers, and fee audit.
| name | bitmex-recipe-drawdown-circuit-breaker |
| description | Halt trading when portfolio drawdown exceeds threshold. |
Monitor margin balance against a high-water mark and automatically flatten all positions when drawdown exceeds your configured threshold.
BITMEX_API_KEY and BITMEX_API_SECRET set.jq and bc installed.MAX_DRAWDOWN_PCT=5.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.
HIGH_WATER=$(bitmex account margin --currency XBt -o json | jq '.marginBalance')
echo "$HIGH_WATER" > /tmp/bitmex_hwm.txt
On subsequent checks, load it:
HIGH_WATER=$(cat /tmp/bitmex_hwm.txt)
CURRENT=$(bitmex account margin --currency XBt -o json | jq '.marginBalance')
Note: This circuit breaker covers XBt-denominated positions only. USDT positions require a separate check using
--currency USDt.
DRAWDOWN=$(echo "scale=4; ($HIGH_WATER - $CURRENT) / $HIGH_WATER * 100" | bc)
echo "Current drawdown: ${DRAWDOWN}%"
MAX_DRAWDOWN_PCT=5
if (( $(echo "$DRAWDOWN > $MAX_DRAWDOWN_PCT" | bc -l) )); then
echo "CIRCUIT BREAKER TRIPPED: ${DRAWDOWN}% drawdown exceeds ${MAX_DRAWDOWN_PCT}%"
# Cancel all open orders
bitmex order cancel-all --yes -o json
# Close all open positions
bitmex position list -o json \
| jq -r '[.[] | select(.currentQty != 0) | .symbol] | .[]' \
| while read -r SYM; do
bitmex order close-position "$SYM" -o json
done
echo "All positions closed. Manual review required before resuming."
exit 1
fi
if (( $(echo "$CURRENT > $HIGH_WATER" | bc -l) )); then
echo "$CURRENT" > /tmp/bitmex_hwm.txt
fi
--testnet before connecting to live funds.