Skip to content

PriceAlertManager

Handles inbound alert callbacks from PriceAlert DOs for limit orders, stop loss, take profit, and liquidation.

Purpose

PriceAlertManager is the RPC handler for alert callbacks triggered by PriceAlert DOs when price conditions are met. It processes four alert types: LIMIT_ORDER (executes pending limit orders), STOP_LOSS (closes position at stop loss), TAKE_PROFIT (closes position at take profit), and LIQUIDATION_WATCH (liquidates position).

Each alert callback goes through stale alert detection (comparing accountId and alert IDs against current position state) before executing the trade. On successful execution, the manager broadcasts WebSocket events, queues email notifications, and creates in-app notifications.

The manager also handles PENDING_PRICE limit order price arrival, where limit orders that were created before price data was available get evaluated once the price arrives. Orders meeting their condition execute immediately; others transition to ACTIVE status for normal alert monitoring.

Edge Cases & Error Handling

  • Stale alert detection at two levels: (1) accountId mismatch rejects alerts from previous accounts, (2) alert ID mismatch rejects alerts superseded by position updates
  • Limit order execution is idempotent: already-processed orders (EXECUTED/CANCELLED/FAILED) are skipped
  • PENDING_PRICE limit orders that don't meet their condition transition to ACTIVE for normal PriceAlert monitoring
  • Zombie alerts (position not found) are logged and return POSITION_NOT_FOUND
  • Limit order metadata parsing failures are caught and logged; SL/TP are omitted

See Also