Cancel outstanding orders when their trading key misses its heartbeat
This commit is contained in:
@@ -7,6 +7,7 @@ mod catalog;
|
||||
mod estimate;
|
||||
mod expiry;
|
||||
mod fees;
|
||||
mod heartbeat;
|
||||
mod holders;
|
||||
mod twap;
|
||||
mod validation;
|
||||
@@ -70,7 +71,27 @@ impl Exchange {
|
||||
Ok(Self { db, books })
|
||||
}
|
||||
|
||||
pub fn execute(&mut self, payload: Value) -> Result<Value> {
|
||||
/// Run expiry and synchronize the resident book while the transport is idle.
|
||||
pub fn maintain(&mut self) -> Result<()> {
|
||||
let tx = expiry::transaction(&self.db, TransactionBehavior::Deferred)?;
|
||||
let changes = self.books.changes(&tx)?;
|
||||
tx.commit()?;
|
||||
self.books.apply(changes);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn execute(&mut self, mut payload: Value) -> Result<Value> {
|
||||
if payload["op"].as_str() == Some("heartbeat") {
|
||||
payload
|
||||
.as_object_mut()
|
||||
.context("expected object")?
|
||||
.remove("op");
|
||||
let beat: heartbeat::Beat = serde_json::from_value(payload)?;
|
||||
let tx = expiry::transaction(&self.db, TransactionBehavior::Immediate)?;
|
||||
let response = beat.accept(&tx)?;
|
||||
tx.commit()?;
|
||||
return Ok(response);
|
||||
}
|
||||
if matches!(
|
||||
payload["op"].as_str(),
|
||||
Some(
|
||||
|
||||
Reference in New Issue
Block a user