Reconstruct trade-only position basis and realized results
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
SELECT t.side,t.price,t.quantity,COALESCE(f.fee_micros,0)
|
||||
FROM wallet_trade_legs t
|
||||
LEFT JOIN execution_fees f ON f.execution=t.execution AND f.taker_order=t.order_seq
|
||||
WHERE t.account=?1 AND t.market=?2 AND t.outcome=?3
|
||||
-- A fill-only reconstruction cannot assign basis to these custody changes.
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM wallet_movements w
|
||||
WHERE w.account=?1 AND w.market=?2 AND w.kind IN ('SPLIT','MERGE','REDEEM')
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM neg_risk_members n WHERE n.market=?2 AND (
|
||||
EXISTS (SELECT 1 FROM wallet_movements w
|
||||
WHERE w.account=?1 AND w.group_id=n.group_id AND w.kind='CONVERSION')
|
||||
OR EXISTS (SELECT 1 FROM neg_risk_conversion_fees f
|
||||
WHERE f.group_id=n.group_id AND f.vault=?1)
|
||||
)
|
||||
)
|
||||
ORDER BY t.execution,t.order_seq
|
||||
Reference in New Issue
Block a user