apple_quant_algorithmic/order/dependency/
deferred.rs1use crate::{
2 backend::{OrderIdGenerator, OrdersBackend},
3 instrument::InstrumentSpec,
4 order::{ActiveOrderGoals, ActiveStateGoal},
5 order_manager::{OrderManager, OrdersCapacitySpec},
6 timestamp::TickTimestamp,
7 volume::DirectionalExposure,
8};
9
10use super::{OrderAction, OrderDependency, TriggerError};
11
12#[derive(Debug)]
13pub struct DeferredOrderActions<IS: InstrumentSpec>(Vec<OrderAction<IS>>);
14
15impl<IS: InstrumentSpec> DeferredOrderActions<IS> {
16 pub fn push(
17 &mut self,
18 order_action: OrderAction<IS>,
19 ) {
20 self.0.push(order_action);
21 }
22
23 pub(crate) async fn trigger<OB: OrdersBackend<IS>, CS: OrdersCapacitySpec>(
24 &mut self,
25 tick_timestamp: &TickTimestamp,
26 order_manager: &mut OrderManager<IS, CS>,
27 orders_backend: &mut OB,
28 order_id_generator: &mut OrderIdGenerator,
29 directional_exposure: &mut DirectionalExposure<IS>,
30 active_order_goals: &mut ActiveOrderGoals<IS>,
31 active_state_goal: &mut ActiveStateGoal,
32 ) -> Result<(), TriggerError>
33 where
34 IS: Send,
35 {
36 for order_action in self.0.drain(..) {
37 order_action
38 .trigger(
39 tick_timestamp,
40 order_manager,
41 orders_backend,
42 order_id_generator,
43 directional_exposure,
44 active_order_goals,
45 active_state_goal,
46 )
47 .await?;
48 }
49
50 Ok(())
51 }
52}
53
54impl<IS: InstrumentSpec> Default for DeferredOrderActions<IS> {
55 fn default() -> Self {
56 Self(Vec::default())
57 }
58}