Unify simulation order execution and persist paper accounting
This commit is contained in:
parent
7dec0be3b4
commit
63c3856797
37 changed files with 3901 additions and 3043 deletions
22
database/postgres/init/11-simulation-execution-ledger.sql
Normal file
22
database/postgres/init/11-simulation-execution-ledger.sql
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
-- Separate, account-scoped paper ledger. Existing trading/backtest history is untouched.
|
||||
CREATE TABLE IF NOT EXISTS simulation_accounts (
|
||||
id TEXT PRIMARY KEY, state JSONB NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS simulation_orders (
|
||||
id UUID PRIMARY KEY, account_id TEXT NOT NULL REFERENCES simulation_accounts(id),
|
||||
client_order_id TEXT NOT NULL, status TEXT NOT NULL,
|
||||
payload JSONB NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE(account_id,client_order_id), UNIQUE(account_id,id),
|
||||
CHECK(status IN ('accepted','partiallyFilled','filled','cancelled','rejected'))
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS simulation_open_orders ON simulation_orders(account_id,status);
|
||||
CREATE TABLE IF NOT EXISTS simulation_fills (
|
||||
account_id TEXT NOT NULL, id TEXT NOT NULL, order_id UUID NOT NULL, payload JSONB NOT NULL,
|
||||
PRIMARY KEY(account_id,id),
|
||||
FOREIGN KEY(account_id,order_id) REFERENCES simulation_orders(account_id,id)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS simulation_events (
|
||||
account_id TEXT NOT NULL REFERENCES simulation_accounts(id), id TEXT NOT NULL,
|
||||
fingerprint TEXT NOT NULL, PRIMARY KEY(account_id,id)
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue