apple-quant-algorithmic 0.1.0

Apple Quant's algorithmic trading api
Documentation
use crate::{
	backend::{OrderIdGenerator, OrdersBackend},
	instrument::InstrumentSpec,
	order::{
		ActiveOrderGoals, ActiveStateGoal, ClientOrder, ClientOrderTracker, OrderDependency,
		TriggerError,
	},
	order_manager::{OrderManager, OrdersCapacitySpec},
	price::BidAskPriceSpread,
	timestamp::TickTimestamp,
	volume::DirectionalExposure,
};

use super::ClientDeployedRemoteDependency;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SubmitClientOrder<IS: InstrumentSpec> {
	pub client_order_tracker: ClientOrderTracker,
	pub client_order: ClientOrder<IS>,
	pub client_deployed_remote_dependency: ClientDeployedRemoteDependency<IS>,
}

impl<IS: InstrumentSpec> SubmitClientOrder<IS> {
	pub(crate) fn parent_processed(
		&mut self,
		bid_ask_price_spread: &BidAskPriceSpread<IS>,
	) {
		self.client_order
			.parent_processed(bid_ask_price_spread);
	}
}

impl<IS: InstrumentSpec> OrderDependency<IS> for SubmitClientOrder<IS> {
	async fn trigger<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>,
		active_order_goals: &mut ActiveOrderGoals<IS>,
		active_state_goal: &mut ActiveStateGoal,
	) -> Result<(), TriggerError>
	where
		IS: Send,
	{
		let Self {
			client_order_tracker,
			client_order,
			client_deployed_remote_dependency,
		} = self;

		order_manager
			.pending_client_orders
			.submit::<OB>(
				tick_timestamp,
				directional_exposure,
				client_order_tracker,
				client_order.clone(),
				client_deployed_remote_dependency.clone(),
			)?;

		Ok(())
	}
}