Merge available binary share pairs back into collateral

This commit is contained in:
2026-12-03 03:41:41 +08:00
parent 8116c8ce8b
commit 6736619277
4 changed files with 75 additions and 1 deletions
+5
View File
@@ -27,6 +27,11 @@ pub(crate) enum Command {
account: String,
qty: i64,
},
Merge {
market: String,
account: String,
qty: i64,
},
Order {
market: String,
account: String,
+20
View File
@@ -83,6 +83,26 @@ pub(crate) fn apply(tx: &Transaction, books: &Books, command: Command) -> Result
}
Ok(json!({"pairs":qty}))
}
Command::Merge {
market,
account,
qty,
} => {
identifier(&account)?;
amount(qty)?;
phase(tx, &market, &["preopen", "continuous", "closed"])?;
let cents = 100 * qty;
for outcome in ["YES", "NO"] {
ledger::position(tx, &account, &market, outcome, -qty)?;
}
let released = tx.execute(
"UPDATE markets SET collateral=collateral-?1 WHERE id=?2 AND collateral>=?1",
params![cents, market],
)?;
ensure!(released == 1, "insufficient collateral");
ledger::cash(tx, &account, cents)?;
Ok(json!({"pairs":qty,"released_cents":cents}))
}
Command::Order {
market,
account,