Fix: Resolved KeyError 'price' by synchronizing engine output keys with dashboard expectations
Browse files- engine/simulation.py +5 -1
engine/simulation.py
CHANGED
|
@@ -404,9 +404,13 @@ class SimulationEngine:
|
|
| 404 |
|
| 405 |
def _record_csv_row(self, tick: int, metrics: TickMetrics, trades: list[Trade]):
|
| 406 |
"""Record a row for the tick-level CSV."""
|
|
|
|
|
|
|
|
|
|
| 407 |
self.csv_rows.append({
|
| 408 |
"tick": tick,
|
| 409 |
-
"
|
|
|
|
| 410 |
"best_bid": metrics.best_bid,
|
| 411 |
"best_ask": metrics.best_ask,
|
| 412 |
"spread": metrics.spread,
|
|
|
|
| 404 |
|
| 405 |
def _record_csv_row(self, tick: int, metrics: TickMetrics, trades: list[Trade]):
|
| 406 |
"""Record a row for the tick-level CSV."""
|
| 407 |
+
# Use mid_price if available, else last known price
|
| 408 |
+
current_price = metrics.mid_price if metrics.mid_price else self.price_history[-1]
|
| 409 |
+
|
| 410 |
self.csv_rows.append({
|
| 411 |
"tick": tick,
|
| 412 |
+
"price": current_price,
|
| 413 |
+
"mid_price": current_price, # keep for compat
|
| 414 |
"best_bid": metrics.best_bid,
|
| 415 |
"best_ask": metrics.best_ask,
|
| 416 |
"spread": metrics.spread,
|