Phase 1: Add MAE/MFE tracking and analytics schema
- Added 20+ analytics fields to Trade model (MAE/MFE, fill tracking, timing, market context, slippage) - Implemented real-time MAE/MFE tracking in Position Manager (updates every 5s) - Enhanced database schema with comprehensive trade analytics - Updated all API endpoints to initialize MAE/MFE fields - Modified updateTradeState() to persist MAE/MFE in configSnapshot Database changes: - maxFavorableExcursion/maxAdverseExcursion track best/worst profit % - maxFavorablePrice/maxAdversePrice track exact price levels - Fill tracking: tp1Filled, tp2Filled, softSlFilled, hardSlFilled - Timing metrics: timeToTp1, timeToTp2, timeToSl - Market context: atrAtEntry, adxAtEntry, volumeAtEntry, fundingRateAtEntry, basisAtEntry - Slippage tracking: expectedEntryPrice, entrySlippagePct, expectedExitPrice, exitSlippagePct Position Manager changes: - Track MAE/MFE on every price check (2s interval) - Throttled database updates (5s interval) via updateTradeMetrics() - Persist MAE/MFE in trade state snapshots for recovery Next: Phase 2 (market context capture) or Phase 3 (analytics API)
This commit is contained in:
@@ -49,6 +49,39 @@ model Trade {
|
||||
maxDrawdown Float? // Peak to valley during trade
|
||||
maxGain Float? // Peak gain reached
|
||||
|
||||
// MAE/MFE Analysis (Maximum Adverse/Favorable Excursion)
|
||||
maxFavorableExcursion Float? // Best profit % reached during trade
|
||||
maxAdverseExcursion Float? // Worst drawdown % during trade
|
||||
maxFavorablePrice Float? // Best price hit (direction-aware)
|
||||
maxAdversePrice Float? // Worst price hit (direction-aware)
|
||||
|
||||
// Exit details - which levels actually filled
|
||||
tp1Filled Boolean @default(false)
|
||||
tp2Filled Boolean @default(false)
|
||||
softSlFilled Boolean @default(false)
|
||||
hardSlFilled Boolean @default(false)
|
||||
tp1FillPrice Float?
|
||||
tp2FillPrice Float?
|
||||
slFillPrice Float?
|
||||
|
||||
// Timing metrics
|
||||
timeToTp1 Int? // Seconds from entry to TP1 fill
|
||||
timeToTp2 Int? // Seconds from entry to TP2 fill
|
||||
timeToSl Int? // Seconds from entry to SL hit
|
||||
|
||||
// Market context at entry
|
||||
atrAtEntry Float? // ATR% when trade opened
|
||||
adxAtEntry Float? // ADX trend strength (0-50)
|
||||
volumeAtEntry Float? // Volume relative to MA
|
||||
fundingRateAtEntry Float? // Perp funding rate at entry
|
||||
basisAtEntry Float? // Perp-spot basis at entry
|
||||
|
||||
// Slippage tracking
|
||||
expectedEntryPrice Float? // Target entry from signal
|
||||
entrySlippagePct Float? // Actual slippage %
|
||||
expectedExitPrice Float? // Which TP/SL should have hit
|
||||
exitSlippagePct Float? // Exit slippage %
|
||||
|
||||
// Order signatures
|
||||
entryOrderTx String
|
||||
tp1OrderTx String?
|
||||
|
||||
Reference in New Issue
Block a user