Appearance
AccountValueTrackerManager
Manages interaction with AccountValueAggregationTracker DO for peak/bottom account value tracking with eventual consistency.
Purpose
AccountValueTrackerManager bridges UserPaperTradePortfolio and the AccountValueAggregationTracker DO. It subscribes users to tracking when challenges start, sends coefficient updates on every position change, and handles hourly/daily extremes callbacks.
The tracker uses a coefficient-based formula to calculate account value from price data: accountValue = constantTerm + sum(coefficient[token] * price[token]). This avoids re-sending full position data on every update -- only the mathematical coefficients change.
The manager implements an eventual consistency model with sequence numbers. Each position change increments a coefficient_seq, and updates are persisted to a pending_coefficient_updates SQLite table before sending to the tracker. Failed sends are retried with exponential backoff (1m, 5m, 15m, 1h, 2h). Gap detection triggers full reconciliation.
Edge Cases & Error Handling
- Subscription failure is non-fatal: challenge continues without peak tracking
- Account version mismatch on coefficient update triggers automatic re-subscribe
- DUPLICATE responses from tracker are silently accepted (pending entry deleted)
- Gap detection triggers reconciliation: sends all pending updates since the expected seq
- Max 5 retries with exponential backoff before dropping a coefficient update
- MLL warning threshold: 50% of loss allowance remaining
- MLL breach at daily boundary fails challenge immediately
- Daily extremes callback validates account version to reject stale callbacks
See Also
- AnalyticsManager - Stores snapshots from callbacks
- MllRiskManager - MLL breach detection
- UserPaperTradePortfolio - Parent DO