Skip to main content

apple_quant_algorithmic/volume/
directional_exposure.rs

1use crate::instrument::InstrumentSpec;
2
3use super::ZeroableDirectionalIntentVolume;
4
5#[derive(Debug)]
6pub struct DirectionalExposure<IS: InstrumentSpec> {
7	/// Directional intent volume that is effecting the current exposed position. Fully matched orders fully effect this and are negated from [`armed_directional_intent_volume`], while partially matched order partially effect both effective and armed. Only client acknowledged matched volume is part of this, all other volume contributes to armed. It is guaranteed that the combination of effective and armed directional intent volume equals the combination of all non-canceled/non-rejected submitted orders. Orders will be fully matched before the client is made aware of the events.
8	effective: ZeroableDirectionalIntentVolume<IS>,
9
10	/// Directional intent volume that has the potential to transition to altering the current exposed position. Resting limit, client stop, and all unbooked and unmatched orders contribute to this. Immediately executable orders do effect this until they are fully matched. Partially matched orders partially effect this. Orders will be fully matched before the client is made aware of the events.
11	armed: ZeroableDirectionalIntentVolume<IS>,
12}
13
14impl<IS: InstrumentSpec> DirectionalExposure<IS> {
15	pub fn effective(&self) -> &ZeroableDirectionalIntentVolume<IS> {
16		&self.effective
17	}
18
19	pub fn armed(&self) -> &ZeroableDirectionalIntentVolume<IS> {
20		&self.armed
21	}
22
23	pub fn combined(&self) -> ZeroableDirectionalIntentVolume<IS> {
24		self.effective + self.armed
25	}
26
27	pub(crate) fn change_armed_directional_exposure(
28		&mut self,
29		delta_directional_exposure: &ZeroableDirectionalIntentVolume<IS>,
30	) {
31		self.armed += *delta_directional_exposure;
32	}
33
34	pub(crate) fn change_effective_directional_exposure(
35		&mut self,
36		delta_directional_exposure: &ZeroableDirectionalIntentVolume<IS>,
37	) {
38		self.effective += *delta_directional_exposure;
39	}
40}
41
42impl<IS: InstrumentSpec> Default for DirectionalExposure<IS> {
43	fn default() -> Self {
44		Self {
45			armed: ZeroableDirectionalIntentVolume::ZERO,
46			effective: ZeroableDirectionalIntentVolume::ZERO,
47		}
48	}
49}