feat: math core v3 engine upgrade

This commit is contained in:
Celes Renata
2026-06-27 12:21:41 +00:00
parent 365bc5d4b7
commit b4bf0f2361
34 changed files with 11693 additions and 3 deletions
+8 -2
View File
@@ -456,7 +456,7 @@ async def list_trend_history(
dominant_catalysts, material_risks, generated_at
FROM trend_history
{where}
ORDER BY generated_at ASC
ORDER BY generated_at DESC
LIMIT ${idx}""",
*params, limit,
)
@@ -470,6 +470,9 @@ async def list_trend_history(
d["dominant_catalysts"] = _parse_jsonb(d.get("dominant_catalysts"))
d["material_risks"] = _parse_jsonb(d.get("material_risks"))
results.append(d)
# Return in ascending order for chart rendering (query fetches newest first
# so the LIMIT captures recent data relevant to short time windows).
results.reverse()
return results
@@ -496,7 +499,7 @@ async def get_market_prices(
(data->>'t')::bigint AS bar_timestamp
FROM market_snapshots
WHERE ticker = $1 AND snapshot_type = 'bar'
ORDER BY captured_at ASC
ORDER BY captured_at DESC
LIMIT $2""",
ticker, limit,
)
@@ -521,6 +524,9 @@ async def get_market_prices(
"bar_timestamp": bar_ts,
"captured_at": r["captured_at"].isoformat() if r["captured_at"] else None,
})
# Reverse to ascending order for chart rendering (query fetches newest first
# so the LIMIT captures recent data relevant to short time windows).
results.reverse()
# Compute 90-day high/low from all bars in the window
cutoff_90d = datetime.now(timezone.utc) - timedelta(days=90)