Retain submission time and instructions for live and terminal orders

This commit is contained in:
2026-12-03 14:30:12 +08:00
parent 3bec895a0a
commit 2a6332620c
8 changed files with 133 additions and 4 deletions
@@ -0,0 +1,20 @@
BEGIN IMMEDIATE;
CREATE TABLE IF NOT EXISTS order_submissions (
order_seq INTEGER PRIMARY KEY REFERENCES orders(seq),
order_type TEXT NOT NULL,
post_only INTEGER NOT NULL CHECK(post_only IN (0,1)),
created_at INTEGER DEFAULT (unixepoch())
);
-- Old receipts preserve the accepted instruction but do not record when it was submitted.
INSERT INTO order_submissions(order_seq,order_type,post_only,created_at)
SELECT o.seq, COALESCE(json_extract(r.payload,'$.tif'),
CASE WHEN json_extract(r.payload,'$.op') IN ('market_buy','market_sell') THEN 'FAK'
WHEN d.seq IS NOT NULL THEN 'GTD' ELSE 'GTC' END),
COALESCE(json_extract(r.payload,'$.post_only'),0), NULL
FROM requests r JOIN orders o ON o.seq=json_extract(r.response,'$.order')
LEFT JOIN order_deadlines d ON d.seq=o.seq
WHERE json_extract(r.payload,'$.op') IN ('order','market_buy','market_sell')
AND json_type(r.response,'$.order')='integer'
ON CONFLICT(order_seq) DO NOTHING;
COMMIT;