Calculate priced gross open interest from outstanding outcome positions

This commit is contained in:
2026-12-03 05:46:00 +08:00
parent 38742fbdec
commit f72d0fe602
10 changed files with 222 additions and 32 deletions
+16
View File
@@ -0,0 +1,16 @@
WITH candidates AS (
SELECT id,phase FROM markets WHERE ?1 IS NULL
UNION ALL
SELECT id,phase FROM markets WHERE id IN (SELECT value FROM json_each(?1))
), selected AS MATERIALIZED (
SELECT m.id,m.phase FROM candidates m
LEFT JOIN augmented_outcomes a ON a.market=m.id
WHERE a.role IS NULL OR a.role<>'placeholder'
), balances AS (
SELECT s.id,p.outcome,SUM(p.available+p.reserved) AS shares,p.payout_per_share
FROM selected s CROSS JOIN position_sizes p ON p.market=s.id
GROUP BY s.id,p.outcome,p.payout_per_share
)
SELECT s.id,s.phase,b.outcome,b.shares,b.payout_per_share
FROM selected s LEFT JOIN balances b ON b.id=s.id
ORDER BY s.id,b.outcome