Skip to content

Commit

Permalink
chore: Set expired limit orders to failed
Browse files Browse the repository at this point in the history
  • Loading branch information
holzeis committed Sep 14, 2023
1 parent e326854 commit 2be5881
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions coordinator/src/orderbook/db/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ pub fn set_order_state(
Ok(OrderbookOrder::from(order))
}

pub fn set_expired_limit_orders_to_failed(conn: &mut PgConnection) -> QueryResult<usize> {
diesel::update(orders::table)
.filter(orders::order_state.eq(OrderState::Open))
.filter(orders::order_type.eq(OrderType::Limit))
.filter(orders::expiry.lt(OffsetDateTime::now_utc()))
.set(orders::order_state.eq(OrderState::Failed))
.execute(conn)
}

/// Returns the order by id
pub fn get_with_id(conn: &mut PgConnection, uid: Uuid) -> QueryResult<Option<OrderbookOrder>> {
let x = orders::table
Expand Down
7 changes: 7 additions & 0 deletions coordinator/src/orderbook/trading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ impl Trading {
}

let mut conn = self.pool.get()?;

// before processing any match we set all expired limit orders to failed, to ensure the do
// not get matched.
// todo(holzeis): orders should probably do not have an expiry, but should either be
// replaced or deleted if not wanted anymore.
orders::set_expired_limit_orders_to_failed(&mut conn)?;

let order = orders::insert(&mut conn, new_order.clone(), order_reason)
.map_err(|e| anyhow!("Failed to insert new order into db: {e:#}"))?;

Expand Down

0 comments on commit 2be5881

Please sign in to comment.