Port the simulator to a Rust workspace and document each crate

This commit is contained in:
2026-12-03 02:53:46 +08:00
parent b7579603f9
commit 2f3c699e9c
25 changed files with 1320 additions and 371 deletions
+28
View File
@@ -0,0 +1,28 @@
use anyhow::{ensure, Result};
use rusqlite::{params, Transaction};
pub(crate) fn cash(tx: &Transaction, account: &str, delta: i64) -> Result<()> {
ensure!(
tx.execute(
"UPDATE accounts SET cash=cash+? WHERE id=? AND cash+?>=0",
params![delta, account, delta]
)? == 1,
"unknown account or insufficient cash"
);
Ok(())
}
pub(crate) fn position(
tx: &Transaction,
account: &str,
market: &str,
outcome: &str,
delta: i64,
) -> Result<()> {
tx.execute(
"INSERT OR IGNORE INTO positions VALUES(?,?,?,0)",
params![account, market, outcome],
)?;
ensure!(tx.execute("UPDATE positions SET quantity=quantity+? WHERE account=? AND market=? AND outcome=? AND quantity+?>=0",params![delta,account,market,outcome,delta])?==1,"insufficient position");
Ok(())
}