Resolve up-down markets from exact same-stream TWAP observations
This commit is contained in:
@@ -11,7 +11,8 @@ pub(crate) fn transaction(
|
||||
loop {
|
||||
let tx = Transaction::new_unchecked(db, behavior)?;
|
||||
let due: bool = tx.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM order_deadlines WHERE pending=1 AND expiration<=unixepoch()+60)",
|
||||
"SELECT EXISTS(SELECT 1 FROM order_deadlines WHERE pending=1 AND expiration<=unixepoch()+60)
|
||||
OR EXISTS(SELECT 1 FROM twap_markets WHERE pending_close=1 AND end_at<=unixepoch())",
|
||||
[], |row| row.get(0),
|
||||
)?;
|
||||
if !due {
|
||||
@@ -33,6 +34,16 @@ pub(crate) fn transaction(
|
||||
for (seq, owner) in due {
|
||||
release(&write, seq, &owner, CancelReason::Expired)?;
|
||||
}
|
||||
let mut closing = write.prepare(
|
||||
"SELECT market FROM twap_markets WHERE pending_close=1 AND end_at<=unixepoch()",
|
||||
)?;
|
||||
let markets = closing
|
||||
.query_map([], |r| r.get::<_, String>(0))?
|
||||
.collect::<rusqlite::Result<Vec<_>>>()?;
|
||||
drop(closing);
|
||||
for market in markets {
|
||||
crate::market::close_market(&write, &market)?;
|
||||
}
|
||||
write.commit()?;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user