feat: add portfolio summary to simulation page
Shows real-time portfolio metrics: - Cash Balance - Position (quantity and value) - Entry Price / Current Price - Unrealized P&L - Total Value - P&L (absolute and percentage) Updates as simulation runs and trades are executed.
This commit is contained in:
@@ -60,6 +60,9 @@ def run_simulation_sync(
|
||||
for k in engine.klines
|
||||
]
|
||||
simulation.trade_log = engine.trade_log
|
||||
# Save portfolio data
|
||||
if hasattr(engine, 'current_balance') and engine.current_balance is not None:
|
||||
simulation.signals = [serialize_signal(s) for s in engine.signals]
|
||||
db.commit()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
@@ -169,6 +169,14 @@ class SimulateEngine:
|
||||
self.results["total_candles"] = self.total_candles
|
||||
self.results["klines"] = self.klines # Include klines for chart display
|
||||
self.results["trade_log"] = self.trade_log # Include trade log for dashboard
|
||||
self.results["portfolio"] = {
|
||||
"initial_balance": self.config.get("initial_balance", 10000),
|
||||
"current_balance": self.current_balance,
|
||||
"position": self.position,
|
||||
"position_token": self.position_token,
|
||||
"entry_price": self.entry_price,
|
||||
"current_price": self.last_close,
|
||||
}
|
||||
self.results["started_at"] = self.started_at
|
||||
self.results["ended_at"] = datetime.utcnow()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user