From f2a273b61ad533e64e8610e9e68b783b4162fa4c Mon Sep 17 00:00:00 2001 From: Philipp Hoenisch Date: Fri, 15 Dec 2023 15:22:04 +0100 Subject: [PATCH] chore: update rust doc --- mobile/native/src/db/mod.rs | 2 +- mobile/native/src/trade/order/handler.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/mobile/native/src/db/mod.rs b/mobile/native/src/db/mod.rs index d3474c06f..4ff507931 100644 --- a/mobile/native/src/db/mod.rs +++ b/mobile/native/src/db/mod.rs @@ -211,7 +211,7 @@ pub fn get_filled_orders() -> Result> { Ok(orders) } -/// Returns an order of there is currently an order that is open +/// Returns all open orders pub fn maybe_get_open_orders() -> Result> { let mut db = connection()?; let orders = Order::get_by_state(OrderState::Open, &mut db)?; diff --git a/mobile/native/src/trade/order/handler.rs b/mobile/native/src/trade/order/handler.rs index 34ce608c6..f2ba34cbf 100644 --- a/mobile/native/src/trade/order/handler.rs +++ b/mobile/native/src/trade/order/handler.rs @@ -132,8 +132,9 @@ fn get_order_being_filled() -> Result { Ok(order_being_filled) } +/// Checks open orders and sets them as failed in case they timed out. pub fn check_open_orders() -> Result<()> { - let orders_being_filled = match maybe_get_open_orders() { + let open_orders = match maybe_get_open_orders() { Ok(orders_being_filled) => orders_being_filled, Err(e) => { bail!("Error when loading open orders from database: {e:#}"); @@ -142,10 +143,11 @@ pub fn check_open_orders() -> Result<()> { let now = OffsetDateTime::now_utc(); - for order_being_filled in orders_being_filled { - if order_being_filled.creation_timestamp + ORDER_OUTDATED_AFTER < now { + for open_order in open_orders { + tracing::debug!(?open_order, "Checking order if it is still up to date"); + if open_order.creation_timestamp + ORDER_OUTDATED_AFTER < now { order_failed( - Some(order_being_filled.id), + Some(open_order.id), FailureReason::TimedOut, anyhow!("Order was not matched within {ORDER_OUTDATED_AFTER:?}"), )?;