Expose negative-risk membership and convert fractional outcome balances

This commit is contained in:
2026-12-03 12:56:07 +08:00
parent f7946d2277
commit 351de6187e
13 changed files with 233 additions and 45 deletions
+23 -14
View File
@@ -72,15 +72,20 @@ pub(crate) fn movement(
tx: &Transaction,
request: &str,
account: &str,
market: &str,
target: &str,
kind: &str,
shares: i64,
cash: i64,
) -> Result<()> {
let (market, group_id) = if kind == "CONVERSION" {
(None, Some(target))
} else {
(Some(target), None)
};
tx.execute(
"INSERT INTO wallet_movements(request_id,account,kind,market,shares,cash_delta,at_ms)
VALUES(?,?,?,?,?,?,CAST(unixepoch('subsec')*1000 AS INTEGER))",
params![request, account, kind, market, shares / UNIT, cash / 10000],
"INSERT INTO wallet_movements(request_id,account,kind,market,group_id,shares,cash_delta,at_ms)
VALUES(?,?,?,?,?,?,?,CAST(unixepoch('subsec')*1000 AS INTEGER))",
params![request, account, kind, market, group_id, shares / UNIT, cash / 10000],
)?;
tx.execute(
"INSERT INTO precise_movements VALUES(?,?,?,?)",
@@ -89,6 +94,19 @@ pub(crate) fn movement(
Ok(())
}
pub(crate) fn quantity_units(qty: Option<i64>, qty_micros: Option<i64>) -> Result<i64> {
Ok(match (qty, qty_micros) {
(Some(q), None) => {
crate::validation::amount(q)?;
q * UNIT
}
(None, Some(u)) if (1..=1_000_000_000 * UNIT).contains(&u) => u,
_ => anyhow::bail!(
"provide exactly one positive qty or qty_micros within the quantity limit"
),
})
}
pub(crate) fn pairs(
tx: &Transaction,
request: &str,
@@ -108,16 +126,7 @@ pub(crate) fn pairs(
&["preopen", "continuous", "closed"][..]
},
)?;
let units = match (qty, qty_micros) {
(Some(q), None) => {
crate::validation::amount(q)?;
q * UNIT
}
(None, Some(u)) if (1..=1_000_000_000 * UNIT).contains(&u) => u,
_ => anyhow::bail!(
"provide exactly one positive qty or qty_micros within the quantity limit"
),
};
let units = quantity_units(qty, qty_micros)?;
let delta = if split { units } else { -units };
ledger::cash_micros(tx, account, -delta)?;
for outcome in ["YES", "NO"] {