Serve the CLOB price history protocol with minute-based fidelity

This commit is contained in:
2026-12-03 10:18:43 +08:00
parent 74749bfdb8
commit fe69e31929
10 changed files with 201 additions and 1 deletions
@@ -0,0 +1,13 @@
-- Return the last observed price in each UTC fidelity window at its actual time.
WITH observations(ms, micros, sequence, payout) AS (
SELECT at_ms, price_micros, fill, 0 FROM outcome_trade_prices
WHERE market=?1 AND outcome=?2 AND at_ms BETWEEN ?3 AND ?4
UNION ALL
SELECT at_ms, CASE WHEN winner='VOID' THEN 500000 WHEN winner=?2 THEN 1000000 ELSE 0 END, id, 1
FROM price_settlements WHERE market=?1 AND at_ms BETWEEN ?3 AND ?4
), ranked AS (
SELECT ms, micros, ROW_NUMBER() OVER (
PARTITION BY ms/1000/?5 ORDER BY ms DESC, payout DESC, sequence DESC
) AS position FROM observations
)
SELECT ms/1000, micros FROM ranked WHERE position=1 ORDER BY ms