# Risk Guard

> 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.

- **Type:** Skill
- **Install:** `agentstack add skill-daviddme-claude-skills-risk-guard`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [daviddme](https://agentstack.voostack.com/s/daviddme)
- **Installs:** 0
- **Category:** [Finance & Payments](https://agentstack.voostack.com/c/finance-and-payments)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [daviddme](https://github.com/daviddme)
- **Source:** https://github.com/daviddme/claude-skills/tree/main/risk-guard

## Install

```sh
agentstack add skill-daviddme-claude-skills-risk-guard
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# 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  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.

```json
{
  "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": []
}
```

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [daviddme](https://github.com/daviddme)
- **Source:** [daviddme/claude-skills](https://github.com/daviddme/claude-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** yes
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-daviddme-claude-skills-risk-guard
- Seller: https://agentstack.voostack.com/s/daviddme
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
