use crate::{
backend::{OrderIdGenerator, OrdersBackend, RemoteOrderId},
order::{DeferredOrderActions, StateGoal},
order_manager::{OrderManager, OrdersCapacitySpec},
instrument::InstrumentSpec, timestamp::TickTimestamp, volume::DirectionalExposure,
};
use super::{ApplyOrderStateUpdate, ApplyOrderStateUpdateError};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NewCanceledState {
pub remote_order_id: RemoteOrderId,
}
impl<IS: InstrumentSpec> ApplyOrderStateUpdate<IS> for NewCanceledState {
async fn apply<
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>,
deferred_order_actions: &mut DeferredOrderActions<IS>,
state_goal: &mut StateGoal,
) -> Result<(), ApplyOrderStateUpdateError>
where
IS: Send,
{
let Self {
remote_order_id,
} = self;
let working_remote_order = order_manager.working_remote_orders.remove(
directional_exposure,
remote_order_id,
)?;
order_manager.completed_remote_orders.submit::<OB>(
tick_timestamp,
working_remote_order,
);
Ok(())
}
}