INNER CODE UNIT · Python
_serialize_snapshot
YichengYang-Ethan/oracle3 · oracle3/dashboard/server.py:29
def _serialize_snapshot(engine: 'TradingEngine') -> dict[str, Any]: # noqa: C901
"""Build a JSON-safe state dict from the engine snapshot.
Re-uses the same data as ControlServer._cmd_get_state() but reads
directly from the engine's get_snapshot() method for cleaner access.
"""
snap = engine.get_snapshot()
# Positions
positions = [
{
'symbol': p.ticker_symbol,
'name': p.ticker_name,
'qty': str(p.quantity),
'avg_cost': str(p.average_cost),
'current_price': str(p.current_price),
'unrealized_pnl': str(p.unrealized_pnl),
}