fix: keep Alpaca price as primary (includes after-hours), add polygon_price field
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build-3 Pipeline was successful
ci/woodpecker/push/build-1 Pipeline was successful
ci/woodpecker/push/build-2 Pipeline was successful
ci/woodpecker/push/finalize Pipeline was successful
Build and Push / lint-and-test (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.adapters.broker_adapter name:broker-adapter]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.aggregation.worker name:aggregation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.extractor.worker name:extractor]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.ingestion.worker name:ingestion]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.lake_publisher.worker name:lake-publisher]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.parser.worker name:parser]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.recommendation.worker name:recommendation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.scheduler.app name:scheduler]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.api.app:app --host 0.0.0.0 --port 8000 name:query-api]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.risk.app:app --host 0.0.0.0 --port 8000 name:risk]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.symbol_registry.app:app --host 0.0.0.0 --port 8000 name:symbol-registry]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.trading.app:app --host 0.0.0.0 --port 8000 name:trading-engine]) (push) Has been cancelled
Build and Push / build-dashboard (push) Has been cancelled
Build and Push / build-superset (push) Has been cancelled
Build and Push / integration-test (push) Has been cancelled
Build and Push / beta-gate (push) Has been cancelled

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.
This commit is contained in:
Celes Renata
2026-04-30 22:35:22 +00:00
parent 9a60ce127b
commit 2f2ea65fb4
2 changed files with 4 additions and 6 deletions
+1
View File
@@ -389,6 +389,7 @@ export interface Position {
quantity: number; quantity: number;
avg_entry_price: number; avg_entry_price: number;
current_price: number | null; current_price: number | null;
polygon_price: number | null;
unrealized_pnl: number | null; unrealized_pnl: number | null;
realized_pnl: number | null; realized_pnl: number | null;
updated_at: string; updated_at: string;
+3 -6
View File
@@ -1201,7 +1201,8 @@ async def list_positions(
FROM positions p ORDER BY p.ticker""", 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}) tickers = list({r["ticker"] for r in rows})
price_map: dict[str, float] = {} price_map: dict[str, float] = {}
if tickers: if tickers:
@@ -1218,11 +1219,7 @@ async def list_positions(
for r in rows: for r in rows:
d = _row_to_dict(r) d = _row_to_dict(r)
polygon_price = price_map.get(d["ticker"]) polygon_price = price_map.get(d["ticker"])
if polygon_price: d["polygon_price"] = 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)
results.append(d) results.append(d)
return results return results