Model sports events and market rules and persist trade price history

This commit is contained in:
2026-12-03 03:30:07 +08:00
parent ca45f83038
commit 9708d701c2
9 changed files with 386 additions and 1 deletions
+40 -1
View File
@@ -17,13 +17,52 @@ pub(crate) fn apply(tx: &Transaction, books: &Books, command: Command) -> Result
tx.execute("INSERT INTO accounts VALUES(?,?)", params![account, cents])?;
Ok(json!({"funded":cents}))
}
Command::List { market, rules } => {
Command::Event {
event,
title,
sport,
competition,
home,
away,
scheduled_at_ms,
} => {
identifier(&event)?;
ensure!(
scheduled_at_ms >= 0
&& home.trim() != away.trim()
&& [&title, &sport, &competition, &home, &away]
.iter()
.all(|s| !s.trim().is_empty()),
"invalid event"
);
tx.execute(
"INSERT INTO events VALUES(?,?,?,?,?,?,?)",
params![
event,
title,
sport,
competition,
home,
away,
scheduled_at_ms
],
)?;
Ok(json!({"event":event}))
}
Command::List {
market,
rules,
listing,
} => {
identifier(&market)?;
ensure!(!rules.trim().is_empty(), "rules required");
tx.execute(
"INSERT INTO markets(id,rules,phase) VALUES(?,?,'preopen')",
params![market, rules],
)?;
if let Some(listing) = listing {
listing.save(tx, &market)?;
}
Ok(json!({"phase":"preopen"}))
}
Command::Split {