1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* Copyright 2023 Architect Financial Technologies LLC. This is free
 * software released under the GNU Affero Public License version 3. */

//! Types used by various queries to the OMS.

use crate::{
    packed_value, pool,
    protocol::{
        limits::Limit,
        orderflow::{AberrantFill, FillId, Halt, NormalFill, Order, OrderId, OrderState},
    },
};
use enumflags2::BitFlags;
use netidx::{chars::Chars, pool::Pooled};
use netidx_derive::Pack;
use std::{ops::Deref, result, sync::Arc};

pool!(pub, pool_oids_fids, Vec<(OrderId, FillId)>, 1_000, 1_000);
pool!(pub, pool_fids, Vec<FillId>, 1_000, 1_000);
pool!(pub, pool_fills, Vec<result::Result<NormalFill, AberrantFill>>, 1_000, 1_000);
pool!(pub, pool_orders, Vec<Order>, 1_000, 1_000);
pool!(pub, pool_order_state, Vec<BitFlags<OrderState>>, 1_000, 10_000);
pool!(pub, pool_oids, Vec<OrderId>, 1_000, 10_000);

#[derive(Debug, Clone, PartialEq, Eq, Pack)]
#[pack(unwrapped)]
pub struct OrderIds(pub Arc<Pooled<Vec<OrderId>>>);

packed_value!(OrderIds);

impl Deref for OrderIds {
    type Target = Pooled<Vec<OrderId>>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Pack)]
#[pack(unwrapped)]
pub struct FillIds(pub Arc<Pooled<Vec<FillId>>>);

packed_value!(FillIds);

impl Deref for FillIds {
    type Target = Pooled<Vec<FillId>>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Pack)]
#[pack(unwrapped)]
pub struct OidsAndFillids(pub Arc<Pooled<Vec<(OrderId, FillId)>>>);

packed_value!(OidsAndFillids);

impl Deref for OidsAndFillids {
    type Target = Pooled<Vec<(OrderId, FillId)>>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Pack)]
#[pack(unwrapped)]
pub struct OrderStates(pub Arc<Pooled<Vec<BitFlags<OrderState>>>>);

packed_value!(OrderStates);

impl Deref for OrderStates {
    type Target = Pooled<Vec<BitFlags<OrderState>>>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Pack)]
#[pack(unwrapped)]
pub struct RejectReasons(pub Arc<Pooled<Vec<Option<Chars>>>>);

packed_value!(RejectReasons);

impl Deref for RejectReasons {
    type Target = Pooled<Vec<Option<Chars>>>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Pack)]
#[pack(unwrapped)]
pub struct Orders(pub Arc<Pooled<Vec<Order>>>);

packed_value!(Orders);

impl Deref for Orders {
    type Target = Pooled<Vec<Order>>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Pack)]
#[pack(unwrapped)]
pub struct Fills(pub Arc<Pooled<Vec<result::Result<NormalFill, AberrantFill>>>>);

packed_value!(Fills);

impl Deref for Fills {
    type Target = Pooled<Vec<result::Result<NormalFill, AberrantFill>>>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Pack)]
#[pack(unwrapped)]
pub struct Limits(pub Arc<Pooled<Vec<Limit>>>);

packed_value!(Limits);

impl Deref for Limits {
    type Target = Pooled<Vec<Limit>>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Pack)]
#[pack(unwrapped)]
pub struct Halts(pub Arc<Pooled<Vec<Halt>>>);

packed_value!(Halts);

impl Deref for Halts {
    type Target = Pooled<Vec<Halt>>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}