Keep per-instrument order books in memory and recover committed orders

This commit is contained in:
2026-12-03 03:01:52 +08:00
parent d2361f158b
commit 417692633f
11 changed files with 402 additions and 127 deletions
+13
View File
@@ -22,3 +22,16 @@ CREATE TABLE IF NOT EXISTS fills (
CREATE TABLE IF NOT EXISTS requests (
id TEXT PRIMARY KEY, payload TEXT NOT NULL, response TEXT NOT NULL
);
-- Keep only the last change per order. Other connections can catch up by revision.
CREATE TABLE IF NOT EXISTS book_changes (
seq INTEGER PRIMARY KEY REFERENCES orders, revision INTEGER NOT NULL UNIQUE
);
CREATE TRIGGER IF NOT EXISTS book_insert AFTER INSERT ON orders BEGIN
INSERT INTO book_changes(seq, revision)
SELECT NEW.seq, COALESCE(MAX(revision), 0) + 1 FROM book_changes;
END;
CREATE TRIGGER IF NOT EXISTS book_update AFTER UPDATE OF remaining,status ON orders BEGIN
INSERT OR REPLACE INTO book_changes(seq, revision)
SELECT NEW.seq, COALESCE(MAX(revision), 0) + 1 FROM book_changes;
END;