Skip to main content

apple_quant_algorithmic/points/
whole.rs

1use crate::{
2	instrument::{InstrumentSpec, XSpec},
3	volume::DirectionlessVolume,
4};
5
6use super::{Subpoints, SubpointsType};
7
8#[cfg(feature = "points-i32")]
9pub type WholePointsType = i32;
10
11#[cfg(not(feature = "points-i32"))]
12pub type WholePointsType = i64;
13
14pub trait VolumeFromWholePoints: From<Subpoints> {
15	fn volume_from_whole_points(
16		whole_points: WholePoints,
17	) -> Self
18	where
19		Self: Sized,
20	{
21		let subpoints_type = *whole_points.whole_points_type() as SubpointsType;
22		Self::from(subpoints_type.into())
23	}
24}
25
26pub trait PriceFromWholePoints<XS: XSpec>: From<Subpoints> {
27	fn price_from_whole_points(
28		whole_points: WholePoints,
29	) -> Self
30	where
31		Self: Sized,
32	{
33		let mut subpoints_type = *whole_points.whole_points_type() as SubpointsType;
34		subpoints_type *= XS::TICKS_PER_POINT as SubpointsType;
35		Self::from(subpoints_type.into())
36	}
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
40pub struct WholePoints(WholePointsType);
41
42impl WholePoints {
43	pub(crate) unsafe fn from_whole_points_type(
44		whole_points_type: WholePointsType,
45	) -> Self {
46		Self(whole_points_type)
47	}
48
49	pub fn whole_points_type(
50		&self,
51	) -> &WholePointsType {
52		&self.0
53	}
54
55	pub fn into_subpoints<XS: XSpec>(
56		self,
57	) -> Subpoints {
58		Subpoints::from_whole_points::<XS>(self)
59	}
60
61	pub fn as_directionless_volume<IS: InstrumentSpec>(
62		&self,
63	) -> DirectionlessVolume<IS> {
64		self.into()
65	}
66
67	pub fn into_directionless_volume<IS: InstrumentSpec>(
68		self,
69	) -> DirectionlessVolume<IS> {
70		self.into()
71	}
72}