1use crate::prelude::{Deserialize, Serialize};
16use std::collections::HashSet;
17use std::fmt::{Debug, Display};
18
19#[derive(Clone, Deserialize, Serialize, PartialEq, Eq, Default, Hash)]
24#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
25pub enum StreamingMarketField {
26 MidOpen,
28 High,
30 Low,
32 Change,
34 ChangePct,
36 UpdateTime,
38 MarketDelay,
40 MarketState,
42 Bid,
44 #[default]
46 Offer,
47}
48
49impl Debug for StreamingMarketField {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 let field_name = serde_json::to_string(self).unwrap();
52 write!(f, "{:?}", field_name)
53 }
54}
55
56impl Display for StreamingMarketField {
57 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58 write!(f, "{:?}", self)
59 }
60}
61
62pub(crate) fn get_streaming_market_fields(fields: &HashSet<StreamingMarketField>) -> Vec<String> {
77 let mut fields_vec = Vec::new();
78 for field in fields {
79 let val = serde_json::to_value(field).expect("Failed to serialize StreamingMarketField");
81 match val {
82 serde_json::Value::String(s) => fields_vec.push(s),
83 _ => fields_vec.push(format!("{:?}", field)),
85 }
86 }
87 fields_vec
88}
89
90#[derive(Clone, Deserialize, Serialize, PartialEq, Eq, Default, Hash)]
95#[serde(rename_all = "UPPERCASE")]
96pub enum StreamingPriceField {
97 #[serde(rename = "MID_OPEN")]
99 MidOpen,
100 High,
102 Low,
104 BidQuoteId,
106 AskQuoteId,
108 BidPrice1,
110 BidPrice2,
112 BidPrice3,
114 BidPrice4,
116 BidPrice5,
118 AskPrice1,
120 AskPrice2,
122 AskPrice3,
124 AskPrice4,
126 #[default]
128 AskPrice5,
129 BidSize1,
131 BidSize2,
133 BidSize3,
135 BidSize4,
137 BidSize5,
139 AskSize1,
141 AskSize2,
143 AskSize3,
145 AskSize4,
147 AskSize5,
149 Currency0,
151 Currency1,
153 C1BidSize1,
155 C1BidSize2,
157 C1BidSize3,
159 C1BidSize4,
161 C1BidSize5,
163 C1AskSize1,
165 C1AskSize2,
167 C1AskSize3,
169 C1AskSize4,
171 C1AskSize5,
173 Currency2,
175 C2BidSize1,
177 C2BidSize2,
179 C2BidSize3,
181 C2BidSize4,
183 C2BidSize5,
185 C2AskSize1,
187 C2AskSize2,
189 C2AskSize3,
191 C2AskSize4,
193 C2AskSize5,
195 Currency3,
197 C3BidSize1,
199 C3BidSize2,
201 C3BidSize3,
203 C3BidSize4,
205 C3BidSize5,
207 C3AskSize1,
209 C3AskSize2,
211 C3AskSize3,
213 C3AskSize4,
215 C3AskSize5,
217 Currency4,
219 C4BidSize1,
221 C4BidSize2,
223 C4BidSize3,
225 C4BidSize4,
227 C4BidSize5,
229 C4AskSize1,
231 C4AskSize2,
233 C4AskSize3,
235 C4AskSize4,
237 C4AskSize5,
239 Currency5,
241 C5BidSize1,
243 C5BidSize2,
245 C5BidSize3,
247 C5BidSize4,
249 C5BidSize5,
251 C5AskSize1,
253 C5AskSize2,
255 C5AskSize3,
257 C5AskSize4,
259 C5AskSize5,
261 Timestamp,
263 #[serde(rename = "DLG_FLAG")]
265 DlgFlag,
266}
267
268impl Debug for StreamingPriceField {
269 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
270 let field_name = serde_json::to_string(self).unwrap();
271 write!(f, "{:?}", field_name)
272 }
273}
274
275impl Display for StreamingPriceField {
276 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
277 write!(f, "{:?}", self)
278 }
279}
280
281pub(crate) fn get_streaming_price_fields(fields: &HashSet<StreamingPriceField>) -> Vec<String> {
296 let map_field = |f: &StreamingPriceField| -> &'static str {
298 match f {
299 StreamingPriceField::MidOpen => "MID_OPEN",
301 StreamingPriceField::High => "HIGH",
302 StreamingPriceField::Low => "LOW",
303 StreamingPriceField::BidQuoteId => "BIDQUOTEID",
304 StreamingPriceField::AskQuoteId => "ASKQUOTEID",
305
306 StreamingPriceField::BidPrice1 => "BIDPRICE1",
308 StreamingPriceField::BidPrice2 => "BIDPRICE2",
309 StreamingPriceField::BidPrice3 => "BIDPRICE3",
310 StreamingPriceField::BidPrice4 => "BIDPRICE4",
311 StreamingPriceField::BidPrice5 => "BIDPRICE5",
312
313 StreamingPriceField::AskPrice1 => "ASKPRICE1",
315 StreamingPriceField::AskPrice2 => "ASKPRICE2",
316 StreamingPriceField::AskPrice3 => "ASKPRICE3",
317 StreamingPriceField::AskPrice4 => "ASKPRICE4",
318 StreamingPriceField::AskPrice5 => "ASKPRICE5",
319
320 StreamingPriceField::BidSize1 => "BIDSIZE1",
322 StreamingPriceField::BidSize2 => "BIDSIZE2",
323 StreamingPriceField::BidSize3 => "BIDSIZE3",
324 StreamingPriceField::BidSize4 => "BIDSIZE4",
325 StreamingPriceField::BidSize5 => "BIDSIZE5",
326
327 StreamingPriceField::AskSize1 => "ASKSIZE1",
329 StreamingPriceField::AskSize2 => "ASKSIZE2",
330 StreamingPriceField::AskSize3 => "ASKSIZE3",
331 StreamingPriceField::AskSize4 => "ASKSIZE4",
332 StreamingPriceField::AskSize5 => "ASKSIZE5",
333
334 StreamingPriceField::Currency0 => "CURRENCY0",
336 StreamingPriceField::Currency1 => "CURRENCY1",
337 StreamingPriceField::Currency2 => "CURRENCY2",
338 StreamingPriceField::Currency3 => "CURRENCY3",
339 StreamingPriceField::Currency4 => "CURRENCY4",
340 StreamingPriceField::Currency5 => "CURRENCY5",
341
342 StreamingPriceField::C1BidSize1 => "C1BIDSIZE1",
344 StreamingPriceField::C1BidSize2 => "C1BIDSIZE2",
345 StreamingPriceField::C1BidSize3 => "C1BIDSIZE3",
346 StreamingPriceField::C1BidSize4 => "C1BIDSIZE4",
347 StreamingPriceField::C1BidSize5 => "C1BIDSIZE5",
348 StreamingPriceField::C1AskSize1 => "C1ASKSIZE1",
350 StreamingPriceField::C1AskSize2 => "C1ASKSIZE2",
351 StreamingPriceField::C1AskSize3 => "C1ASKSIZE3",
352 StreamingPriceField::C1AskSize4 => "C1ASKSIZE4",
353 StreamingPriceField::C1AskSize5 => "C1ASKSIZE5",
354
355 StreamingPriceField::C2BidSize1 => "C2BIDSIZE1",
357 StreamingPriceField::C2BidSize2 => "C2BIDSIZE2",
358 StreamingPriceField::C2BidSize3 => "C2BIDSIZE3",
359 StreamingPriceField::C2BidSize4 => "C2BIDSIZE4",
360 StreamingPriceField::C2BidSize5 => "C2BIDSIZE5",
361 StreamingPriceField::C2AskSize1 => "C2ASKSIZE1",
363 StreamingPriceField::C2AskSize2 => "C2ASKSIZE2",
364 StreamingPriceField::C2AskSize3 => "C2ASKSIZE3",
365 StreamingPriceField::C2AskSize4 => "C2ASKSIZE4",
366 StreamingPriceField::C2AskSize5 => "C2ASKSIZE5",
367
368 StreamingPriceField::C3BidSize1 => "C3BIDSIZE1",
370 StreamingPriceField::C3BidSize2 => "C3BIDSIZE2",
371 StreamingPriceField::C3BidSize3 => "C3BIDSIZE3",
372 StreamingPriceField::C3BidSize4 => "C3BIDSIZE4",
373 StreamingPriceField::C3BidSize5 => "C3BIDSIZE5",
374 StreamingPriceField::C3AskSize1 => "C3ASKSIZE1",
376 StreamingPriceField::C3AskSize2 => "C3ASKSIZE2",
377 StreamingPriceField::C3AskSize3 => "C3ASKSIZE3",
378 StreamingPriceField::C3AskSize4 => "C3ASKSIZE4",
379 StreamingPriceField::C3AskSize5 => "C3ASKSIZE5",
380
381 StreamingPriceField::C4BidSize1 => "C4BIDSIZE1",
383 StreamingPriceField::C4BidSize2 => "C4BIDSIZE2",
384 StreamingPriceField::C4BidSize3 => "C4BIDSIZE3",
385 StreamingPriceField::C4BidSize4 => "C4BIDSIZE4",
386 StreamingPriceField::C4BidSize5 => "C4BIDSIZE5",
387 StreamingPriceField::C4AskSize1 => "C4ASKSIZE1",
389 StreamingPriceField::C4AskSize2 => "C4ASKSIZE2",
390 StreamingPriceField::C4AskSize3 => "C4ASKSIZE3",
391 StreamingPriceField::C4AskSize4 => "C4ASKSIZE4",
392 StreamingPriceField::C4AskSize5 => "C4ASKSIZE5",
393
394 StreamingPriceField::C5BidSize1 => "C5BIDSIZE1",
396 StreamingPriceField::C5BidSize2 => "C5BIDSIZE2",
397 StreamingPriceField::C5BidSize3 => "C5BIDSIZE3",
398 StreamingPriceField::C5BidSize4 => "C5BIDSIZE4",
399 StreamingPriceField::C5BidSize5 => "C5BIDSIZE5",
400 StreamingPriceField::C5AskSize1 => "C5ASKSIZE1",
402 StreamingPriceField::C5AskSize2 => "C5ASKSIZE2",
403 StreamingPriceField::C5AskSize3 => "C5ASKSIZE3",
404 StreamingPriceField::C5AskSize4 => "C5ASKSIZE4",
405 StreamingPriceField::C5AskSize5 => "C5ASKSIZE5",
406
407 StreamingPriceField::Timestamp => "TIMESTAMP",
409 StreamingPriceField::DlgFlag => "DLG_FLAG",
410 }
411 };
412
413 let mut fields_vec = Vec::with_capacity(fields.len());
414 for field in fields {
415 fields_vec.push(map_field(field).to_string());
416 }
417 fields_vec
418}
419
420#[derive(Clone, Deserialize, Serialize, PartialEq, Eq, Default, Hash)]
425#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
426pub enum StreamingAccountDataField {
427 #[default]
429 Pnl,
430 Deposit,
432 AvailableCash,
434 PnlLr,
436 PnlNlr,
438 Funds,
440 Margin,
442 MarginLr,
444 MarginNlr,
446 AvailableToDeal,
448 Equity,
450 EquityUsed,
452}
453
454impl Debug for StreamingAccountDataField {
455 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
456 let field_name = serde_json::to_string(self).unwrap();
457 write!(f, "{:?}", field_name)
458 }
459}
460
461impl Display for StreamingAccountDataField {
462 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
463 write!(f, "{:?}", self)
464 }
465}
466
467pub(crate) fn get_streaming_account_data_fields(
482 fields: &HashSet<StreamingAccountDataField>,
483) -> Vec<String> {
484 let mut fields_vec = Vec::new();
485 for field in fields {
486 let val =
487 serde_json::to_value(field).expect("Failed to serialize StreamingAccountDataField");
488 match val {
489 serde_json::Value::String(s) => fields_vec.push(s),
490 _ => fields_vec.push(format!("{:?}", field)),
491 }
492 }
493 fields_vec
494}