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
+9 -1
View File
@@ -19,6 +19,7 @@ mod command;
mod inventory;
mod kickoff;
mod ledger;
mod lots;
mod market;
mod minimum_size;
mod neg_risk;
@@ -44,7 +45,7 @@ pub struct Exchange {
}
impl Exchange {
pub fn open(path: impl AsRef<Path>) -> Result<Self> {
let db = Connection::open(path)?;
let mut db = Connection::open(path)?;
db.busy_timeout(Duration::from_secs(10))?;
db.execute_batch("PRAGMA foreign_keys=ON")?;
db.execute_batch(include_str!("schema.sql"))?;
@@ -77,6 +78,7 @@ impl Exchange {
if !marks_ready {
db.execute_batch(include_str!("valuation_schema.sql"))?;
}
lots::migrate(&mut db)?;
let tx = expiry::transaction(&db, TransactionBehavior::Deferred)?;
let books = Books::recover(&tx)?;
tx.commit()?;
@@ -169,6 +171,12 @@ impl Exchange {
for (i, name) in names.iter().enumerate() {
let v = match row.get_ref(i)? {
ValueRef::Null => Value::Null,
ValueRef::Integer(n)
if matches!(table, "orders" | "fills" | "paired_fills")
&& matches!(name.as_str(), "quantity" | "remaining") =>
{
json!(lots::display(n))
}
ValueRef::Integer(n) => json!(n),
ValueRef::Text(s) => json!(std::str::from_utf8(s)?),
_ => anyhow::bail!("unexpected column type"),