Skip to content

Port limit order filling for OrderMatchingEngine in Rust #2212

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

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

filipmacek
Copy link
Member

Pull Request

  • porting limit order flow in OrderMatchingEngine

@filipmacek filipmacek added the rust Relating to the Rust core label Jan 14, 2025
@filipmacek filipmacek requested a review from cjdsellers January 14, 2025 16:14
@filipmacek filipmacek self-assigned this Jan 14, 2025
@filipmacek filipmacek force-pushed the order-matching-engine-process-limit-order branch from 3152655 to b01a469 Compare January 14, 2025 17:05
@filipmacek filipmacek force-pushed the order-matching-engine-process-limit-order branch from b01a469 to 05b0ffb Compare January 15, 2025 15:46
self.core.bid = self.target_bid;
self.core.ask = self.target_ask;
self.core.last = self.target_last;
if let Some(target_bid) = self.target_bid {
Copy link
Member Author

@filipmacek filipmacek Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cython version has self._has_targets variable, and Rust doesn't. But best to use native Option and check if the value is defined to achieve the same effect

} else if order.time_in_force() == TimeInForce::Fok
|| order.time_in_force() == TimeInForce::Ioc
{
self.cancel_order(order, None);
Copy link
Member Author

@filipmacek filipmacek Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that after self.accept_order is called, the corresponding AcceptOrder event is not applied anywhere, and it should be in generate_order_accepted function. Basically we are doing a lot of processing on order object and we expect the status was changed, we we never call order.apply anywhere in OrderMatchingEngine code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.accept_order(order) will call the ExecutionEngine immediately which will apply the event along with other logic.

@@ -1242,6 +1458,8 @@ impl OrderMatchingEngine {
));
let msgbus = self.msgbus.as_ref().borrow();
msgbus.send(&msgbus.switchboard.exec_engine_process, &event as &dyn Any);

order.apply(event).expect("Failed to apply order event");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event will be applied to the order in the ExecutionEngine following the completion of msgbus.send(&msgbus.switchboard.exec_engine_process, &event as &dyn Any).

} else if order.time_in_force() == TimeInForce::Fok
|| order.time_in_force() == TimeInForce::Ioc
{
self.cancel_order(order, None);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.accept_order(order) will call the ExecutionEngine immediately which will apply the event along with other logic.

@@ -1242,6 +1458,8 @@ impl OrderMatchingEngine {
));
let msgbus = self.msgbus.as_ref().borrow();
msgbus.send(&msgbus.switchboard.exec_engine_process, &event as &dyn Any);

order.apply(event).expect("Failed to apply order event");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event will be applied to the order in the ExecutionEngine following the completion of msgbus.send(&msgbus.switchboard.exec_engine_process, &event as &dyn Any).

@cjdsellers cjdsellers marked this pull request as ready for review January 15, 2025 23:03
@cjdsellers cjdsellers merged commit 4d29540 into develop Jan 15, 2025
12 checks passed
@cjdsellers cjdsellers deleted the order-matching-engine-process-limit-order branch January 15, 2025 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Relating to the Rust core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants