Expire GTD orders before matching, reads and recovery
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
mod account_orders;
|
||||
mod catalog;
|
||||
mod expiry;
|
||||
mod validation;
|
||||
use validation::identifier;
|
||||
mod book;
|
||||
@@ -21,11 +22,11 @@ pub struct Exchange {
|
||||
}
|
||||
impl Exchange {
|
||||
pub fn open(path: impl AsRef<Path>) -> Result<Self> {
|
||||
let mut db = Connection::open(path)?;
|
||||
let 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"))?;
|
||||
let tx = db.transaction()?;
|
||||
let tx = expiry::transaction(&db, TransactionBehavior::Deferred)?;
|
||||
let books = Books::recover(&tx)?;
|
||||
tx.commit()?;
|
||||
Ok(Self { db, books })
|
||||
@@ -37,13 +38,13 @@ impl Exchange {
|
||||
Some("catalog" | "history" | "quote" | "book" | "open_orders" | "positions")
|
||||
) {
|
||||
let query: catalog::Query = serde_json::from_value(payload)?;
|
||||
let tx = self.db.transaction()?;
|
||||
let tx = expiry::transaction(&self.db, TransactionBehavior::Deferred)?;
|
||||
let value = query.read(&tx)?;
|
||||
tx.commit()?;
|
||||
return Ok(value);
|
||||
}
|
||||
if payload == json!({"op":"state"}) {
|
||||
let tx = self.db.transaction()?;
|
||||
let tx = expiry::transaction(&self.db, TransactionBehavior::Deferred)?;
|
||||
let mut state = Map::new();
|
||||
for table in [
|
||||
"accounts",
|
||||
@@ -78,9 +79,7 @@ impl Exchange {
|
||||
}
|
||||
let id = payload["id"].as_str().context("request id required")?;
|
||||
identifier(id)?;
|
||||
let tx = self
|
||||
.db
|
||||
.transaction_with_behavior(TransactionBehavior::Immediate)?;
|
||||
let tx = expiry::transaction(&self.db, TransactionBehavior::Immediate)?;
|
||||
let prior: Option<(String, String)> = tx
|
||||
.query_row(
|
||||
"SELECT payload,response FROM requests WHERE id=?",
|
||||
|
||||
Reference in New Issue
Block a user