Serve time-bucketed token prices and point-in-time settlement history
This commit is contained in:
@@ -218,3 +218,14 @@ CREATE TABLE IF NOT EXISTS augmented_results (
|
||||
CREATE TRIGGER IF NOT EXISTS reject_placeholder_orders BEFORE INSERT ON orders
|
||||
WHEN EXISTS(SELECT 1 FROM augmented_outcomes WHERE market=NEW.market AND role='placeholder')
|
||||
BEGIN SELECT RAISE(ABORT,'outcome has not been named'); END;
|
||||
|
||||
-- Existing resolved rows have no trustworthy settlement timestamp to backfill.
|
||||
CREATE TABLE IF NOT EXISTS price_settlements (
|
||||
id INTEGER PRIMARY KEY, market TEXT NOT NULL UNIQUE REFERENCES markets,
|
||||
winner TEXT NOT NULL, at_ms INTEGER NOT NULL
|
||||
);
|
||||
CREATE TRIGGER IF NOT EXISTS record_price_settlement AFTER UPDATE OF phase ON markets
|
||||
WHEN NEW.phase='resolved' AND OLD.phase<>'resolved' BEGIN
|
||||
INSERT INTO price_settlements(market,winner,at_ms)
|
||||
VALUES(NEW.id,NEW.winner,CAST(unixepoch('subsec')*1000 AS INTEGER));
|
||||
END;
|
||||
|
||||
Reference in New Issue
Block a user