Skip to main content

Real-Time Risk Alerts (WebSocket)

GET /v1/alerts/ws — WebSocket upgrade for real-time risk alert streaming.

Overview

Connect via WebSocket to receive push notifications when risk thresholds are breached for monitored wallets. Alerts are emitted whenever the /v1/monitor/{wallet} endpoint detects threshold violations.

Connection Flow

  1. Connect to wss://api.canonprotocol.org/v1/alerts/ws
  2. Send an AlertConfig JSON message to subscribe
  3. Receive a {"subscribed": "0x..."} confirmation
  4. Receive RiskAlert JSON messages when thresholds breach
  5. Server sends WebSocket pings every 15s for keepalive

AlertConfig (send on connect)

FieldTypeDefaultDescription
walletstringrequiredEthereum wallet address to monitor
thresholds.max_risk_scoreu870Alert when risk score exceeds this
thresholds.min_liquidation_distance_pctf645.0Alert when liq distance drops below this %
thresholds.max_portfolio_var_pctf6450.0Alert when portfolio VaR exceeds this %
thresholds.max_funding_drag_daily_pctf641.0Alert when daily funding drag exceeds this %

Example

{
"wallet": "0x1234567890abcdef1234567890abcdef12345678",
"thresholds": {
"max_risk_score": 60,
"min_liquidation_distance_pct": 8.0
}
}

RiskAlert (received from server)

FieldTypeDescription
alert_typestringliquidation_proximity, high_risk_score, portfolio_var_breach, funding_drag_excessive, regime_shift
walletstringWallet address
assetstring?Asset symbol (null for portfolio-level alerts)
severitystringwarning or critical
messagestringHuman-readable alert description
timestampstringISO 8601 timestamp
current_valuef64Current metric value that triggered the alert
thresholdf64Threshold that was breached

Example Alert

{
"alert_type": "liquidation_proximity",
"wallet": "0x1234...",
"asset": "ETH",
"severity": "critical",
"message": "Liquidation distance 1.8% below threshold 8.0%",
"timestamp": "2026-03-21T18:30:00Z",
"current_value": 1.8,
"threshold": 8.0
}

Severity Levels

  • critical: Risk score >= 85 or liquidation distance < 2% or regime shift to crisis
  • warning: All other threshold breaches

Notes

  • This endpoint does not require authentication (WebSocket connections are stateless)
  • Alerts are only emitted when the monitor endpoint is called (pull-based triggering)
  • Disconnected clients are automatically unsubscribed