Match fractional share lots and preserve order quantities across restart

This commit is contained in:
2026-12-03 07:01:24 +08:00
parent 2c4179a64e
commit 064b301ebd
27 changed files with 343 additions and 111 deletions
+18
View File
@@ -0,0 +1,18 @@
-- Caller holds an IMMEDIATE transaction and checks the format marker under the lock.
-- Fail the transaction if any integer would be promoted to SQLite REAL.
CREATE TABLE order_lot_format (version INTEGER PRIMARY KEY CHECK(version=1));
INSERT INTO order_lot_format
SELECT CASE WHEN EXISTS(SELECT 1 FROM orders WHERE MAX(quantity,remaining)>92233720368547758)
OR EXISTS(SELECT 1 FROM fills WHERE quantity>92233720368547758)
OR EXISTS(SELECT 1 FROM paired_fills WHERE quantity>92233720368547758)
OR EXISTS(SELECT 1 FROM trade_prices WHERE quantity>92233720368547758)
THEN 0 ELSE 1 END;
UPDATE orders SET quantity=quantity*100,remaining=remaining*100;
UPDATE fills SET quantity=quantity*100;
UPDATE paired_fills SET quantity=quantity*100;
UPDATE trade_prices SET quantity=quantity*100;
DROP VIEW position_units;
CREATE VIEW position_units AS
SELECT p.account,p.market,p.outcome,p.available*1000000+COALESCE(r.micros,0) AS available,
p.reserved*10000 AS reserved,p.phase,p.payout_per_share
FROM position_sizes p LEFT JOIN position_remainders r USING(account,market,outcome);