Expose account executions with original order, role and fill economics

This commit is contained in:
2026-12-03 04:12:22 +08:00
parent 5cbbdcbe64
commit 66f42f7b7f
11 changed files with 221 additions and 12 deletions
+14 -8
View File
@@ -102,7 +102,7 @@ pub(crate) fn submit(tx: &Transaction, books: &Books, order: NewOrder) -> Result
tif != TimeInForce::Fak || !fills.is_empty(),
"FAK has no matching liquidity"
);
settle(tx, &market, &outcome, fills)?;
settle(tx, &market, &outcome, fills, Some(seq))?;
}
let (remaining, mut status): (i64, String) = tx.query_row(
"SELECT remaining,status FROM orders WHERE seq=?",
@@ -162,19 +162,20 @@ pub(crate) fn settle(
market: &str,
outcome: &str,
fills: Vec<Fill>,
taker: Option<i64>,
) -> Result<()> {
for f in fills {
let first = book_leg(tx, market, outcome, &f, f.bid)?;
let second = book_leg(tx, market, outcome, &f, f.ask)?;
if first.outcome == second.outcome {
let execution: i64 = if first.outcome == second.outcome {
let (buy, sell) = if first.side == "buy" {
(first, second)
} else {
(second, first)
};
ensure!(buy.side == "buy" && sell.side == "sell", "invalid transfer");
tx.execute("INSERT INTO fills(seq,bid,ask,price,quantity) SELECT id,?1,?2,?3,?4 FROM next_execution",
params![buy.seq,sell.seq,buy.price,f.quantity])?;
tx.query_row("INSERT INTO fills(seq,bid,ask,price,quantity) SELECT id,?1,?2,?3,?4 FROM next_execution RETURNING seq",
params![buy.seq,sell.seq,buy.price,f.quantity], |r|r.get(0))?
} else {
ensure!(first.side == second.side, "invalid complementary legs");
let mint = first.side == "buy";
@@ -195,9 +196,9 @@ pub(crate) fn settle(
} else {
(second, first)
};
tx.execute(
tx.query_row(
"INSERT INTO paired_fills(seq,market,kind,yes_order,no_order,yes_price,quantity)
SELECT id,?1,?2,?3,?4,?5,?6 FROM next_execution",
SELECT id,?1,?2,?3,?4,?5,?6 FROM next_execution RETURNING seq",
params![
market,
if mint { "mint" } else { "merge" },
@@ -206,8 +207,13 @@ pub(crate) fn settle(
yes.price,
f.quantity
],
)?;
}
|r| r.get(0),
)?
};
tx.execute(
"INSERT INTO execution_context(execution,taker_order) VALUES(?,?)",
params![execution, taker],
)?;
for seq in [f.bid, f.ask] {
tx.execute("UPDATE orders SET remaining=remaining-?1,status=CASE WHEN remaining=?1 THEN 'filled' ELSE 'live' END WHERE seq=?2",params![f.quantity,seq])?;
}