Skip to content

Commit

Permalink
chore: Remove unused db functions
Browse files Browse the repository at this point in the history
  • Loading branch information
holzeis committed Jun 7, 2024
1 parent f0cae92 commit 37a7a73
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 70 deletions.
68 changes: 0 additions & 68 deletions coordinator/src/orderbook/db/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -233,29 +232,6 @@ pub fn all_limit_orders(conn: &mut PgConnection) -> QueryResult<Vec<OrderbookOrd
Ok(orders.into_iter().map(OrderbookOrder::from).collect())
}

/// Loads all orders by the given order direction and type
pub fn all_by_direction_and_type(
conn: &mut PgConnection,
direction: OrderbookDirection,
order_type: OrderBookOrderType,
filter_expired: bool,
) -> QueryResult<Vec<OrderbookOrder>> {
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<Order> = if filter_expired {
filters
.filter(orders::expiry.gt(OffsetDateTime::now_utc()))
.load::<Order>(conn)?
} else {
filters.load::<Order>(conn)?
};

Ok(orders.into_iter().map(OrderbookOrder::from).collect())
}

pub fn get_best_price(
conn: &mut PgConnection,
contract_symbol: commons::ContractSymbol,
Expand Down Expand Up @@ -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<OrderbookOrder> {
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<OrderbookOrder> {
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<OrderbookOrder> {
set_order_state(conn, id, commons::OrderState::Deleted)
Expand Down Expand Up @@ -451,22 +399,6 @@ pub fn update_quantity(
.execute(conn)
}

pub fn set_expired_limit_orders_to_expired(
conn: &mut PgConnection,
) -> QueryResult<Vec<OrderbookOrder>> {
let expired_limit_orders: Vec<Order> = 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<Option<OrderbookOrder>> {
let x = orders::table
Expand Down
3 changes: 1 addition & 2 deletions coordinator/src/orderbook/tests/sample_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 37a7a73

Please sign in to comment.