-
Notifications
You must be signed in to change notification settings - Fork 489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port RiskEngine to Rust #2035
Port RiskEngine to Rust #2035
Conversation
Signed-off-by: Pushkar Mishra <[email protected]>
CodSpeed Performance ReportMerging #2035 will not alter performanceComparing Summary
|
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking solid! I've addressed the closure issue.
} | ||
|
||
impl<T, F> Debug for Throttler<T, F> | ||
impl<T, S, D> Debug for Throttler<T, S, D> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need different parameters for Send and Drop when they are the same traits Fn(T)
? Have you considered removing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, I was registering two different functions with the same parameters, which was causing an error. The compiler requires both functions to be identical, so I made this change. However, since we're now using closures as callbacks, this is no longer needed, so I have removed it.
@@ -33,6 +33,7 @@ pub use self::{ | |||
}; | |||
|
|||
#[derive(Clone, Debug, Display)] | |||
#[allow(clippy::large_enum_variant)] // TODO: why? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is a problem that will have to be fixed throughout the system. We'll tackle this once significant control flow is in Rust.
clock: Rc<RefCell<dyn Clock>>, | ||
cache: Rc<RefCell<Cache>>, | ||
msgbus: Rc<RefCell<MessageBus>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rc RefCell is equivalent to a Python pointer - a shared reference that is garbage collected. Common state between components will be shared this way.
nautilus_core/risk/src/engine/mod.rs
Outdated
Box::new(move |order: SubmitOrder| { | ||
msgbus1 | ||
.borrow_mut() | ||
.send(&Ustr::from("ExecEngine.execute"), &order); | ||
}) as Box<dyn Fn(SubmitOrder)>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trick here is that the closure does not need the whole RiskEngine i.e. &self
state. It only needs a reference to the message bus since its own job is to send a message. By cloning and moving the message bus into the closure we can avoid the inner outer pattern.
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work here!
Pull Request
calculate_fixed_risk_position_size
to Rust.TODOs:
Type of change
How has this change been tested?
make cargo-test