fixer_fix/fix43/
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_encoded_text(&mut self, v: String) {
116 self.message.body.set_field(tag::ENCODED_TEXT, FIXString::from(v));
117 }
118
119 pub fn get_encoded_text(&self) -> Result<String, MessageRejectErrorEnum> {
121 let mut fld = field::EncodedTextField::new(String::new());
122 self.message.body.get_field(tag::ENCODED_TEXT, &mut fld.0)?;
123 Ok(fld.value().to_string())
124 }
125
126
127 pub fn has_encoded_text(&self) -> bool {
129 self.message.body.has(tag::ENCODED_TEXT)
130 }
131
132
133
134
135 pub fn set_encoded_text_len(&mut self, v: isize) {
137 self.message.body.set_field(tag::ENCODED_TEXT_LEN, fixer::fix_int::FIXInt::from(v));
138 }
139
140 pub fn get_encoded_text_len(&self) -> Result<isize, MessageRejectErrorEnum> {
142 let mut fld = field::EncodedTextLenField::new(0);
143 self.message.body.get_field(tag::ENCODED_TEXT_LEN, &mut fld.0)?;
144 Ok(fld.value())
145 }
146
147
148 pub fn has_encoded_text_len(&self) -> bool {
150 self.message.body.has(tag::ENCODED_TEXT_LEN)
151 }
152
153
154
155
156 pub fn set_legal_confirm(&mut self, v: bool) {
158 self.message.body.set_field(tag::LEGAL_CONFIRM, fixer::fix_boolean::FIXBoolean::from(v));
159 }
160
161 pub fn get_legal_confirm(&self) -> Result<bool, MessageRejectErrorEnum> {
163 let mut fld = field::LegalConfirmField::new(false);
164 self.message.body.get_field(tag::LEGAL_CONFIRM, &mut fld.0)?;
165 Ok(fld.value())
166 }
167
168
169 pub fn has_legal_confirm(&self) -> bool {
171 self.message.body.has(tag::LEGAL_CONFIRM)
172 }
173
174
175
176
177 pub fn set_no_party_i_ds(&mut self, v: isize) {
179 self.message.body.set_field(tag::NO_PARTY_I_DS, fixer::fix_int::FIXInt::from(v));
180 }
181
182 pub fn get_no_party_i_ds(&self) -> Result<isize, MessageRejectErrorEnum> {
184 let mut fld = field::NoPartyIDsField::new(0);
185 self.message.body.get_field(tag::NO_PARTY_I_DS, &mut fld.0)?;
186 Ok(fld.value())
187 }
188
189
190 pub fn has_no_party_i_ds(&self) -> bool {
192 self.message.body.has(tag::NO_PARTY_I_DS)
193 }
194
195
196
197
198 pub fn set_text(&mut self, v: String) {
200 self.message.body.set_field(tag::TEXT, FIXString::from(v));
201 }
202
203 pub fn get_text(&self) -> Result<String, MessageRejectErrorEnum> {
205 let mut fld = field::TextField::new(String::new());
206 self.message.body.get_field(tag::TEXT, &mut fld.0)?;
207 Ok(fld.value().to_string())
208 }
209
210
211 pub fn has_text(&self) -> bool {
213 self.message.body.has(tag::TEXT)
214 }
215
216
217
218
219 pub fn set_trade_date(&mut self, v: String) {
221 self.message.body.set_field(tag::TRADE_DATE, FIXString::from(v));
222 }
223
224 pub fn get_trade_date(&self) -> Result<String, MessageRejectErrorEnum> {
226 let mut fld = field::TradeDateField::new(String::new());
227 self.message.body.get_field(tag::TRADE_DATE, &mut fld.0)?;
228 Ok(fld.value().to_string())
229 }
230
231
232 pub fn has_trade_date(&self) -> bool {
234 self.message.body.has(tag::TRADE_DATE)
235 }
236
237
238
239
240 pub fn set_transact_time(&mut self, v: Timestamp) {
242 self.message.body.set_field(tag::TRANSACT_TIME, fixer::fix_utc_timestamp::FIXUTCTimestamp {
243 time: v,
244 precision: fixer::fix_utc_timestamp::TimestampPrecision::Millis,
245 });
246 }
247
248 pub fn get_transact_time(&self) -> Result<Timestamp, MessageRejectErrorEnum> {
250 let mut fld = field::TransactTimeField::new(Timestamp::UNIX_EPOCH);
251 self.message.body.get_field(tag::TRANSACT_TIME, &mut fld.0)?;
252 Ok(fld.value())
253 }
254
255
256 pub fn has_transact_time(&self) -> bool {
258 self.message.body.has(tag::TRANSACT_TIME)
259 }
260
261
262}
263
264pub type RouteOut = fn(msg: AllocationAck, session_id: SessionID) -> Result<(), MessageRejectErrorEnum>;
266
267pub type Route = (&'static str, &'static str, Box<dyn Fn(&Message, SessionID) -> Result<(), MessageRejectErrorEnum> + Send>);
269
270pub fn route(router: RouteOut) -> Route {
272 let r = move |msg: &Message, session_id: SessionID| -> Result<(), MessageRejectErrorEnum> {
273 router(AllocationAck::from_message(msg.clone()), session_id)
274 };
275 ("FIX.4.3", "P", Box::new(r))
276}