apple-quant-algorithmic 0.1.0

Apple Quant's algorithmic trading api
Documentation
use crate::{
	backend::{OrderIdGenerator, OrdersBackend, RemoteOrderId},
	instrument::InstrumentSpec,
	order::{ActiveOrderGoals, ActiveStateGoal, DeferredOrderActions, PartialOrderFill},
	order_manager::{OrderManager, OrdersCapacitySpec},
	timestamp::TickTimestamp,
	volume::DirectionalExposure,
};

use super::{ApplyOrderStateUpdate, ApplyOrderStateUpdateError};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NewPartialFillState<IS: InstrumentSpec> {
	pub remote_order_id: RemoteOrderId,
	pub partial_order_fill: PartialOrderFill<IS>,
}

impl<IS: InstrumentSpec> ApplyOrderStateUpdate<IS> for NewPartialFillState<IS> {
	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>,
		active_order_goals: &mut ActiveOrderGoals<IS>,
		active_state_goal: &mut ActiveStateGoal,
	) -> Result<(), ApplyOrderStateUpdateError>
	where
		IS: Send,
	{
		let Self {
			remote_order_id,
			partial_order_fill,
		} = self;

		order_manager
			.working_remote_orders
			.partial_fill::<OB>(
				tick_timestamp,
				&mut order_manager.completed_remote_orders,
				deferred_order_actions,
				directional_exposure,
				partial_order_fill,
				&remote_order_id,
			)?;

		Ok(())
	}
}