Skip to main content

apple_quant_algorithmic/order/state_update/
new_canceled.rs

1use crate::{
2	backend::{OrderIdGenerator, OrdersBackend, RemoteOrderId},
3	order::{DeferredOrderActions, StateGoal},
4	order_manager::{OrderManager, OrdersCapacitySpec},
5	instrument::InstrumentSpec, timestamp::TickTimestamp, volume::DirectionalExposure,
6};
7
8use super::{ApplyOrderStateUpdate, ApplyOrderStateUpdateError};
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11pub struct NewCanceledState {
12	pub remote_order_id: RemoteOrderId,
13}
14
15impl<IS: InstrumentSpec> ApplyOrderStateUpdate<IS> for NewCanceledState {
16	async fn apply<
17		OB: OrdersBackend<IS>,
18		CS: OrdersCapacitySpec,
19	>(
20		&self,
21		tick_timestamp: &TickTimestamp,
22		order_manager: &mut OrderManager<IS, CS>,
23		orders_backend: &mut OB,
24		order_id_generator: &mut OrderIdGenerator,
25		directional_exposure: &mut DirectionalExposure<IS>,
26		deferred_order_actions: &mut DeferredOrderActions<IS>,
27		state_goal: &mut StateGoal,
28	) -> Result<(), ApplyOrderStateUpdateError>
29	where
30		IS: Send,
31	{
32		let Self {
33			remote_order_id,
34		} = self;
35
36		let working_remote_order = order_manager.working_remote_orders.remove(
37			directional_exposure,
38			remote_order_id,
39		)?;
40
41		order_manager.completed_remote_orders.submit::<OB>(
42			tick_timestamp,
43			working_remote_order,
44		);
45
46		Ok(())
47	}
48}