1#![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
12use rust_decimal::Decimal;
13
14
15use jiff::Timestamp;
16
17use crate::field;
18use crate::tag;
19
20pub struct Quote {
22 pub message: Message,
23}
24
25impl Quote {
26 pub fn new(quote_id: field::QuoteIDField, symbol: field::SymbolField, bid_px: field::BidPxField) -> Self {
28 let mut msg = Message::new();
29 msg.header.set_field(tag::MSG_TYPE, FIXString::from("S".to_string()));
30
31 msg.body.set_field(tag::QUOTE_ID, quote_id.0);
32
33 msg.body.set_field(tag::SYMBOL, symbol.0);
34
35 msg.body.set_field(tag::BID_PX, bid_px.0);
36
37 Self { message: msg }
38 }
39
40 pub fn from_message(msg: Message) -> Self {
42 Self { message: msg }
43 }
44
45 pub fn to_message(self) -> Message {
47 self.message
48 }
49
50
51
52
53 pub fn set_bid_px(&mut self, val: Decimal, scale: i32) {
55 self.message.body.set_field(tag::BID_PX, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
56 }
57
58 pub fn get_bid_px(&self) -> Result<Decimal, MessageRejectErrorEnum> {
60 let mut fld = field::BidPxField::new(Decimal::ZERO, 0);
61 self.message.body.get_field(tag::BID_PX, &mut fld.0)?;
62 Ok(fld.value())
63 }
64
65
66 pub fn has_bid_px(&self) -> bool {
68 self.message.body.has(tag::BID_PX)
69 }
70
71
72
73
74 pub fn set_bid_size(&mut self, val: Decimal, scale: i32) {
76 self.message.body.set_field(tag::BID_SIZE, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
77 }
78
79 pub fn get_bid_size(&self) -> Result<Decimal, MessageRejectErrorEnum> {
81 let mut fld = field::BidSizeField::new(Decimal::ZERO, 0);
82 self.message.body.get_field(tag::BID_SIZE, &mut fld.0)?;
83 Ok(fld.value())
84 }
85
86
87 pub fn has_bid_size(&self) -> bool {
89 self.message.body.has(tag::BID_SIZE)
90 }
91
92
93
94
95 pub fn set_id_source(&mut self, v: String) {
97 self.message.body.set_field(tag::ID_SOURCE, FIXString::from(v));
98 }
99
100 pub fn get_id_source(&self) -> Result<String, MessageRejectErrorEnum> {
102 let mut fld = field::IDSourceField::new(String::new());
103 self.message.body.get_field(tag::ID_SOURCE, &mut fld.0)?;
104 Ok(fld.value().to_string())
105 }
106
107
108 pub fn has_id_source(&self) -> bool {
110 self.message.body.has(tag::ID_SOURCE)
111 }
112
113
114
115
116 pub fn set_issuer(&mut self, v: String) {
118 self.message.body.set_field(tag::ISSUER, FIXString::from(v));
119 }
120
121 pub fn get_issuer(&self) -> Result<String, MessageRejectErrorEnum> {
123 let mut fld = field::IssuerField::new(String::new());
124 self.message.body.get_field(tag::ISSUER, &mut fld.0)?;
125 Ok(fld.value().to_string())
126 }
127
128
129 pub fn has_issuer(&self) -> bool {
131 self.message.body.has(tag::ISSUER)
132 }
133
134
135
136
137 pub fn set_offer_px(&mut self, val: Decimal, scale: i32) {
139 self.message.body.set_field(tag::OFFER_PX, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
140 }
141
142 pub fn get_offer_px(&self) -> Result<Decimal, MessageRejectErrorEnum> {
144 let mut fld = field::OfferPxField::new(Decimal::ZERO, 0);
145 self.message.body.get_field(tag::OFFER_PX, &mut fld.0)?;
146 Ok(fld.value())
147 }
148
149
150 pub fn has_offer_px(&self) -> bool {
152 self.message.body.has(tag::OFFER_PX)
153 }
154
155
156
157
158 pub fn set_offer_size(&mut self, val: Decimal, scale: i32) {
160 self.message.body.set_field(tag::OFFER_SIZE, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
161 }
162
163 pub fn get_offer_size(&self) -> Result<Decimal, MessageRejectErrorEnum> {
165 let mut fld = field::OfferSizeField::new(Decimal::ZERO, 0);
166 self.message.body.get_field(tag::OFFER_SIZE, &mut fld.0)?;
167 Ok(fld.value())
168 }
169
170
171 pub fn has_offer_size(&self) -> bool {
173 self.message.body.has(tag::OFFER_SIZE)
174 }
175
176
177
178
179 pub fn set_quote_id(&mut self, v: String) {
181 self.message.body.set_field(tag::QUOTE_ID, FIXString::from(v));
182 }
183
184 pub fn get_quote_id(&self) -> Result<String, MessageRejectErrorEnum> {
186 let mut fld = field::QuoteIDField::new(String::new());
187 self.message.body.get_field(tag::QUOTE_ID, &mut fld.0)?;
188 Ok(fld.value().to_string())
189 }
190
191
192 pub fn has_quote_id(&self) -> bool {
194 self.message.body.has(tag::QUOTE_ID)
195 }
196
197
198
199
200 pub fn set_quote_req_id(&mut self, v: String) {
202 self.message.body.set_field(tag::QUOTE_REQ_ID, FIXString::from(v));
203 }
204
205 pub fn get_quote_req_id(&self) -> Result<String, MessageRejectErrorEnum> {
207 let mut fld = field::QuoteReqIDField::new(String::new());
208 self.message.body.get_field(tag::QUOTE_REQ_ID, &mut fld.0)?;
209 Ok(fld.value().to_string())
210 }
211
212
213 pub fn has_quote_req_id(&self) -> bool {
215 self.message.body.has(tag::QUOTE_REQ_ID)
216 }
217
218
219
220
221 pub fn set_security_desc(&mut self, v: String) {
223 self.message.body.set_field(tag::SECURITY_DESC, FIXString::from(v));
224 }
225
226 pub fn get_security_desc(&self) -> Result<String, MessageRejectErrorEnum> {
228 let mut fld = field::SecurityDescField::new(String::new());
229 self.message.body.get_field(tag::SECURITY_DESC, &mut fld.0)?;
230 Ok(fld.value().to_string())
231 }
232
233
234 pub fn has_security_desc(&self) -> bool {
236 self.message.body.has(tag::SECURITY_DESC)
237 }
238
239
240
241
242 pub fn set_security_id(&mut self, v: String) {
244 self.message.body.set_field(tag::SECURITY_ID, FIXString::from(v));
245 }
246
247 pub fn get_security_id(&self) -> Result<String, MessageRejectErrorEnum> {
249 let mut fld = field::SecurityIDField::new(String::new());
250 self.message.body.get_field(tag::SECURITY_ID, &mut fld.0)?;
251 Ok(fld.value().to_string())
252 }
253
254
255 pub fn has_security_id(&self) -> bool {
257 self.message.body.has(tag::SECURITY_ID)
258 }
259
260
261
262
263 pub fn set_symbol(&mut self, v: String) {
265 self.message.body.set_field(tag::SYMBOL, FIXString::from(v));
266 }
267
268 pub fn get_symbol(&self) -> Result<String, MessageRejectErrorEnum> {
270 let mut fld = field::SymbolField::new(String::new());
271 self.message.body.get_field(tag::SYMBOL, &mut fld.0)?;
272 Ok(fld.value().to_string())
273 }
274
275
276 pub fn has_symbol(&self) -> bool {
278 self.message.body.has(tag::SYMBOL)
279 }
280
281
282
283
284 pub fn set_symbol_sfx(&mut self, v: String) {
286 self.message.body.set_field(tag::SYMBOL_SFX, FIXString::from(v));
287 }
288
289 pub fn get_symbol_sfx(&self) -> Result<String, MessageRejectErrorEnum> {
291 let mut fld = field::SymbolSfxField::new(String::new());
292 self.message.body.get_field(tag::SYMBOL_SFX, &mut fld.0)?;
293 Ok(fld.value().to_string())
294 }
295
296
297 pub fn has_symbol_sfx(&self) -> bool {
299 self.message.body.has(tag::SYMBOL_SFX)
300 }
301
302
303
304
305 pub fn set_valid_until_time(&mut self, v: Timestamp) {
307 self.message.body.set_field(tag::VALID_UNTIL_TIME, fixer::fix_utc_timestamp::FIXUTCTimestamp {
308 time: v,
309 precision: fixer::fix_utc_timestamp::TimestampPrecision::Millis,
310 });
311 }
312
313 pub fn get_valid_until_time(&self) -> Result<Timestamp, MessageRejectErrorEnum> {
315 let mut fld = field::ValidUntilTimeField::new(Timestamp::UNIX_EPOCH);
316 self.message.body.get_field(tag::VALID_UNTIL_TIME, &mut fld.0)?;
317 Ok(fld.value())
318 }
319
320
321 pub fn has_valid_until_time(&self) -> bool {
323 self.message.body.has(tag::VALID_UNTIL_TIME)
324 }
325
326
327}
328
329pub type RouteOut = fn(msg: Quote, session_id: SessionID) -> Result<(), MessageRejectErrorEnum>;
331
332pub type Route = (&'static str, &'static str, Box<dyn Fn(&Message, SessionID) -> Result<(), MessageRejectErrorEnum> + Send>);
334
335pub fn route(router: RouteOut) -> Route {
337 let r = move |msg: &Message, session_id: SessionID| -> Result<(), MessageRejectErrorEnum> {
338 router(Quote::from_message(msg.clone()), session_id)
339 };
340 ("FIX.4.0", "S", Box::new(r))
341}