Skip to main content

acta_maker_sdk/types/
ids.rs

1use std::fmt::Display;
2
3use derive_more::{Display as DeriveDisplay, From, Into};
4use serde::{Deserialize, Serialize};
5
6define_bytes32_newtype!(OrderId);
7
8define_numeric_newtype!(Strike, u64);
9define_numeric_newtype!(Price, u64);
10define_numeric_newtype!(Quantity, u64);
11define_numeric_newtype!(Nonce, u64);
12define_numeric_newtype!(RfqVersion, u64);
13define_numeric_newtype!(OrderVersion, u64);
14define_numeric_newtype!(Slot, u64);
15define_numeric_newtype!(ChainId, u64);
16define_numeric_newtype!(DurationSeconds, u64);
17define_numeric_newtype!(Volume, u64);
18define_numeric_newtype!(Balance, u64);
19
20define_numeric_newtype!(QuoteCount, u32);
21define_numeric_newtype!(TradeCount, u32);
22define_numeric_newtype!(TimeoutSeconds, u32);
23
24#[derive(
25    Debug,
26    Default,
27    Clone,
28    Copy,
29    PartialEq,
30    Eq,
31    PartialOrd,
32    Ord,
33    Hash,
34    Serialize,
35    Deserialize,
36    From,
37    Into,
38)]
39pub struct Decimals(pub u8);
40
41impl Decimals {
42    #[must_use]
43    pub const fn new(value: u8) -> Self {
44        Self(value)
45    }
46
47    #[must_use]
48    pub const fn value(self) -> u8 {
49        self.0
50    }
51}
52
53impl Display for Decimals {
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        write!(f, "{}", self.0)
56    }
57}
58
59define_string_newtype!(MarketId);
60define_string_newtype!(UserId);
61
62#[derive(
63    Debug,
64    Clone,
65    Copy,
66    PartialEq,
67    Eq,
68    Hash,
69    Serialize,
70    Deserialize,
71    strum::IntoStaticStr,
72    strum::EnumString,
73)]
74#[serde(rename_all = "snake_case")]
75#[strum(serialize_all = "snake_case")]
76#[repr(u8)]
77pub enum PositionType {
78    CoveredCall = 0,
79    CashSecuredPut = 1,
80}
81
82impl From<PositionType> for u8 {
83    fn from(position_type: PositionType) -> Self {
84        position_type as Self
85    }
86}
87
88#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
89#[error("invalid position type value: {0}")]
90pub struct PositionTypeParseError(pub u8);
91
92impl TryFrom<u8> for PositionType {
93    type Error = PositionTypeParseError;
94
95    fn try_from(value: u8) -> Result<Self, Self::Error> {
96        match value {
97            0 => Ok(Self::CoveredCall),
98            1 => Ok(Self::CashSecuredPut),
99            _ => Err(PositionTypeParseError(value)),
100        }
101    }
102}
103
104impl Display for PositionType {
105    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
106        f.write_str(self.into())
107    }
108}