From f8e9991b8eb96fa956b9fc765a5422fd18b0bbf6 Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Mon, 3 Jun 2024 15:36:51 +0200 Subject: [PATCH] chore: Remove unused db functions --- coordinator/src/orderbook/db/orders.rs | 68 ------------------- .../src/orderbook/tests/sample_test.rs | 3 +- 2 files changed, 1 insertion(+), 70 deletions(-) diff --git a/coordinator/src/orderbook/db/orders.rs b/coordinator/src/orderbook/db/orders.rs index 0c2f7e124..d95367c3a 100644 --- a/coordinator/src/orderbook/db/orders.rs +++ b/coordinator/src/orderbook/db/orders.rs @@ -19,7 +19,6 @@ use time::OffsetDateTime; use uuid::Uuid; use xxi_node::commons; use xxi_node::commons::BestPrice; -use xxi_node::commons::Direction as OrderbookDirection; use xxi_node::commons::NewLimitOrder; use xxi_node::commons::NewMarketOrder; use xxi_node::commons::Order as OrderbookOrder; @@ -233,29 +232,6 @@ pub fn all_limit_orders(conn: &mut PgConnection) -> QueryResult QueryResult> { - let filters = orders::table - .filter(orders::direction.eq(Direction::from(direction))) - .filter(orders::order_type.eq(OrderType::from(order_type))) - .filter(orders::order_state.eq(OrderState::Open)); - - let orders: Vec = if filter_expired { - filters - .filter(orders::expiry.gt(OffsetDateTime::now_utc())) - .load::(conn)? - } else { - filters.load::(conn)? - }; - - Ok(orders.into_iter().map(OrderbookOrder::from).collect()) -} - pub fn get_best_price( conn: &mut PgConnection, contract_symbol: commons::ContractSymbol, @@ -377,34 +353,6 @@ pub fn insert_market_order( Ok(OrderbookOrder::from(order)) } -/// Returns the number of affected rows: 1. -pub fn set_is_taken( - conn: &mut PgConnection, - id: Uuid, - is_taken: bool, -) -> QueryResult { - if is_taken { - set_order_state(conn, id, commons::OrderState::Taken) - } else { - set_order_state(conn, id, commons::OrderState::Open) - } -} - -/// Mark an order as [`OrderState::Deleted`], if it belongs to the given `trader_id`. -pub fn delete_trader_order( - conn: &mut PgConnection, - id: Uuid, - trader_pubkey: PublicKey, -) -> QueryResult { - let order: Order = diesel::update(orders::table) - .filter(orders::order_id.eq(id)) - .filter(orders::trader_pubkey.eq(trader_pubkey.to_string())) - .set(orders::order_state.eq(OrderState::Deleted)) - .get_result(conn)?; - - Ok(OrderbookOrder::from(order)) -} - /// Mark an order as [`OrderState::Deleted`]. pub fn delete(conn: &mut PgConnection, id: Uuid) -> QueryResult { set_order_state(conn, id, commons::OrderState::Deleted) @@ -440,22 +388,6 @@ pub fn set_order_state( Ok(OrderbookOrder::from(order)) } -pub fn set_expired_limit_orders_to_expired( - conn: &mut PgConnection, -) -> QueryResult> { - let expired_limit_orders: Vec = 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::Expired)) - .get_results(conn)?; - - Ok(expired_limit_orders - .into_iter() - .map(OrderbookOrder::from) - .collect()) -} - /// Returns the order by id pub fn get_with_id(conn: &mut PgConnection, uid: Uuid) -> QueryResult> { let x = orders::table diff --git a/coordinator/src/orderbook/tests/sample_test.rs b/coordinator/src/orderbook/tests/sample_test.rs index b111f531c..b0e9a10ab 100644 --- a/coordinator/src/orderbook/tests/sample_test.rs +++ b/coordinator/src/orderbook/tests/sample_test.rs @@ -32,8 +32,7 @@ async fn crud_test() { ) .unwrap(); - let order = orders::set_is_taken(&mut conn, order.id, true).unwrap(); - assert_eq!(order.order_state, OrderState::Taken); + assert_eq!(order.order_state, OrderState::Open); } #[tokio::test]