Skip to content

Commit

Permalink
chore: remove unneeded ordertype
Browse files Browse the repository at this point in the history
  • Loading branch information
bonomat committed Mar 25, 2024
1 parent b1b4072 commit 7410d39
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 51 deletions.
2 changes: 0 additions & 2 deletions coordinator/src/node/expired_positions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use commons::MatchState;
use commons::NewOrder;
use commons::OrderReason;
use commons::OrderState;
use commons::OrderType;
use rust_decimal::prelude::FromPrimitive;
use rust_decimal::prelude::ToPrimitive;
use rust_decimal::Decimal;
Expand Down Expand Up @@ -86,7 +85,6 @@ pub async fn close(node: Node, trading_sender: mpsc::Sender<NewOrderMessage>) ->
trader_id: position.trader,
direction: position.trader_direction.opposite(),
leverage: Decimal::from_f32(position.trader_leverage).expect("to fit into decimal"),
order_type: OrderType::Market,
// This order can basically not expire, but if the user does not come back online within
// a certain time period we can assume the channel to be abandoned and we should force
// close.
Expand Down
4 changes: 2 additions & 2 deletions coordinator/src/orderbook/db/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl From<LimitOrder> for NewOrder {
.round_dp(2)
.to_f32()
.expect("To be able to convert decimal to f32"),
order_type: value.order_type.into(),
order_type: OrderType::Limit,
expiry: value.expiry,
order_reason: OrderReason::Manual,
contract_symbol: value.contract_symbol.into(),
Expand All @@ -202,7 +202,7 @@ impl From<MarketOrder> for NewOrder {
.round_dp(2)
.to_f32()
.expect("To be able to convert decimal to f32"),
order_type: value.order_type.into(),
order_type: OrderType::Market,
expiry: value.expiry,
order_reason: OrderReason::Manual,
contract_symbol: value.contract_symbol.into(),
Expand Down
62 changes: 27 additions & 35 deletions coordinator/src/orderbook/tests/sample_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::orderbook::tests::setup_db;
use crate::orderbook::tests::start_postgres;
use bitcoin::secp256k1::PublicKey;
use commons::LimitOrder;
use commons::MarketOrder;
use commons::OrderReason;
use commons::OrderState;
use commons::OrderType;
use rust_decimal_macros::dec;
use std::str::FromStr;
use testcontainers::clients::Cli;
Expand All @@ -26,10 +26,7 @@ async fn crud_test() {

let order = orders::insert_limit_order(
&mut conn,
dummy_order(
OffsetDateTime::now_utc() + Duration::minutes(1),
OrderType::Market,
),
dummy_limit_order(OffsetDateTime::now_utc() + Duration::minutes(1)),
OrderReason::Manual,
)
.unwrap();
Expand All @@ -50,42 +47,38 @@ async fn test_all_limit_orders() {
let orders = orders::all_limit_orders(&mut conn).unwrap();
assert!(orders.is_empty());

orders::insert_limit_order(
&mut conn,
dummy_order(
OffsetDateTime::now_utc() + Duration::minutes(1),
OrderType::Market,
),
OrderReason::Manual,
)
.unwrap();
let order_1 = dummy_limit_order(OffsetDateTime::now_utc() + Duration::minutes(1));
orders::insert_limit_order(&mut conn, order_1, OrderReason::Manual).unwrap();

let second_order = orders::insert_limit_order(
&mut conn,
dummy_order(
OffsetDateTime::now_utc() + Duration::minutes(1),
OrderType::Limit,
),
OrderReason::Manual,
)
.unwrap();
orders::set_order_state(&mut conn, second_order.id, OrderState::Failed).unwrap();
let order_2 = dummy_market_order(OffsetDateTime::now_utc() + Duration::minutes(1));
orders::insert_market_order(&mut conn, order_2, OrderReason::Manual).unwrap();

orders::insert_limit_order(
&mut conn,
dummy_order(
OffsetDateTime::now_utc() + Duration::minutes(1),
OrderType::Limit,
),
OrderReason::Manual,
)
.unwrap();
let order_3 = dummy_limit_order(OffsetDateTime::now_utc() + Duration::minutes(1));
let second_limit_order =
orders::insert_limit_order(&mut conn, order_3, OrderReason::Manual).unwrap();
orders::set_order_state(&mut conn, second_limit_order.id, OrderState::Failed).unwrap();

let orders = orders::all_limit_orders(&mut conn).unwrap();
assert_eq!(orders.len(), 1);
}

fn dummy_order(expiry: OffsetDateTime, order_type: OrderType) -> LimitOrder {
fn dummy_market_order(expiry: OffsetDateTime) -> MarketOrder {
MarketOrder {
id: Uuid::new_v4(),
trader_id: PublicKey::from_str(
"027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007",
)
.unwrap(),
direction: Direction::Long,
quantity: dec!(100.0),
expiry,
contract_symbol: trade::ContractSymbol::BtcUsd,
leverage: dec!(1.0),
stable: false,
}
}

fn dummy_limit_order(expiry: OffsetDateTime) -> LimitOrder {
LimitOrder {
id: Uuid::new_v4(),
price: dec!(20000.00),
Expand All @@ -95,7 +88,6 @@ fn dummy_order(expiry: OffsetDateTime, order_type: OrderType) -> LimitOrder {
.unwrap(),
direction: Direction::Long,
quantity: dec!(100.0),
order_type,
expiry,
contract_symbol: trade::ContractSymbol::BtcUsd,
leverage: dec!(1.0),
Expand Down
11 changes: 0 additions & 11 deletions crates/commons/src/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ pub struct MarketOrder {
pub direction: Direction,
#[serde(with = "rust_decimal::serde::float")]
pub leverage: Decimal,
pub order_type: OrderType,
#[serde(with = "time::serde::timestamp")]
pub expiry: OffsetDateTime,
pub stable: bool,
Expand All @@ -111,7 +110,6 @@ pub struct LimitOrder {
pub direction: Direction,
#[serde(with = "rust_decimal::serde::float")]
pub leverage: Decimal,
pub order_type: OrderType,
#[serde(with = "time::serde::timestamp")]
pub expiry: OffsetDateTime,
pub stable: bool,
Expand All @@ -126,8 +124,6 @@ impl LimitOrder {

let symbol = self.contract_symbol.label();
let symbol = symbol.as_bytes();
let order_type = self.order_type.label();
let order_type = order_type.as_bytes();
let direction = self.direction.to_string();
let direction = direction.as_bytes();
let quantity = format!("{:.2}", self.quantity);
Expand All @@ -140,7 +136,6 @@ impl LimitOrder {
vec.append(&mut id);
vec.append(&mut seconds);
vec.append(&mut symbol.to_vec());
vec.append(&mut order_type.to_vec());
vec.append(&mut direction.to_vec());
vec.append(&mut quantity.to_vec());
vec.append(&mut price.to_vec());
Expand All @@ -159,8 +154,6 @@ impl MarketOrder {

let symbol = self.contract_symbol.label();
let symbol = symbol.as_bytes();
let order_type = self.order_type.label();
let order_type = order_type.as_bytes();
let direction = self.direction.to_string();
let direction = direction.as_bytes();
let quantity = format!("{:.2}", self.quantity);
Expand All @@ -171,7 +164,6 @@ impl MarketOrder {
vec.append(&mut id);
vec.append(&mut seconds);
vec.append(&mut symbol.to_vec());
vec.append(&mut order_type.to_vec());
vec.append(&mut direction.to_vec());
vec.append(&mut quantity.to_vec());
vec.append(&mut leverage.to_vec());
Expand Down Expand Up @@ -251,7 +243,6 @@ pub mod tests {
use crate::LimitOrder;
use crate::NewOrder;
use crate::NewOrderRequest;
use crate::OrderType;
use secp256k1::rand;
use secp256k1::Secp256k1;
use secp256k1::SecretKey;
Expand All @@ -276,7 +267,6 @@ pub mod tests {
trader_id: public_key,
direction: Direction::Long,
leverage: rust_decimal_macros::dec!(2.0),
order_type: OrderType::Market,
expiry: OffsetDateTime::now_utc(),
stable: false,
};
Expand All @@ -303,7 +293,6 @@ pub mod tests {
trader_id: public_key,
direction: Direction::Long,
leverage: rust_decimal_macros::dec!(2.0),
order_type: OrderType::Market,
// Note: the last 5 is too much as it does not get serialized
expiry: OffsetDateTime::UNIX_EPOCH + 1.1010101015.seconds(),
stable: false,
Expand Down
1 change: 0 additions & 1 deletion mobile/native/src/trade/order/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ impl From<Order> for commons::MarketOrder {
trader_id,
direction: order.direction,
leverage: Decimal::from_f32(order.leverage).expect("to fit into f32"),
order_type: order.order_type.into(),
expiry: order.order_expiry_timestamp,
stable: order.stable,
}
Expand Down

0 comments on commit 7410d39

Please sign in to comment.