apple_quant_algorithmic/volume/
directional_intent.rs1use rust_decimal::Decimal;
2
3use crate::instrument::InstrumentSpec;
4
5use super::{AggressorSide, DirectionalIntentVolume, DirectionlessVolume, RestingSide};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[repr(u8)]
9pub enum DirectionalIntent {
10 Positive,
11 Negative,
12}
13
14impl DirectionalIntent {
15 pub fn with_volume<IS: InstrumentSpec>(
16 self,
17 directionless_volume: DirectionlessVolume<IS>,
18 ) -> DirectionalIntentVolume<IS> {
19 DirectionalIntentVolume {
20 directional_intent: self,
21 directionless_volume,
22 }
23 }
24
25 pub fn flip(
26 &mut self,
27 ) {
28 *self = self.as_flipped();
29 }
30
31 pub fn as_flipped(
32 &self,
33 ) -> Self {
34 match self {
35 Self::Positive => Self::Negative,
36 Self::Negative => Self::Positive,
37 }
38 }
39
40 pub fn is_positive(
41 &self,
42 ) -> bool {
43 *self == Self::Positive
44 }
45
46 pub fn as_decimal(
47 &self,
48 ) -> Decimal {
49 match self {
50 Self::Negative => Decimal::NEGATIVE_ONE,
51 Self::Positive => Decimal::ONE,
52 }
53 }
54}
55
56impl From<AggressorSide> for DirectionalIntent {
57 fn from(
58 value: AggressorSide,
59 ) -> Self {
60 match value {
61 AggressorSide::Bid => Self::Negative,
62 AggressorSide::Ask => Self::Positive,
63 }
64 }
65}
66
67impl From<&AggressorSide> for DirectionalIntent {
68 fn from(
69 value: &AggressorSide,
70 ) -> Self {
71 (*value).into()
72 }
73}
74
75impl From<RestingSide> for DirectionalIntent {
76 fn from(
77 value: RestingSide,
78 ) -> Self {
79 match value {
80 RestingSide::Bid => Self::Positive,
81 RestingSide::Ask => Self::Negative,
82 }
83 }
84}
85
86impl From<&RestingSide> for DirectionalIntent {
87 fn from(
88 value: &RestingSide,
89 ) -> Self {
90 (*value).into()
91 }
92}