Risk Management

Per-user stop-loss, take-profit, drawdown freeze, position cap and cool-down — enforced on both Binance API and internal trades

What Risk Management Does

The Risk Management module is a pre-trade gate that blocks orders breaching user-defined risk limits. Each user gets stop-loss, take-profit, daily drawdown, position size cap, and cool-down controls — and the same engine applies whether the order is routed to Binance or matched on the internal exchange.

🛡️ Risk Controls

  • Max Position Size: per-trade quote cost cannot exceed N% of the user's balance
  • Daily Loss Limit: trades blocked once today's net PnL drops below -N%
  • Drawdown Freeze: trades blocked when current equity is N% below the user's peak
  • Consecutive-Loss Cooldown: after K losses inside a lookback window, lock out for M minutes
  • Per-User Override: users can tighten their own limits below the admin defaults

Where Limits Apply

Limits are enforced uniformly across both order pathways:

Exchange Hook Behaviour
BINANCE wpcrypto_risk_check_policy() before the Binance order is sent Order is rejected client-side with the failing reason returned to the UI
MYEXCHANGE (internal) Same hook called inside the exchange module before insert Order never reaches the matcher; user sees the same error message

Per-User Settings

Users open Profile → Risk to see and tighten their own limits. The form mirrors the standard profile-tab style used across the plugin.

Setting Default Meaning
enabled1Master switch for the user's policy
max_position_pct25Max quote-cost per order, as % of the user's balance
daily_loss_limit_pct10Block trades once today's PnL is below -N%
drawdown_freeze_pct20Block trades when equity falls N% below the recorded peak
consecutive_loss_threshold3Losses in lookback that trigger a cool-down
cooldown_minutes30Minutes the user is locked out after the threshold is hit
loss_lookback_minutes240Window in which the consecutive-loss counter resets

Admin Defaults

Admins configure defaults at WPCrypto → Risk Management. Per-user values fall back to these defaults when the user has not explicitly saved their own. The admin page lists active locks (cooldown, drawdown freeze) and lets you clear a lock manually if a user is incorrectly stuck.

How Daily PnL and Drawdown Are Tracked

The module snapshots each user's equity at the start of every day and uses that snapshot as the baseline for the daily-loss check; this way the percentage is stable even as trades come in. It also keeps a running peak equity per user for the drawdown check. Drawdown freeze only kicks in once the user has a meaningful balance — empty accounts (current ≤ $10 equivalent) are exempt so new users can trade.

After Every Fill

The risk module listens for filled trades. A losing fill advances the consecutive-loss counter; a profitable fill leaves it alone. When too many losses happen inside the lookback window, the cool-down lock is applied and the user sees a friendly "too many losses, paused for X minutes" message on the next order attempt.

Conditional Orders

Stop-loss, take-profit, trailing-stop and OCO orders live in a sister module — see the dedicated Conditional Orders page for details.

⚠️ Operator Notes

  • Defaults are intentionally permissive; tighten the drawdown freeze and the daily-loss limit on production sites with real money.
  • If you migrate balances and the user's recorded peak no longer makes sense, reset it from the admin Risk Management screen so the drawdown check starts fresh.
  • Risk locks always return a user-facing reason — surface it in your own UI so traders understand why an order was blocked.