1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
1516use std::{any::Any, cell::RefCell, rc::Rc};
1718use nautilus_common::msgbus::handler::MessageHandler;
19use nautilus_model::events::OrderEventAny;
20use ustr::Ustr;
2122use crate::{messages::TradingCommand, order_emulator::emulator::OrderEmulator};
2324pub struct OrderEmulatorExecuteHandler {
25pub id: Ustr,
26pub emulator: Rc<RefCell<OrderEmulator>>,
27}
2829impl MessageHandler for OrderEmulatorExecuteHandler {
30fn id(&self) -> Ustr {
31self.id
32 }
3334fn handle(&self, msg: &dyn Any) {
35self.emulator.borrow_mut().execute(
36 msg.downcast_ref::<&TradingCommand>()
37 .unwrap()
38 .to_owned()
39 .clone(),
40 );
41 }
4243fn as_any(&self) -> &dyn Any {
44self
45}
46}
4748pub struct OrderEmulatorOnEventHandler {
49pub id: Ustr,
50pub emulator: Rc<RefCell<OrderEmulator>>,
51}
5253impl MessageHandler for OrderEmulatorOnEventHandler {
54fn id(&self) -> Ustr {
55self.id
56 }
5758fn handle(&self, msg: &dyn Any) {
59self.emulator.borrow_mut().on_event(
60 msg.downcast_ref::<&OrderEventAny>()
61 .unwrap()
62 .to_owned()
63 .clone(),
64 );
65 }
6667fn as_any(&self) -> &dyn Any {
68self
69}
70}