Refactor execution boundaries and add durable strategy recovery

This commit is contained in:
Boki 2026-10-21 12:23:43 -04:00
parent d6b09eb635
commit 694c48bbdb
36 changed files with 3077 additions and 491 deletions

View file

@ -0,0 +1,23 @@
-- Append-only market/execution inputs, bounded strategy checkpoints, transactional order outbox.
-- Legacy event fingerprints have no payload and cannot be fabricated into replayable history.
CREATE TABLE IF NOT EXISTS simulation_market_inputs (
account_id TEXT NOT NULL REFERENCES simulation_accounts(id), id TEXT NOT NULL,
sequence BIGINT NOT NULL, status TEXT NOT NULL CHECK(status IN ('pending','applied')),
payload JSONB NOT NULL, PRIMARY KEY(account_id,id), UNIQUE(account_id,sequence)
);
CREATE INDEX IF NOT EXISTS simulation_pending_inputs ON simulation_market_inputs(account_id,status,sequence);
CREATE TABLE IF NOT EXISTS simulation_strategy_journal (
account_id TEXT NOT NULL REFERENCES simulation_accounts(id), sequence BIGINT NOT NULL,
payload JSONB NOT NULL, PRIMARY KEY(account_id,sequence)
);
CREATE TABLE IF NOT EXISTS simulation_strategy_checkpoints (
account_id TEXT NOT NULL REFERENCES simulation_accounts(id), strategy_id TEXT NOT NULL,
payload JSONB NOT NULL, PRIMARY KEY(account_id,strategy_id)
);
CREATE TABLE IF NOT EXISTS simulation_strategy_intents (
account_id TEXT NOT NULL, client_order_id TEXT NOT NULL, strategy_id TEXT NOT NULL,
sequence BIGINT NOT NULL, status TEXT NOT NULL CHECK(status IN ('pending','dispatched')),
payload JSONB NOT NULL, PRIMARY KEY(account_id,client_order_id),
FOREIGN KEY(account_id,strategy_id) REFERENCES simulation_strategy_checkpoints(account_id,strategy_id)
);
CREATE INDEX IF NOT EXISTS simulation_pending_intents ON simulation_strategy_intents(account_id,status,sequence);