Model sports events and market rules and persist trade price history
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user