| name | risk-guard |
| description | Single source of truth for trading session P&L, per-trade risk cap, and daily drawdown kill-switch. Always called by bybit-trade before any order; also exposes status/init/open/close subcommands. Use for "what's my P&L / am I within risk limits / reset my session". Stateful, no network, no API keys. |
risk-guard
Stateful session tracker. Records every trade, enforces the per-trade risk
cap and daily drawdown limit, and acts as a veto gate for bybit-trade.
When to use
- "Initialize my trading session at $500 equity"
- "What's my P&L today?"
- "Am I allowed to risk $30 on this?"
- Called as a subprocess by
bybit-trade before every order (not by the user)
How to run
All subcommands accept --state-file PATH (default: ~/.claude/skills/risk-guard/state.json).
# Start a session (overwrites existing state after confirmation)
python risk-guard/guard.py init --equity 500 \
[--per-trade-risk-cap 25] [--daily-drawdown-limit 150]
# Veto gate — exit 0 if allowed, exit 2 if blocked
python risk-guard/guard.py check --risk-usd 25
# Record an opened position (called by bybit-trade after a successful order)
python risk-guard/guard.py open \
--order-link-id clive-SOLUSDT-1719000000000 \
--symbol SOLUSDT --side long \
--qty 11.2 --entry 148.20 --sl 145.97 --tp 151.16 --risk-usd 25
# Close it
python risk-guard/guard.py close \
--order-link-id clive-SOLUSDT-1719000000000 \
--exit 151.16 --realized-pnl 33.15
# Human-readable or JSON status
python risk-guard/guard.py status [--json]
Block conditions (exit 2)
check exits 2 with an explanation in stderr if ANY of:
- state file missing (you must run
init first)
realized_pnl <= -daily_drawdown_limit (drawdown kill-switch)
risk_usd > per_trade_risk_cap (this trade would breach the per-trade cap)
There is no override flag. This is intentional — bybit-trade invokes
check as a subprocess and treats any non-zero exit as a hard veto.
Exit codes
- 0 — allowed / success
- 1 — argument error (missing required fields, invalid state)
- 2 — veto (cap or drawdown tripped, or state missing)
State file shape
Human-readable JSON. Open it. Read it. Don't trust.
{
"session_id": "2026-04-22T15:00:00Z",
"started_at": "2026-04-22T15:00:00Z",
"equity_start": 500.0,
"realized_pnl": 0.0,
"per_trade_risk_cap": 25.0,
"daily_drawdown_limit": 150.0,
"trades": [],
"open_positions": []
}