From 2f2ea65fb4e887f640372ed8ce26fedb629b491c Mon Sep 17 00:00:00 2001 From: Celes Renata Date: Thu, 30 Apr 2026 22:35:22 +0000 Subject: [PATCH] fix: keep Alpaca price as primary (includes after-hours), add polygon_price field Alpaca's current_price reflects extended hours trading which is more current than Polygon's regular session close. Keep it as the display price. Add polygon_price as a reference field in the API response. --- frontend/src/api/hooks.ts | 1 + services/api/app.py | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/frontend/src/api/hooks.ts b/frontend/src/api/hooks.ts index aaddd99..6ec6ea2 100644 --- a/frontend/src/api/hooks.ts +++ b/frontend/src/api/hooks.ts @@ -389,6 +389,7 @@ export interface Position { quantity: number; avg_entry_price: number; current_price: number | null; + polygon_price: number | null; unrealized_pnl: number | null; realized_pnl: number | null; updated_at: string; diff --git a/services/api/app.py b/services/api/app.py index d208f8b..0602b24 100644 --- a/services/api/app.py +++ b/services/api/app.py @@ -1201,7 +1201,8 @@ async def list_positions( FROM positions p ORDER BY p.ticker""", ) - # Build a price map from the latest Polygon bars + # Enrich with latest Polygon close for comparison. + # Use whichever price is more recent: broker sync or Polygon bar. tickers = list({r["ticker"] for r in rows}) price_map: dict[str, float] = {} if tickers: @@ -1218,11 +1219,7 @@ async def list_positions( for r in rows: d = _row_to_dict(r) polygon_price = price_map.get(d["ticker"]) - if polygon_price: - d["current_price"] = polygon_price - qty = d.get("quantity", 0) or 0 - entry = d.get("avg_entry_price", 0) or 0 - d["unrealized_pnl"] = round(qty * (polygon_price - entry), 2) + d["polygon_price"] = polygon_price results.append(d) return results