INNER CODE UNIT · Python

_load_paper_trade_history

aaryansinha16/AI-trader · backend/app.py:89

def _load_paper_trade_history():
    """Load closed paper trade history from JSONL files on startup."""
    global _closed_trades_by_mode
    _PAPER_TRADES_DIR.mkdir(exist_ok=True)
    for mode in ("test", "live"):
        fpath = _paper_trades_file(mode)
        if fpath.exists():
            try:
                trades = []
                for line in fpath.read_text().splitlines():
                    line = line.strip()
                    if line:
                        trades.append(json.loads(line))
                _closed_trades_by_mode[mode] = trades
                logger.info(f"Loaded {len(trades)} closed {mode} paper trades from history")
            except Exception as e:
                logger.warning(f"Failed to load paper trade history ({mode}): {e}")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…