Skip to content

Commit

Permalink
chore: rename new order types
Browse files Browse the repository at this point in the history
this will allow us to differentiate between newOrders and Orders
  • Loading branch information
bonomat committed Mar 26, 2024
1 parent 2561dab commit 92364c6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions coordinator/src/node/expired_positions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use anyhow::anyhow;
use anyhow::Context;
use anyhow::Result;
use commons::average_execution_price;
use commons::MarketOrder;
use commons::Match;
use commons::MatchState;
use commons::NewMarketOrder;
use commons::OrderReason;
use commons::OrderState;
use rust_decimal::prelude::FromPrimitive;
Expand Down Expand Up @@ -79,7 +79,7 @@ pub async fn close(node: Node, trading_sender: mpsc::Sender<NewOrderMessage>) ->

tracing::debug!(trader_pk=%position.trader, %position.expiry_timestamp, "Attempting to close expired position");

let new_order = MarketOrder {
let new_order = NewMarketOrder {
id: uuid::Uuid::new_v4(),
contract_symbol: position.contract_symbol,
quantity: Decimal::try_from(position.quantity).expect("to fit into decimal"),
Expand Down
16 changes: 8 additions & 8 deletions coordinator/src/orderbook/db/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::orderbook::db::custom_types::OrderType;
use crate::schema::matches;
use crate::schema::orders;
use bitcoin::secp256k1::PublicKey;
use commons::LimitOrder;
use commons::MarketOrder;
use commons::NewLimitOrder;
use commons::NewMarketOrder;
use commons::Order as OrderbookOrder;
use commons::OrderReason as OrderBookOrderReason;
use commons::OrderState as OrderBookOrderState;
Expand Down Expand Up @@ -160,8 +160,8 @@ struct NewOrder {
pub stable: bool,
}

impl From<LimitOrder> for NewOrder {
fn from(value: LimitOrder) -> Self {
impl From<NewLimitOrder> for NewOrder {
fn from(value: NewLimitOrder) -> Self {
NewOrder {
trader_order_id: value.id,
price: value
Expand Down Expand Up @@ -189,8 +189,8 @@ impl From<LimitOrder> for NewOrder {
}
}

impl From<MarketOrder> for NewOrder {
fn from(value: MarketOrder) -> Self {
impl From<NewMarketOrder> for NewOrder {
fn from(value: NewMarketOrder) -> Self {
NewOrder {
trader_order_id: value.id,
// TODO: it would be cool to get rid of this as well
Expand Down Expand Up @@ -271,7 +271,7 @@ pub fn get_all_orders(
/// Returns the number of affected rows: 1.
pub fn insert_limit_order(
conn: &mut PgConnection,
order: LimitOrder,
order: NewLimitOrder,
order_reason: OrderBookOrderReason,
) -> QueryResult<OrderbookOrder> {
let new_order = NewOrder {
Expand All @@ -288,7 +288,7 @@ pub fn insert_limit_order(
/// Returns the number of affected rows: 1.
pub fn insert_market_order(
conn: &mut PgConnection,
order: MarketOrder,
order: NewMarketOrder,
order_reason: OrderBookOrderReason,
) -> QueryResult<OrderbookOrder> {
let new_order = NewOrder {
Expand Down
12 changes: 6 additions & 6 deletions coordinator/src/orderbook/tests/sample_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::orderbook::db::orders;
use crate::orderbook::tests::setup_db;
use crate::orderbook::tests::start_postgres;
use bitcoin::secp256k1::PublicKey;
use commons::LimitOrder;
use commons::MarketOrder;
use commons::NewLimitOrder;
use commons::NewMarketOrder;
use commons::OrderReason;
use commons::OrderState;
use rust_decimal_macros::dec;
Expand Down Expand Up @@ -62,8 +62,8 @@ async fn test_all_limit_orders() {
assert_eq!(orders.len(), 1);
}

fn dummy_market_order(expiry: OffsetDateTime) -> MarketOrder {
MarketOrder {
fn dummy_market_order(expiry: OffsetDateTime) -> NewMarketOrder {
NewMarketOrder {
id: Uuid::new_v4(),
trader_id: PublicKey::from_str(
"027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007",
Expand All @@ -78,8 +78,8 @@ fn dummy_market_order(expiry: OffsetDateTime) -> MarketOrder {
}
}

fn dummy_limit_order(expiry: OffsetDateTime) -> LimitOrder {
LimitOrder {
fn dummy_limit_order(expiry: OffsetDateTime) -> NewLimitOrder {
NewLimitOrder {
id: Uuid::new_v4(),
price: dec!(20000.00),
trader_id: PublicKey::from_str(
Expand Down
18 changes: 9 additions & 9 deletions crates/commons/src/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ impl NewOrderRequest {

#[derive(Serialize, Deserialize, Clone)]
pub enum NewOrder {
Market(MarketOrder),
Limit(LimitOrder),
Market(NewMarketOrder),
Limit(NewLimitOrder),
}

impl NewOrder {
Expand Down Expand Up @@ -83,7 +83,7 @@ impl NewOrder {
}

#[derive(Serialize, Deserialize, Clone)]
pub struct MarketOrder {
pub struct NewMarketOrder {
pub id: Uuid,
pub contract_symbol: ContractSymbol,
#[serde(with = "rust_decimal::serde::float")]
Expand All @@ -98,7 +98,7 @@ pub struct MarketOrder {
}

#[derive(Serialize, Deserialize, Clone)]
pub struct LimitOrder {
pub struct NewLimitOrder {
pub id: Uuid,
pub contract_symbol: ContractSymbol,
#[serde(with = "rust_decimal::serde::float")]
Expand All @@ -114,7 +114,7 @@ pub struct LimitOrder {
pub stable: bool,
}

impl LimitOrder {
impl NewLimitOrder {
pub fn message(&self) -> Message {
let mut vec: Vec<u8> = vec![];
let mut id = self.id.as_bytes().to_vec();
Expand Down Expand Up @@ -144,7 +144,7 @@ impl LimitOrder {
}
}

impl MarketOrder {
impl NewMarketOrder {
pub fn message(&self) -> Message {
let mut vec: Vec<u8> = vec![];
let mut id = self.id.as_bytes().to_vec();
Expand Down Expand Up @@ -239,7 +239,7 @@ pub struct ChannelOpeningParams {

#[cfg(test)]
pub mod tests {
use crate::LimitOrder;
use crate::NewLimitOrder;
use crate::NewOrder;
use crate::NewOrderRequest;
use secp256k1::rand;
Expand All @@ -258,7 +258,7 @@ pub mod tests {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let public_key = secret_key.public_key(SECP256K1);

let order = LimitOrder {
let order = NewLimitOrder {
id: Default::default(),
contract_symbol: ContractSymbol::BtcUsd,
price: rust_decimal_macros::dec!(53_000),
Expand All @@ -284,7 +284,7 @@ pub mod tests {
.unwrap();
let public_key = secret_key.public_key(SECP256K1);

let original_order = LimitOrder {
let original_order = NewLimitOrder {
id: Uuid::from_str("67e5504410b1426f9247bb680e5fe0c8").unwrap(),
contract_symbol: ContractSymbol::BtcUsd,
price: rust_decimal_macros::dec!(53_000),
Expand Down
4 changes: 2 additions & 2 deletions crates/dev-maker/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::logger::init_tracing;
use crate::orderbook_client::OrderbookClient;
use anyhow::Result;
use commons::LimitOrder;
use commons::NewLimitOrder;
use commons::NewOrder;
use reqwest::Url;
use rust_decimal::Decimal;
Expand Down Expand Up @@ -99,7 +99,7 @@ async fn post_order(
let uuid = Uuid::new_v4();
if let Err(err) = client
.post_new_order(
NewOrder::Limit(LimitOrder {
NewOrder::Limit(NewLimitOrder {
id: uuid,
contract_symbol: ContractSymbol::BtcUsd,
price,
Expand Down
4 changes: 2 additions & 2 deletions mobile/native/src/trade/order/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ impl Order {
}
}

impl From<Order> for commons::MarketOrder {
impl From<Order> for commons::NewMarketOrder {
fn from(order: Order) -> Self {
let quantity = Decimal::try_from(order.quantity).expect("to parse into decimal");
let trader_id = ln_dlc::get_node_pubkey();
commons::MarketOrder {
commons::NewMarketOrder {
id: order.id,
contract_symbol: order.contract_symbol,
quantity,
Expand Down
4 changes: 2 additions & 2 deletions mobile/native/src/trade/order/orderbook_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::ln_dlc::get_node_key;
use anyhow::bail;
use anyhow::Result;
use commons::ChannelOpeningParams;
use commons::MarketOrder;
use commons::NewMarketOrder;
use commons::NewOrder;
use commons::NewOrderRequest;
use reqwest::Url;
Expand All @@ -19,7 +19,7 @@ impl OrderbookClient {

pub(crate) async fn post_new_market_order(
&self,
order: MarketOrder,
order: NewMarketOrder,
channel_opening_params: Option<ChannelOpeningParams>,
) -> Result<()> {
let secret_key = get_node_key();
Expand Down

0 comments on commit 92364c6

Please sign in to comment.