apple_quant_algorithmic/order/dependency/remote/
cancel.rs1use crate::{
2 backend::{LocalOrderId, OrderIdGenerator, OrdersBackend},
3 instrument::InstrumentSpec,
4 order::{ActiveOrderGoals, ActiveStateGoal, OrderDependency, TriggerError},
5 order_manager::{OrderManager, OrdersCapacitySpec},
6 timestamp::TickTimestamp,
7 volume::DirectionalExposure,
8};
9
10#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11pub struct CancelRemoteOrder {
12 pub local_order_id: LocalOrderId,
13 pub attempt_exposure_revertion: bool,
14}
15
16impl CancelRemoteOrder {
17 pub fn new(
18 local_order_id: LocalOrderId,
19 attempt_exposure_revertion: bool,
20 ) -> Self {
21 Self {
22 local_order_id,
23 attempt_exposure_revertion,
24 }
25 }
26}
27
28impl<IS: InstrumentSpec> OrderDependency<IS> for CancelRemoteOrder {
29 async fn trigger<OB: OrdersBackend<IS>, CS: OrdersCapacitySpec>(
30 &self,
31 tick_timestamp: &TickTimestamp,
32 order_manager: &mut OrderManager<IS, CS>,
33 orders_backend: &mut OB,
34 order_id_generator: &mut OrderIdGenerator,
35 directional_exposure: &mut DirectionalExposure<IS>,
36 active_order_goals: &mut ActiveOrderGoals<IS>,
37 active_state_goal: &mut ActiveStateGoal,
38 ) -> Result<(), TriggerError>
39 where
40 IS: Send,
41 {
42 let working_remote_order = order_manager
43 .working_remote_orders
44 .get_with_local(&self.local_order_id)?;
45
46 orders_backend
47 .initiate_cancel_order(&working_remote_order.remote_order_id)
48 .await?;
49
50 Ok(())
51 }
52}