apple-quant-algorithmic 0.4.0

Apple Quant's algorithmic library.
Documentation
use crate::{
	backend::{LocalOrderId, OrderIdGenerator, OrdersBackend, RemoteOrderId},
	order::{DeferredOrderActions, StateGoal},
	order_manager::{OrderManager, OrdersCapacitySpec},
	timestamp::{TickTimestamp, Timestamp},
	instrument::InstrumentSpec, volume::DirectionalExposure,
};

use super::{ApplyOrderStateUpdate, ApplyOrderStateUpdateError};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NewWorkingState {
	pub local_order_id: LocalOrderId,
	pub remote_order_id: RemoteOrderId,
	pub booking_timestamp: Timestamp,
}

impl<IS: InstrumentSpec> ApplyOrderStateUpdate<IS> for NewWorkingState {
	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 {
			local_order_id,
			remote_order_id,
			booking_timestamp,
		} = self;

		order_manager.pending_remote_orders.acknowledged::<OB>(
			tick_timestamp,
			&mut order_manager.working_remote_orders,
			directional_exposure,
			deferred_order_actions,
			local_order_id,
			*remote_order_id,
		).await?;

		order_manager.working_remote_orders.processed::<OB>(&remote_order_id)?;

		Ok(())
	}
}