fixer_fix/fix40/
allocation_ack.rs1#![allow(clippy::new_without_default)]
3#![allow(clippy::needless_pass_by_value)]
4#![allow(clippy::too_many_arguments)]
5#![allow(unused_imports)]
6
7use fixer::message::Message;
8use fixer::fix_string::FIXString;
9use fixer::errors::MessageRejectErrorEnum;
10use fixer::session::session_id::SessionID;
11
12
13use jiff::Timestamp;
14
15use crate::field;
16use crate::tag;
17
18pub struct AllocationACK {
20 pub message: Message,
21}
22
23impl AllocationACK {
24 pub fn new(alloc_id: field::AllocIDField, trade_date: field::TradeDateField, alloc_status: field::AllocStatusField) -> Self {
26 let mut msg = Message::new();
27 msg.header.set_field(tag::MSG_TYPE, FIXString::from("P".to_string()));
28
29 msg.body.set_field(tag::ALLOC_ID, alloc_id.0);
30
31 msg.body.set_field(tag::TRADE_DATE, trade_date.0);
32
33 msg.body.set_field(tag::ALLOC_STATUS, alloc_status.0);
34
35 Self { message: msg }
36 }
37
38 pub fn from_message(msg: Message) -> Self {
40 Self { message: msg }
41 }
42
43 pub fn to_message(self) -> Message {
45 self.message
46 }
47
48
49
50
51 pub fn set_alloc_id(&mut self, v: String) {
53 self.message.body.set_field(tag::ALLOC_ID, FIXString::from(v));
54 }
55
56 pub fn get_alloc_id(&self) -> Result<String, MessageRejectErrorEnum> {
58 let mut fld = field::AllocIDField::new(String::new());
59 self.message.body.get_field(tag::ALLOC_ID, &mut fld.0)?;
60 Ok(fld.value().to_string())
61 }
62
63
64 pub fn has_alloc_id(&self) -> bool {
66 self.message.body.has(tag::ALLOC_ID)
67 }
68
69
70
71
72 pub fn set_alloc_rej_code(&mut self, v: isize) {
74 self.message.body.set_field(tag::ALLOC_REJ_CODE, fixer::fix_int::FIXInt::from(v));
75 }
76
77 pub fn get_alloc_rej_code(&self) -> Result<isize, MessageRejectErrorEnum> {
79 let mut fld = field::AllocRejCodeField::new(0);
80 self.message.body.get_field(tag::ALLOC_REJ_CODE, &mut fld.0)?;
81 Ok(fld.value())
82 }
83
84
85 pub fn has_alloc_rej_code(&self) -> bool {
87 self.message.body.has(tag::ALLOC_REJ_CODE)
88 }
89
90
91
92
93 pub fn set_alloc_status(&mut self, v: isize) {
95 self.message.body.set_field(tag::ALLOC_STATUS, fixer::fix_int::FIXInt::from(v));
96 }
97
98 pub fn get_alloc_status(&self) -> Result<isize, MessageRejectErrorEnum> {
100 let mut fld = field::AllocStatusField::new(0);
101 self.message.body.get_field(tag::ALLOC_STATUS, &mut fld.0)?;
102 Ok(fld.value())
103 }
104
105
106 pub fn has_alloc_status(&self) -> bool {
108 self.message.body.has(tag::ALLOC_STATUS)
109 }
110
111
112
113
114 pub fn set_client_id(&mut self, v: String) {
116 self.message.body.set_field(tag::CLIENT_ID, FIXString::from(v));
117 }
118
119 pub fn get_client_id(&self) -> Result<String, MessageRejectErrorEnum> {
121 let mut fld = field::ClientIDField::new(String::new());
122 self.message.body.get_field(tag::CLIENT_ID, &mut fld.0)?;
123 Ok(fld.value().to_string())
124 }
125
126
127 pub fn has_client_id(&self) -> bool {
129 self.message.body.has(tag::CLIENT_ID)
130 }
131
132
133
134
135 pub fn set_exec_broker(&mut self, v: String) {
137 self.message.body.set_field(tag::EXEC_BROKER, FIXString::from(v));
138 }
139
140 pub fn get_exec_broker(&self) -> Result<String, MessageRejectErrorEnum> {
142 let mut fld = field::ExecBrokerField::new(String::new());
143 self.message.body.get_field(tag::EXEC_BROKER, &mut fld.0)?;
144 Ok(fld.value().to_string())
145 }
146
147
148 pub fn has_exec_broker(&self) -> bool {
150 self.message.body.has(tag::EXEC_BROKER)
151 }
152
153
154
155
156 pub fn set_text(&mut self, v: String) {
158 self.message.body.set_field(tag::TEXT, FIXString::from(v));
159 }
160
161 pub fn get_text(&self) -> Result<String, MessageRejectErrorEnum> {
163 let mut fld = field::TextField::new(String::new());
164 self.message.body.get_field(tag::TEXT, &mut fld.0)?;
165 Ok(fld.value().to_string())
166 }
167
168
169 pub fn has_text(&self) -> bool {
171 self.message.body.has(tag::TEXT)
172 }
173
174
175
176
177 pub fn set_trade_date(&mut self, v: String) {
179 self.message.body.set_field(tag::TRADE_DATE, FIXString::from(v));
180 }
181
182 pub fn get_trade_date(&self) -> Result<String, MessageRejectErrorEnum> {
184 let mut fld = field::TradeDateField::new(String::new());
185 self.message.body.get_field(tag::TRADE_DATE, &mut fld.0)?;
186 Ok(fld.value().to_string())
187 }
188
189
190 pub fn has_trade_date(&self) -> bool {
192 self.message.body.has(tag::TRADE_DATE)
193 }
194
195
196
197
198 pub fn set_transact_time(&mut self, v: Timestamp) {
200 self.message.body.set_field(tag::TRANSACT_TIME, fixer::fix_utc_timestamp::FIXUTCTimestamp {
201 time: v,
202 precision: fixer::fix_utc_timestamp::TimestampPrecision::Millis,
203 });
204 }
205
206 pub fn get_transact_time(&self) -> Result<Timestamp, MessageRejectErrorEnum> {
208 let mut fld = field::TransactTimeField::new(Timestamp::UNIX_EPOCH);
209 self.message.body.get_field(tag::TRANSACT_TIME, &mut fld.0)?;
210 Ok(fld.value())
211 }
212
213
214 pub fn has_transact_time(&self) -> bool {
216 self.message.body.has(tag::TRANSACT_TIME)
217 }
218
219
220}
221
222pub type RouteOut = fn(msg: AllocationACK, session_id: SessionID) -> Result<(), MessageRejectErrorEnum>;
224
225pub type Route = (&'static str, &'static str, Box<dyn Fn(&Message, SessionID) -> Result<(), MessageRejectErrorEnum> + Send>);
227
228pub fn route(router: RouteOut) -> Route {
230 let r = move |msg: &Message, session_id: SessionID| -> Result<(), MessageRejectErrorEnum> {
231 router(AllocationACK::from_message(msg.clone()), session_id)
232 };
233 ("FIX.4.0", "P", Box::new(r))
234}