fix: widen price matching tolerance for sparse market data
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build-1 Pipeline was successful
ci/woodpecker/push/build-2 Pipeline was successful
ci/woodpecker/push/build-3 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

Only ~9 price bars per ticker (Polygon returns daily bars, not
intraday). Widened gap tolerance to 6h for intraday, 12h for 1d,
etc. Also skip time-range filtering when price data is sparse
(≤20 bars) to avoid showing no prices at all.
This commit is contained in:
Celes Renata
2026-04-29 22:02:23 +00:00
parent 5109c85a3e
commit fa4ad6b15a
+12 -4
View File
@@ -703,8 +703,8 @@ function TrendHistoryChart({ trends, latestTrends, ticker, marketPrices, selecte
.filter((p) => p.bar_timestamp != null && p.close != null) .filter((p) => p.bar_timestamp != null && p.close != null)
.sort((a, b) => a.bar_timestamp - b.bar_timestamp); .sort((a, b) => a.bar_timestamp - b.bar_timestamp);
// Filter prices to the selected window's time range // Filter prices to the selected window's time range (use all prices if sparse)
const windowPrices = sortedPrices.filter((p) => p.bar_timestamp >= cutoffTs); const windowPrices = sortedPrices.length <= 20 ? sortedPrices : sortedPrices.filter((p) => p.bar_timestamp >= cutoffTs);
function findClosestPrice(ts: number): number | undefined { function findClosestPrice(ts: number): number | undefined {
if (windowPrices.length === 0) return undefined; if (windowPrices.length === 0) return undefined;
@@ -717,8 +717,16 @@ function TrendHistoryChart({ trends, latestTrends, ticker, marketPrices, selecte
bestDiff = diff; bestDiff = diff;
} }
} }
// Only match if within 2 hours (for intraday) or 36 hours (for daily) // Match if within reasonable gap for the window type
const maxGap = selectedWindow === 'intraday' ? 2 * 3600_000 : 36 * 3600_000; // With sparse price data (~1 bar per 4-6 hours), use wider tolerances
const maxGapHours: Record<string, number> = {
intraday: 6,
'1d': 12,
'7d': 36,
'30d': 72,
'90d': 168,
};
const maxGap = (maxGapHours[selectedWindow] ?? 36) * 3600_000;
return bestDiff <= maxGap ? best.close : undefined; return bestDiff <= maxGap ? best.close : undefined;
} }