Expire GTD orders before matching, reads and recovery

This commit is contained in:
2026-12-03 04:05:29 +08:00
parent 3bff1c0bc3
commit d43c958ff2
10 changed files with 220 additions and 19 deletions
+11
View File
@@ -82,3 +82,14 @@ CREATE VIEW IF NOT EXISTS visible_orders AS
SELECT market,CASE outcome WHEN 'YES' THEN 'NO' ELSE 'YES' END,
CASE side WHEN 'buy' THEN 'sell' ELSE 'buy' END,100-price,remaining
FROM orders WHERE status='live';
CREATE TABLE IF NOT EXISTS order_deadlines (
seq INTEGER PRIMARY KEY REFERENCES orders,
expiration INTEGER NOT NULL,
pending INTEGER NOT NULL DEFAULT 1 CHECK(pending IN (0,1))
);
CREATE INDEX IF NOT EXISTS pending_deadlines ON order_deadlines(expiration) WHERE pending=1;
CREATE TRIGGER IF NOT EXISTS finish_deadline AFTER UPDATE OF status ON orders
WHEN OLD.status='live' AND NEW.status<>'live' BEGIN
UPDATE order_deadlines SET pending=0 WHERE seq=NEW.seq;
END;