Skip to main content

apple_quant_algorithmic/price/
proto.rs

1use crate::instrument::InstrumentSpec;
2
3use super::{AbsolutePrice, RelativePrice};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum ProtoabsolutePrice<IS: InstrumentSpec> {
7	Absolute(AbsolutePrice<IS>),
8	Relative(RelativePrice),
9}
10
11impl<IS: InstrumentSpec> ProtoabsolutePrice<IS> {
12	pub fn as_absolute(
13		&self,
14	) -> Option<&AbsolutePrice<IS>> {
15		self.into()
16	}
17
18	pub fn into_absolute(
19		self,
20	) -> Option<AbsolutePrice<IS>> {
21		self.into()
22	}
23
24	pub fn as_relative(
25		&self,
26	) -> Option<&RelativePrice> {
27		self.into()
28	}
29
30	pub fn into_relative(
31		self,
32	) -> Option<RelativePrice> {
33		self.into()
34	}
35}
36
37impl<IS: InstrumentSpec> From<AbsolutePrice<IS>> for ProtoabsolutePrice<IS> {
38	fn from(
39		value: AbsolutePrice<IS>,
40	) -> Self {
41		Self::Absolute(value)
42	}
43}
44
45impl<IS: InstrumentSpec> From<&AbsolutePrice<IS>> for ProtoabsolutePrice<IS> {
46	fn from(
47		value: &AbsolutePrice<IS>,
48	) -> Self {
49		(*value).into()
50	}
51}
52
53impl<IS: InstrumentSpec> From<RelativePrice> for ProtoabsolutePrice<IS> {
54	fn from(
55		value: RelativePrice,
56	) -> Self {
57		Self::Relative(value)
58	}
59}
60
61impl<IS: InstrumentSpec> From<&RelativePrice> for ProtoabsolutePrice<IS> {
62	fn from(
63		value: &RelativePrice,
64	) -> Self {
65		(*value).into()
66	}
67}