Skip to content

Commit

Permalink
Move model crate stubs into defaults (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
fhill2 authored Jan 23, 2025
1 parent 09293b8 commit bce92d8
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 107 deletions.
7 changes: 0 additions & 7 deletions nautilus_core/model/src/accounts/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,6 @@ impl From<AccountState> for AccountAny {
}
}

impl Default for AccountAny {
/// Creates a new default [`AccountAny`] instance.
fn default() -> Self {
AccountAny::Cash(CashAccount::default())
}
}

impl PartialEq for AccountAny {
fn eq(&self, other: &Self) -> bool {
self.id() == other.id()
Expand Down
28 changes: 1 addition & 27 deletions nautilus_core/model/src/accounts/cash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ use crate::{
accounts::base::{Account, BaseAccount},
enums::{AccountType, LiquiditySide, OrderSide},
events::{AccountState, OrderFilled},
identifiers::{
stubs::{account_id, uuid4},
AccountId,
},
identifiers::AccountId,
instruments::InstrumentAny,
position::Position,
types::{AccountBalance, Currency, Money, Price, Quantity},
Expand Down Expand Up @@ -249,29 +246,6 @@ impl Display for CashAccount {
}
}

impl Default for CashAccount {
/// Creates a new default [`CashAccount`] instance.
fn default() -> Self {
// million dollar account
let init_event = AccountState::new(
account_id(),
AccountType::Cash,
vec![AccountBalance::new(
Money::from("1000000 USD"),
Money::from("0 USD"),
Money::from("1000000 USD"),
)],
vec![],
true,
uuid4(),
0.into(),
0.into(),
Some(Currency::USD()),
);
Self::new(init_event, false)
}
}

////////////////////////////////////////////////////////////////////////////////
// Tests
////////////////////////////////////////////////////////////////////////////////
Expand Down
38 changes: 35 additions & 3 deletions nautilus_core/model/src/accounts/stubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,45 @@
use rstest::fixture;

use crate::{
accounts::{base::Account, cash::CashAccount, margin::MarginAccount},
enums::LiquiditySide,
accounts::{base::Account, cash::CashAccount, margin::MarginAccount, AccountAny},
enums::{AccountType, LiquiditySide},
events::account::{state::AccountState, stubs::*},
instruments::InstrumentAny,
types::{Currency, Money, Price, Quantity},
types::{AccountBalance, Currency, Money, Price, Quantity},
};

use crate::identifiers::stubs::{account_id, uuid4};

impl Default for CashAccount {
/// Creates a new default [`CashAccount`] instance.
fn default() -> Self {
// million dollar account
let init_event = AccountState::new(
account_id(),
AccountType::Cash,
vec![AccountBalance::new(
Money::from("1000000 USD"),
Money::from("0 USD"),
Money::from("1000000 USD"),
)],
vec![],
true,
uuid4(),
0.into(),
0.into(),
Some(Currency::USD()),
);
Self::new(init_event, false)
}
}

impl Default for AccountAny {
/// Creates a new default [`AccountAny`] instance.
fn default() -> Self {
AccountAny::Cash(CashAccount::default())
}
}

#[fixture]
pub fn margin_account(margin_account_state: AccountState) -> MarginAccount {
MarginAccount::new(margin_account_state, true)
Expand Down
73 changes: 73 additions & 0 deletions nautilus_core/model/src/identifiers/default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use crate::identifiers::{
AccountId, ClientId, ClientOrderId, PositionId, StrategyId, Symbol, TradeId, TraderId, Venue,
VenueOrderId,
};

impl Default for AccountId {
/// Creates a new default [`AccountId`] instance for testing.
fn default() -> Self {
Self::from("SIM-001")
}
}

impl Default for ClientId {
/// Creates a new default [`ClientId`] instance for testing.
fn default() -> Self {
Self::from("SIM")
}
}

impl Default for ClientOrderId {
/// Creates a new default [`ClientOrderId`] instance for testing.
fn default() -> Self {
Self::from("O-19700101-000000-001-001-1")
}
}

impl Default for PositionId {
/// Creates a new default [`PositionId`] instance for testing.
fn default() -> Self {
Self::from("P-001")
}
}

impl Default for StrategyId {
/// Creates a new default [`StrategyId`] instance for testing.
fn default() -> Self {
Self::from("S-001")
}
}

impl Default for TradeId {
/// Creates a new default [`TradeId`] instance for testing.
fn default() -> Self {
Self::from("1")
}
}

impl Default for TraderId {
/// Creates a new default [`TraderId`] instance for testing.
fn default() -> Self {
Self::from("TRADER-001")
}
}
impl Default for Symbol {
/// Creates a new default [`Symbol`] instance for testing.
fn default() -> Self {
Self::from("AUD/USD")
}
}

impl Default for Venue {
/// Creates a new default [`Venue`] instance for testing.
fn default() -> Self {
Self::from("SIM")
}
}

impl Default for VenueOrderId {
/// Creates a new default [`VenueOrderId`] instance for testing.
fn default() -> Self {
Self::from("001")
}
}
1 change: 1 addition & 0 deletions nautilus_core/model/src/identifiers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod account_id;
pub mod client_id;
pub mod client_order_id;
pub mod component_id;
pub mod default;
pub mod exec_algorithm_id;
pub mod instrument_id;
pub mod order_list_id;
Expand Down
70 changes: 0 additions & 70 deletions nautilus_core/model/src/identifiers/stubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,76 +23,6 @@ use crate::identifiers::{
PositionId, StrategyId, Symbol, TradeId, TraderId, Venue, VenueOrderId,
};

impl Default for AccountId {
/// Creates a new default [`AccountId`] instance for testing.
fn default() -> Self {
Self::from("SIM-001")
}
}

impl Default for ClientId {
/// Creates a new default [`ClientId`] instance for testing.
fn default() -> Self {
Self::from("SIM")
}
}

impl Default for ClientOrderId {
/// Creates a new default [`ClientOrderId`] instance for testing.
fn default() -> Self {
Self::from("O-19700101-000000-001-001-1")
}
}

impl Default for PositionId {
/// Creates a new default [`PositionId`] instance for testing.
fn default() -> Self {
Self::from("P-001")
}
}

impl Default for StrategyId {
/// Creates a new default [`StrategyId`] instance for testing.
fn default() -> Self {
Self::from("S-001")
}
}

impl Default for Symbol {
/// Creates a new default [`Symbol`] instance for testing.
fn default() -> Self {
Self::from("AUD/USD")
}
}

impl Default for TradeId {
/// Creates a new default [`TradeId`] instance for testing.
fn default() -> Self {
Self::from("1")
}
}

impl Default for TraderId {
/// Creates a new default [`TraderId`] instance for testing.
fn default() -> Self {
Self::from("TRADER-001")
}
}

impl Default for Venue {
/// Creates a new default [`Venue`] instance for testing.
fn default() -> Self {
Self::from("SIM")
}
}

impl Default for VenueOrderId {
/// Creates a new default [`VenueOrderId`] instance for testing.
fn default() -> Self {
Self::from("001")
}
}

// ---- AccountId ----

#[fixture]
Expand Down

0 comments on commit bce92d8

Please sign in to comment.