Keep per-instrument order books in memory and recover committed orders
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::resident::Books;
|
||||
use crate::{
|
||||
book,
|
||||
command::Command,
|
||||
@@ -5,11 +6,10 @@ use crate::{
|
||||
validation::{amount, identifier, phase},
|
||||
};
|
||||
use anyhow::{ensure, Result};
|
||||
use matching::Phase;
|
||||
use rusqlite::{params, Transaction};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
pub(crate) fn apply(tx: &Transaction, command: Command) -> Result<Value> {
|
||||
pub(crate) fn apply(tx: &Transaction, books: &Books, command: Command) -> Result<Value> {
|
||||
match command {
|
||||
Command::Fund { account, cents } => {
|
||||
identifier(&account)?;
|
||||
@@ -54,6 +54,7 @@ pub(crate) fn apply(tx: &Transaction, command: Command) -> Result<Value> {
|
||||
tif,
|
||||
} => book::submit(
|
||||
tx,
|
||||
books,
|
||||
book::NewOrder {
|
||||
market,
|
||||
account,
|
||||
@@ -72,7 +73,9 @@ pub(crate) fn apply(tx: &Transaction, command: Command) -> Result<Value> {
|
||||
Command::Open { market } => {
|
||||
phase(tx, &market, &["preopen"])?;
|
||||
for outcome in ["YES", "NO"] {
|
||||
book::match_book(tx, &market, outcome, Phase::Opening)?;
|
||||
if let Some(book) = books.get(&market, outcome) {
|
||||
book::settle(tx, &market, outcome, book.opening())?;
|
||||
}
|
||||
}
|
||||
tx.execute("UPDATE markets SET phase='continuous' WHERE id=?", [market])?;
|
||||
Ok(json!({"phase":"continuous"}))
|
||||
|
||||
Reference in New Issue
Block a user