fixer_fix/fix40/
quote_request.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
12use rust_decimal::Decimal;
13
14
15use crate::field;
16use crate::tag;
17
18pub struct QuoteRequest {
20 pub message: Message,
21}
22
23impl QuoteRequest {
24 pub fn new(quote_req_id: field::QuoteReqIDField, symbol: field::SymbolField) -> Self {
26 let mut msg = Message::new();
27 msg.header.set_field(tag::MSG_TYPE, FIXString::from("R".to_string()));
28
29 msg.body.set_field(tag::QUOTE_REQ_ID, quote_req_id.0);
30
31 msg.body.set_field(tag::SYMBOL, symbol.0);
32
33 Self { message: msg }
34 }
35
36 pub fn from_message(msg: Message) -> Self {
38 Self { message: msg }
39 }
40
41 pub fn to_message(self) -> Message {
43 self.message
44 }
45
46
47
48
49 pub fn set_id_source(&mut self, v: String) {
51 self.message.body.set_field(tag::ID_SOURCE, FIXString::from(v));
52 }
53
54 pub fn get_id_source(&self) -> Result<String, MessageRejectErrorEnum> {
56 let mut fld = field::IDSourceField::new(String::new());
57 self.message.body.get_field(tag::ID_SOURCE, &mut fld.0)?;
58 Ok(fld.value().to_string())
59 }
60
61
62 pub fn has_id_source(&self) -> bool {
64 self.message.body.has(tag::ID_SOURCE)
65 }
66
67
68
69
70 pub fn set_issuer(&mut self, v: String) {
72 self.message.body.set_field(tag::ISSUER, FIXString::from(v));
73 }
74
75 pub fn get_issuer(&self) -> Result<String, MessageRejectErrorEnum> {
77 let mut fld = field::IssuerField::new(String::new());
78 self.message.body.get_field(tag::ISSUER, &mut fld.0)?;
79 Ok(fld.value().to_string())
80 }
81
82
83 pub fn has_issuer(&self) -> bool {
85 self.message.body.has(tag::ISSUER)
86 }
87
88
89
90
91 pub fn set_order_qty(&mut self, val: Decimal, scale: i32) {
93 self.message.body.set_field(tag::ORDER_QTY, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
94 }
95
96 pub fn get_order_qty(&self) -> Result<Decimal, MessageRejectErrorEnum> {
98 let mut fld = field::OrderQtyField::new(Decimal::ZERO, 0);
99 self.message.body.get_field(tag::ORDER_QTY, &mut fld.0)?;
100 Ok(fld.value())
101 }
102
103
104 pub fn has_order_qty(&self) -> bool {
106 self.message.body.has(tag::ORDER_QTY)
107 }
108
109
110
111
112 pub fn set_prev_close_px(&mut self, val: Decimal, scale: i32) {
114 self.message.body.set_field(tag::PREV_CLOSE_PX, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
115 }
116
117 pub fn get_prev_close_px(&self) -> Result<Decimal, MessageRejectErrorEnum> {
119 let mut fld = field::PrevClosePxField::new(Decimal::ZERO, 0);
120 self.message.body.get_field(tag::PREV_CLOSE_PX, &mut fld.0)?;
121 Ok(fld.value())
122 }
123
124
125 pub fn has_prev_close_px(&self) -> bool {
127 self.message.body.has(tag::PREV_CLOSE_PX)
128 }
129
130
131
132
133 pub fn set_quote_req_id(&mut self, v: String) {
135 self.message.body.set_field(tag::QUOTE_REQ_ID, FIXString::from(v));
136 }
137
138 pub fn get_quote_req_id(&self) -> Result<String, MessageRejectErrorEnum> {
140 let mut fld = field::QuoteReqIDField::new(String::new());
141 self.message.body.get_field(tag::QUOTE_REQ_ID, &mut fld.0)?;
142 Ok(fld.value().to_string())
143 }
144
145
146 pub fn has_quote_req_id(&self) -> bool {
148 self.message.body.has(tag::QUOTE_REQ_ID)
149 }
150
151
152
153
154 pub fn set_security_desc(&mut self, v: String) {
156 self.message.body.set_field(tag::SECURITY_DESC, FIXString::from(v));
157 }
158
159 pub fn get_security_desc(&self) -> Result<String, MessageRejectErrorEnum> {
161 let mut fld = field::SecurityDescField::new(String::new());
162 self.message.body.get_field(tag::SECURITY_DESC, &mut fld.0)?;
163 Ok(fld.value().to_string())
164 }
165
166
167 pub fn has_security_desc(&self) -> bool {
169 self.message.body.has(tag::SECURITY_DESC)
170 }
171
172
173
174
175 pub fn set_security_id(&mut self, v: String) {
177 self.message.body.set_field(tag::SECURITY_ID, FIXString::from(v));
178 }
179
180 pub fn get_security_id(&self) -> Result<String, MessageRejectErrorEnum> {
182 let mut fld = field::SecurityIDField::new(String::new());
183 self.message.body.get_field(tag::SECURITY_ID, &mut fld.0)?;
184 Ok(fld.value().to_string())
185 }
186
187
188 pub fn has_security_id(&self) -> bool {
190 self.message.body.has(tag::SECURITY_ID)
191 }
192
193
194
195
196 pub fn set_side(&mut self, v: String) {
198 self.message.body.set_field(tag::SIDE, FIXString::from(v));
199 }
200
201 pub fn get_side(&self) -> Result<String, MessageRejectErrorEnum> {
203 let mut fld = field::SideField::new(String::new());
204 self.message.body.get_field(tag::SIDE, &mut fld.0)?;
205 Ok(fld.value().to_string())
206 }
207
208
209 pub fn has_side(&self) -> bool {
211 self.message.body.has(tag::SIDE)
212 }
213
214
215
216
217 pub fn set_symbol(&mut self, v: String) {
219 self.message.body.set_field(tag::SYMBOL, FIXString::from(v));
220 }
221
222 pub fn get_symbol(&self) -> Result<String, MessageRejectErrorEnum> {
224 let mut fld = field::SymbolField::new(String::new());
225 self.message.body.get_field(tag::SYMBOL, &mut fld.0)?;
226 Ok(fld.value().to_string())
227 }
228
229
230 pub fn has_symbol(&self) -> bool {
232 self.message.body.has(tag::SYMBOL)
233 }
234
235
236
237
238 pub fn set_symbol_sfx(&mut self, v: String) {
240 self.message.body.set_field(tag::SYMBOL_SFX, FIXString::from(v));
241 }
242
243 pub fn get_symbol_sfx(&self) -> Result<String, MessageRejectErrorEnum> {
245 let mut fld = field::SymbolSfxField::new(String::new());
246 self.message.body.get_field(tag::SYMBOL_SFX, &mut fld.0)?;
247 Ok(fld.value().to_string())
248 }
249
250
251 pub fn has_symbol_sfx(&self) -> bool {
253 self.message.body.has(tag::SYMBOL_SFX)
254 }
255
256
257}
258
259pub type RouteOut = fn(msg: QuoteRequest, session_id: SessionID) -> Result<(), MessageRejectErrorEnum>;
261
262pub type Route = (&'static str, &'static str, Box<dyn Fn(&Message, SessionID) -> Result<(), MessageRejectErrorEnum> + Send>);
264
265pub fn route(router: RouteOut) -> Route {
267 let r = move |msg: &Message, session_id: SessionID| -> Result<(), MessageRejectErrorEnum> {
268 router(QuoteRequest::from_message(msg.clone()), session_id)
269 };
270 ("FIX.4.0", "R", Box::new(r))
271}