Calculate priced gross open interest from outstanding outcome positions
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user