Files
robinhood/backend/app/services/simulation_state.py
T
Krikorios 48e60d015f feat: Add Phase 4 advanced metrics and components
- Add advanced metrics dashboard with trade analytics
- Add new trading components (EntryTypeAnalysis, MultiDayPositionTracker, NewsEventTracker, etc.)
- Add strategy mode selector and trend confirmation
- Add risk automation panel and slippage correlation analysis
- Add daily trading plan enhancements with modal components
- Add custom hooks (useApi, useLocalStorage, useAdvancedTradeMetrics)
- Add broker service integration and trading API
- Add test setup and vitest configuration
- Include parquet data files for live market data
- Add comprehensive documentation in docs/ folder
2025-11-27 10:23:58 +02:00

28 lines
975 B
Python

"""Helpers for loading the latest trading simulation snapshot from the database."""
from typing import Any, Dict
from sqlalchemy.orm import Session
from app.api.trading_persistent import get_or_create_simulation, get_portfolio_state_from_db
def load_simulation_state(db: Session, user_id: str = "default") -> Dict[str, Any]:
"""Return the current simulation state as a serializable dict."""
try:
simulation = get_or_create_simulation(db, user_id)
portfolio = get_portfolio_state_from_db(simulation, db)
return portfolio.dict()
except Exception as e:
# If database tables don't exist, return default state
print(f"Warning: Could not load simulation state: {e}")
return {
"cash": 100000.0,
"position": None,
"trades": [],
"total_pnl": 0.0,
"win_rate": 0.0,
"avg_win": 0.0,
"avg_loss": 0.0,
"trade_count": 0
}