Skip to content

Commit

Permalink
chore: update rust doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bonomat committed Dec 16, 2023
1 parent c7013f9 commit f2a273b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mobile/native/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub fn get_filled_orders() -> Result<Vec<trade::order::Order>> {
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<Vec<trade::order::Order>> {
let mut db = connection()?;
let orders = Order::get_by_state(OrderState::Open, &mut db)?;
Expand Down
10 changes: 6 additions & 4 deletions mobile/native/src/trade/order/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ fn get_order_being_filled() -> Result<Order> {
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:#}");
Expand All @@ -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:?}"),
)?;
Expand Down

0 comments on commit f2a273b

Please sign in to comment.