Skip to content

Commit bce92d8

Browse files
authored
Move model crate stubs into defaults (#2235)
1 parent 09293b8 commit bce92d8

File tree

6 files changed

+110
-107
lines changed

6 files changed

+110
-107
lines changed

nautilus_core/model/src/accounts/any.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,6 @@ impl From<AccountState> for AccountAny {
145145
}
146146
}
147147

148-
impl Default for AccountAny {
149-
/// Creates a new default [`AccountAny`] instance.
150-
fn default() -> Self {
151-
AccountAny::Cash(CashAccount::default())
152-
}
153-
}
154-
155148
impl PartialEq for AccountAny {
156149
fn eq(&self, other: &Self) -> bool {
157150
self.id() == other.id()

nautilus_core/model/src/accounts/cash.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ use crate::{
2626
accounts::base::{Account, BaseAccount},
2727
enums::{AccountType, LiquiditySide, OrderSide},
2828
events::{AccountState, OrderFilled},
29-
identifiers::{
30-
stubs::{account_id, uuid4},
31-
AccountId,
32-
},
29+
identifiers::AccountId,
3330
instruments::InstrumentAny,
3431
position::Position,
3532
types::{AccountBalance, Currency, Money, Price, Quantity},
@@ -249,29 +246,6 @@ impl Display for CashAccount {
249246
}
250247
}
251248

252-
impl Default for CashAccount {
253-
/// Creates a new default [`CashAccount`] instance.
254-
fn default() -> Self {
255-
// million dollar account
256-
let init_event = AccountState::new(
257-
account_id(),
258-
AccountType::Cash,
259-
vec![AccountBalance::new(
260-
Money::from("1000000 USD"),
261-
Money::from("0 USD"),
262-
Money::from("1000000 USD"),
263-
)],
264-
vec![],
265-
true,
266-
uuid4(),
267-
0.into(),
268-
0.into(),
269-
Some(Currency::USD()),
270-
);
271-
Self::new(init_event, false)
272-
}
273-
}
274-
275249
////////////////////////////////////////////////////////////////////////////////
276250
// Tests
277251
////////////////////////////////////////////////////////////////////////////////

nautilus_core/model/src/accounts/stubs.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,45 @@
1616
use rstest::fixture;
1717

1818
use crate::{
19-
accounts::{base::Account, cash::CashAccount, margin::MarginAccount},
20-
enums::LiquiditySide,
19+
accounts::{base::Account, cash::CashAccount, margin::MarginAccount, AccountAny},
20+
enums::{AccountType, LiquiditySide},
2121
events::account::{state::AccountState, stubs::*},
2222
instruments::InstrumentAny,
23-
types::{Currency, Money, Price, Quantity},
23+
types::{AccountBalance, Currency, Money, Price, Quantity},
2424
};
2525

26+
use crate::identifiers::stubs::{account_id, uuid4};
27+
28+
impl Default for CashAccount {
29+
/// Creates a new default [`CashAccount`] instance.
30+
fn default() -> Self {
31+
// million dollar account
32+
let init_event = AccountState::new(
33+
account_id(),
34+
AccountType::Cash,
35+
vec![AccountBalance::new(
36+
Money::from("1000000 USD"),
37+
Money::from("0 USD"),
38+
Money::from("1000000 USD"),
39+
)],
40+
vec![],
41+
true,
42+
uuid4(),
43+
0.into(),
44+
0.into(),
45+
Some(Currency::USD()),
46+
);
47+
Self::new(init_event, false)
48+
}
49+
}
50+
51+
impl Default for AccountAny {
52+
/// Creates a new default [`AccountAny`] instance.
53+
fn default() -> Self {
54+
AccountAny::Cash(CashAccount::default())
55+
}
56+
}
57+
2658
#[fixture]
2759
pub fn margin_account(margin_account_state: AccountState) -> MarginAccount {
2860
MarginAccount::new(margin_account_state, true)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use crate::identifiers::{
2+
AccountId, ClientId, ClientOrderId, PositionId, StrategyId, Symbol, TradeId, TraderId, Venue,
3+
VenueOrderId,
4+
};
5+
6+
impl Default for AccountId {
7+
/// Creates a new default [`AccountId`] instance for testing.
8+
fn default() -> Self {
9+
Self::from("SIM-001")
10+
}
11+
}
12+
13+
impl Default for ClientId {
14+
/// Creates a new default [`ClientId`] instance for testing.
15+
fn default() -> Self {
16+
Self::from("SIM")
17+
}
18+
}
19+
20+
impl Default for ClientOrderId {
21+
/// Creates a new default [`ClientOrderId`] instance for testing.
22+
fn default() -> Self {
23+
Self::from("O-19700101-000000-001-001-1")
24+
}
25+
}
26+
27+
impl Default for PositionId {
28+
/// Creates a new default [`PositionId`] instance for testing.
29+
fn default() -> Self {
30+
Self::from("P-001")
31+
}
32+
}
33+
34+
impl Default for StrategyId {
35+
/// Creates a new default [`StrategyId`] instance for testing.
36+
fn default() -> Self {
37+
Self::from("S-001")
38+
}
39+
}
40+
41+
impl Default for TradeId {
42+
/// Creates a new default [`TradeId`] instance for testing.
43+
fn default() -> Self {
44+
Self::from("1")
45+
}
46+
}
47+
48+
impl Default for TraderId {
49+
/// Creates a new default [`TraderId`] instance for testing.
50+
fn default() -> Self {
51+
Self::from("TRADER-001")
52+
}
53+
}
54+
impl Default for Symbol {
55+
/// Creates a new default [`Symbol`] instance for testing.
56+
fn default() -> Self {
57+
Self::from("AUD/USD")
58+
}
59+
}
60+
61+
impl Default for Venue {
62+
/// Creates a new default [`Venue`] instance for testing.
63+
fn default() -> Self {
64+
Self::from("SIM")
65+
}
66+
}
67+
68+
impl Default for VenueOrderId {
69+
/// Creates a new default [`VenueOrderId`] instance for testing.
70+
fn default() -> Self {
71+
Self::from("001")
72+
}
73+
}

nautilus_core/model/src/identifiers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod account_id;
2424
pub mod client_id;
2525
pub mod client_order_id;
2626
pub mod component_id;
27+
pub mod default;
2728
pub mod exec_algorithm_id;
2829
pub mod instrument_id;
2930
pub mod order_list_id;

nautilus_core/model/src/identifiers/stubs.rs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -23,76 +23,6 @@ use crate::identifiers::{
2323
PositionId, StrategyId, Symbol, TradeId, TraderId, Venue, VenueOrderId,
2424
};
2525

26-
impl Default for AccountId {
27-
/// Creates a new default [`AccountId`] instance for testing.
28-
fn default() -> Self {
29-
Self::from("SIM-001")
30-
}
31-
}
32-
33-
impl Default for ClientId {
34-
/// Creates a new default [`ClientId`] instance for testing.
35-
fn default() -> Self {
36-
Self::from("SIM")
37-
}
38-
}
39-
40-
impl Default for ClientOrderId {
41-
/// Creates a new default [`ClientOrderId`] instance for testing.
42-
fn default() -> Self {
43-
Self::from("O-19700101-000000-001-001-1")
44-
}
45-
}
46-
47-
impl Default for PositionId {
48-
/// Creates a new default [`PositionId`] instance for testing.
49-
fn default() -> Self {
50-
Self::from("P-001")
51-
}
52-
}
53-
54-
impl Default for StrategyId {
55-
/// Creates a new default [`StrategyId`] instance for testing.
56-
fn default() -> Self {
57-
Self::from("S-001")
58-
}
59-
}
60-
61-
impl Default for Symbol {
62-
/// Creates a new default [`Symbol`] instance for testing.
63-
fn default() -> Self {
64-
Self::from("AUD/USD")
65-
}
66-
}
67-
68-
impl Default for TradeId {
69-
/// Creates a new default [`TradeId`] instance for testing.
70-
fn default() -> Self {
71-
Self::from("1")
72-
}
73-
}
74-
75-
impl Default for TraderId {
76-
/// Creates a new default [`TraderId`] instance for testing.
77-
fn default() -> Self {
78-
Self::from("TRADER-001")
79-
}
80-
}
81-
82-
impl Default for Venue {
83-
/// Creates a new default [`Venue`] instance for testing.
84-
fn default() -> Self {
85-
Self::from("SIM")
86-
}
87-
}
88-
89-
impl Default for VenueOrderId {
90-
/// Creates a new default [`VenueOrderId`] instance for testing.
91-
fn default() -> Self {
92-
Self::from("001")
93-
}
94-
}
95-
9626
// ---- AccountId ----
9727

9828
#[fixture]

0 commit comments

Comments
 (0)