Skip to content

Commit 3a8b560

Browse files
authored
Continue Risk Engine in Rust (#2210)
1 parent bee3511 commit 3a8b560

File tree

5 files changed

+1402
-450
lines changed

5 files changed

+1402
-450
lines changed

nautilus_core/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nautilus_core/execution/src/emulator.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,9 @@ impl OrderEmulator {
419419
// todo: fix unwrap
420420
self.check_monitoring(command.strategy_id, command.position_id.unwrap());
421421

422-
for order in command.order_list.orders {
422+
for order in &command.order_list.orders {
423423
if let Some(parent_order_id) = order.parent_order_id() {
424424
let cache = self.cache.borrow();
425-
// check this error handling style: todo
426425
let parent_order = cache.order(&parent_order_id).ok_or_else(|| {
427426
anyhow::anyhow!("Parent order for {} not found", order.client_order_id())
428427
})?;

nautilus_core/model/src/accounts/any.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use serde::{Deserialize, Serialize};
1919

2020
use crate::{
2121
accounts::{base::Account, cash::CashAccount, margin::MarginAccount},
22-
enums::AccountType,
22+
enums::{AccountType, LiquiditySide},
2323
events::{AccountState, OrderFilled},
2424
identifiers::AccountId,
2525
instruments::InstrumentAny,
2626
position::Position,
27-
types::{AccountBalance, Currency, Money},
27+
types::{AccountBalance, Currency, Money, Price, Quantity},
2828
};
2929
#[derive(Debug, Clone, Serialize, Deserialize)]
3030
pub enum AccountAny {
@@ -107,6 +107,32 @@ impl AccountAny {
107107
AccountAny::Cash(cash) => cash.calculate_pnls(instrument, fill, position),
108108
}
109109
}
110+
111+
pub fn calculate_commission(
112+
&self,
113+
instrument: InstrumentAny,
114+
last_qty: Quantity,
115+
last_px: Price,
116+
liquidity_side: LiquiditySide,
117+
use_quote_for_inverse: Option<bool>,
118+
) -> anyhow::Result<Money> {
119+
match self {
120+
AccountAny::Margin(margin) => margin.calculate_commission(
121+
instrument,
122+
last_qty,
123+
last_px,
124+
liquidity_side,
125+
use_quote_for_inverse,
126+
),
127+
AccountAny::Cash(cash) => cash.calculate_commission(
128+
instrument,
129+
last_qty,
130+
last_px,
131+
liquidity_side,
132+
use_quote_for_inverse,
133+
),
134+
}
135+
}
110136
}
111137

112138
impl From<AccountState> for AccountAny {

nautilus_core/risk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ nautilus-common = { path = "../common" }
1515
nautilus-core = { path = "../core" }
1616
nautilus-execution = { path = "../execution" }
1717
nautilus-model = { path = "../model", features = ["stubs"] }
18+
nautilus-portfolio = { path = "../portfolio" }
1819
anyhow = { workspace = true }
1920
log = { workspace = true }
2021
pyo3 = { workspace = true, optional = true }

0 commit comments

Comments
 (0)