use crate::{
backend::{LocalOrderId, OrderIdGenerator, OrdersBackend},
instrument::InstrumentSpec,
order::{ActiveOrderGoals, ActiveStateGoal, OrderDependency, TriggerError},
order_manager::{OrderManager, OrdersCapacitySpec},
timestamp::TickTimestamp,
volume::DirectionalExposure,
};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CancelRemoteOrder {
pub local_order_id: LocalOrderId,
pub attempt_exposure_revertion: bool,
}
impl CancelRemoteOrder {
pub fn new(
local_order_id: LocalOrderId,
attempt_exposure_revertion: bool,
) -> Self {
Self {
local_order_id,
attempt_exposure_revertion,
}
}
}
impl<IS: InstrumentSpec> OrderDependency<IS> for CancelRemoteOrder {
async fn trigger<OB: OrdersBackend<IS>, CS: OrdersCapacitySpec>(
&self,
tick_timestamp: &TickTimestamp,
order_manager: &mut OrderManager<IS, CS>,
orders_backend: &mut OB,
order_id_generator: &mut OrderIdGenerator,
directional_exposure: &mut DirectionalExposure<IS>,
active_order_goals: &mut ActiveOrderGoals<IS>,
active_state_goal: &mut ActiveStateGoal,
) -> Result<(), TriggerError>
where
IS: Send,
{
let working_remote_order = order_manager
.working_remote_orders
.get_with_local(&self.local_order_id)?;
orders_backend
.initiate_cancel_order(&working_remote_order.remote_order_id)
.await?;
Ok(())
}
}