1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
use std::collections::{HashMap, HashSet};

use ordered_float::NotNan;
use rust_decimal::Decimal;

use super::constants::{
    OPCODE_HANDSHAKE, OPCODE_REQUEST_FA, OPCODE_REQ_ACCOUNT_UPDATES, OPCODE_REQ_CURRENT_TIME,
    OPCODE_REQ_FAMILY_CODES, OPCODE_REQ_IDS, OPCODE_REQ_MARKET_RULE,
    OPCODE_REQ_MKT_DEPTH_EXCHANGES, OPCODE_REQ_NEWS_PROVIDERS, OPCODE_REQ_OPEN_ORDERS,
    OPCODE_REQ_SCANNER_PARAMETERS, OPCODE_VERIFY_AND_AUTH_MESSAGE, OPCODE_VERIFY_AND_AUTH_REQUEST,
    OPCODE_VERIFY_MESSAGE, OPCODE_VERIFY_REQUEST,
};
use crate::domain::{*, market_data::{MarketDataType, TickByTickType}};

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub enum Response {
    HandshakeAck(HandshakeAck),
    HistoricalTickLastMsg(HistoricalTickLastMsg),
    HistoricalTickBidAskMsg(HistoricalTickBidAskMsg),
    HistoricalTicksMsg(HistoricalTicksMsg),
    MarketRule(MarketRule),
    RerouteMktDepthReq(RerouteMktDepthReq),
    RerouteMktDataReq(RerouteMktDataReq),
    HistoricalDataUpdateMsg(HistoricalDataUpdateMsg),
    PnlSingleMsg(PnlSingleMsg),
    PnlMsg(PnlMsg),
    HistogramDataMsg(HistogramDataMsg),
    HistoricalNewsEndMsg(HistoricalNewsEndMsg),
    HistoricalNewsMsg(HistoricalNewsMsg),
    NewsArticleMsg(NewsArticleMsg),
    NewsProviderMsg(NewsProviderMsg),
    TickNewsMsg(TickNewsMsg),
    HeadTimestampMsg(HeadTimestampMsg),
    MktDepthExchangesMsg(MktDepthExchangesMsg),
    SymbolSamplesMsg(SymbolSamplesMsg),
    FamilyCodesMsg(FamilyCodesMsg),
    SoftDollarTiersMsg(SoftDollarTiersMsg),
    SecurityDefinitionOptionalParameterEndMsg(SecurityDefinitionOptionalParameterEndMsg),
    SecurityDefinitionOptionalParameterMsg(SecurityDefinitionOptionalParameterMsg),
    VerifyAndAuthCompletedMsg(VerifyAndAuthCompletedMsg),
    VerifyAndAuthMessageMsg(VerifyAndAuthMessageMsg),
    DisplayGroupUpdatedMsg(DisplayGroupUpdatedMsg),
    DisplayGroupListMsg(DisplayGroupListMsg),
    VerifyCompletedMsg(VerifyCompletedMsg),
    VerifyMessageApiMsg(VerifyMessageApiMsg),
    CommissionReportMsg(CommissionReportMsg),
    MarketDataTypeMsg(MarketDataTypeMsg),
    TickSnapshotEndMsg(TickSnapshotEndMsg),
    DeltaNeutralValidationMsg(DeltaNeutralValidationMsg),
    ExecutionDataEndMsg(ExecutionDataEndMsg),
    AcctDownloadEndMsg(AcctDownloadEndMsg),
    OpenOrderEndMsg(OpenOrderEndMsg),
    ContractDataEndMsg(ContractDataEndMsg),
    FundamentalDataMsg(FundamentalDataMsg),
    RealTimeBarsMsg(RealTimeBarsMsg),
    CurrentTimeMsg(CurrentTimeMsg),
    ScannerDataMsg(ScannerDataMsg),
    ScannerParametersMsg(ScannerParametersMsg),
    HistoricalDataMsg(HistoricalDataMsg),
    ReceiveFaMsg(ReceiveFaMsg),
    ManagedAcctsMsg(ManagedAcctsMsg),
    NewsBulletinsMsg(NewsBulletinsMsg),
    MarketDepthL2Msg(MarketDepthL2Msg),
    MarketDepthMsg(MarketDepthMsg),
    ExecutionDataMsg(ExecutionDataMsg),
    BondContractDataMsg(BondContractDataMsg),
    ContractDataMsg(ContractDataMsg),
    NextValidIdMsg(NextValidIdMsg),
    OpenOrderMsg(OpenOrderMsg),
    ErrMsgMsg(ErrMsgMsg),
    AcctUpdateTimeMsg(AcctUpdateTimeMsg),
    PortfolioValueMsg(PortfolioValueMsg),
    AcctValueMsg(AcctValueMsg),
    OrderStatusMsg(OrderStatusMsg),
    TickEFPMsg(TickEFPMsg),
    TickStringMsg(TickStringMsg),
    TickGenericMsg(TickGenericMsg),
    TickOptionComputationMsg(TickOptionComputationMsg),
    AccountSummaryEndMsg(AccountSummaryEndMsg),
    AccountSummaryMsg(AccountSummaryMsg),
    PositionEndMsg(PositionEndMsg),
    PositionMsg(PositionMsg),
    TickSizeMsg(TickSizeMsg),
    TickPriceMsg(TickPriceMsg),
    PositionMultiMsg(PositionMultiMsg),
    PositionMultiEndMsg(PositionMultiEndMsg),
    AccountUpdateMultiMsg(AccountUpdateMultiMsg),
    AccountUpdateMultiEndMsg(AccountUpdateMultiEndMsg),
    TickReqParamsMsg(TickReqParamsMsg),
    TickByTickAllLastMsg(TickByTickAllLastMsg),
    TickByTickBidAskMsg(TickByTickBidAskMsg),
    TickByTickMidPointMsg(TickByTickMidPointMsg),
    TickByTickNoneMsg(TickByTickNoneMsg),
    SmartComponentsMsg(SmartComponentsMsg),
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct HandshakeAck {
    pub server_version: i32,
    pub addr_or_time: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct HistoricalTickLastMsg {
    pub req_id: i32,
    pub ticks: Vec<HistoricalTickLast>,
    pub done: bool,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct HistoricalTickBidAskMsg {
    pub req_id: i32,
    pub ticks: Vec<HistoricalTickBidAsk>,
    pub done: bool,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct HistoricalTicksMsg {
    pub req_id: i32,
    pub ticks: Vec<HistoricalTick>,
    pub done: bool,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct MarketRule {
    pub market_rule_id: i32,
    pub price_increments: Vec<PriceIncrement>,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct RerouteMktDepthReq {
    pub req_id: i32,
    pub con_id: i32,
    pub exchange: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct RerouteMktDataReq {
    pub req_id: i32,
    pub con_id: i32,
    pub exchange: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct HistoricalDataUpdateMsg {
    pub req_id: i32,
    pub bar: Bar,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct PnlSingleMsg {
    pub req_id: i32,
    pub pos: i32,
    pub daily_pnl: f64,
    pub unrealized_pnl: f64,
    pub realized_pnl: f64,
    pub value: f64,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct PnlMsg {
    pub req_id: i32,
    pub daily_pnl: f64,
    pub unrealized_pnl: f64,
    pub realized_pnl: f64,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct HistogramDataMsg {
    pub req_id: i32,
    pub items: Vec<HistogramEntry>,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct HistoricalNewsEndMsg {
    pub req_id: i32,
    pub has_more: bool,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct HistoricalNewsMsg {
    pub req_id: i32,
    pub time: String,
    pub provider_code: String,
    pub article_id: String,
    pub headline: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct NewsArticleMsg {
    pub req_id: i32,
    pub article_type: i32,
    pub article_text: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct NewsProviderMsg {
    pub providers: Vec<NewsProvider>,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickNewsMsg {
    pub req_id: i32,
    pub time_stamp: i64,
    pub provider_code: String,
    pub article_id: String,
    pub headline: String,
    pub extra_data: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct HeadTimestampMsg {
    pub req_id: i32,
    pub head_time_stamp: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct MktDepthExchangesMsg {
    pub depth_mkt_data_descriptions: Vec<DepthMktDataDescription>,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct SymbolSamplesMsg {
    pub req_id: i32,
    pub contract_descriptions: Vec<ContractDescription>,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct FamilyCodesMsg {
    pub family_codes: Vec<FamilyCode>,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct SoftDollarTiersMsg {
    pub req_id: i32,
    pub tiers: Vec<SoftDollarTier>,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct SecurityDefinitionOptionalParameterEndMsg {
    pub req_id: i32,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct SecurityDefinitionOptionalParameterMsg {
    pub req_id: i32,
    pub exchange: String,
    pub underlying_con_id: i32,
    pub trading_class: String,
    pub multiplier: String,
    pub expirations: HashSet<String>,
    pub strikes: HashSet<NotNan<f64>>,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct VerifyAndAuthCompletedMsg {
    pub is_successful: bool,
    pub error_text: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct VerifyAndAuthMessageMsg {
    pub api_data: String,
    pub xyz_challenge: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct DisplayGroupUpdatedMsg {
    pub req_id: i32,
    pub contract_info: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct DisplayGroupListMsg {
    pub req_id: i32,
    pub groups: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct VerifyCompletedMsg {
    pub is_successful: bool,
    pub error_text: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct VerifyMessageApiMsg {
    pub api_data: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct CommissionReportMsg {
    pub report: CommissionReport,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct MarketDataTypeMsg {
    pub req_id: i32,
    pub market_data_type: MarketDataType,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickSnapshotEndMsg {
    pub req_id: i32,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct DeltaNeutralValidationMsg {
    pub req_id: i32,
    pub delta_neutral_contract: DeltaNeutralContract,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ExecutionDataEndMsg {
    pub req_id: i32,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct AcctDownloadEndMsg {
    pub account_name: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct OpenOrderEndMsg {}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ContractDataEndMsg {
    pub req_id: i32,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct FundamentalDataMsg {
    pub req_id: i32,
    pub data: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct RealTimeBarsMsg {
    pub req_id: i32,
    pub time: i64,
    pub open: f64,
    pub high: f64,
    pub low: f64,
    pub close: f64,
    pub volume: i64,
    pub wap: f64,
    pub count: i32,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct CurrentTimeMsg {
    pub time: i64,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ScannerParametersMsg {
    pub xml: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct HistoricalDataMsg {
    pub req_id: i32,
    pub start_date: String,
    pub end_date: String,
    pub bars: Vec<Bar>,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ReceiveFaMsg {
    pub fa_data_type: i32,
    pub xml: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ManagedAcctsMsg {
    pub accounts: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct NewsBulletinsMsg {
    pub req_id: i32,
    pub msg_type: i32,
    pub message: String,
    pub originating_exch: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct MarketDepthL2Msg {
    pub id: i32,
    pub position: i32,
    pub market_maker: String,
    pub operation: i32,
    pub side: i32,
    pub price: f64,
    pub size: i32,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct MarketDepthMsg {
    pub id: i32,
    pub position: i32,
    pub operation: i32,
    pub side: i32,
    pub price: f64,
    pub size: Decimal,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ExecutionDataMsg {
    pub req_id: i32,
    pub contract: Contract,
    pub exec: Execution,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct BondContractDataMsg {
    pub req_id: i32,
    pub contract_details: ContractDetails,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ContractDataMsg {
    pub req_id: i32,
    pub contract_details: ContractDetails,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ScannerData {
    pub rank: i32,
    pub contract_details: ContractDetails,
    pub distance: String,
    pub benchmark: String,
    pub projection: String,
    pub legs: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ScannerDataMsg {
    pub req_id: i32,
    pub datas: Vec<ScannerData>,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct NextValidIdMsg {
    pub order_id: i32,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct OpenOrderMsg {
    pub order_id: i32,
    pub contract: Contract,
    pub order: Order,
    pub order_state: OrderState,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ErrMsgMsg {
    pub id: i32,
    pub error_code: i32,
    pub error_message: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct AcctUpdateTimeMsg {
    pub time_stamp: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct PortfolioValueMsg {
    pub contract: Contract,
    pub position: f64,
    pub market_price: f64,
    pub market_value: f64,
    pub average_cost: f64,
    pub unrealized_pnl: f64,
    pub realized_pnl: f64,
    pub account_name: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct AcctValueMsg {
    pub key: String,
    pub val: String,
    pub cur: String,
    pub account_name: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct OrderStatusMsg {
    pub id: i32,
    pub status: String,
    pub filled: f64,
    pub remaining: f64,
    pub avg_fill_price: f64,
    pub perm_id: i32,
    pub parent_id: i32,
    pub last_fill_price: f64,
    pub client_id: i32,
    pub why_held: String,
    pub mkt_cap_price: f64,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickEFPMsg {
    pub req_id: i32,
    pub tick_type: Decimal,
    pub basis_points: f64,
    pub formatted_basis_points: String,
    pub implied_futures_price: f64,
    pub hold_days: i32,
    pub future_last_trade_date: String,
    pub dividend_impact: f64,
    pub dividends_to_last_trade_date: f64,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickStringMsg {
    pub req_id: i32,
    pub tick_type: TickType,
    pub value: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickGenericMsg {
    pub req_id: i32,
    pub tick_type: TickType,
    pub value: f64,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickOptionComputationMsg {
    pub req_id: i32,
    pub tick_type: TickType,
    pub implied_vol: f64,
    pub delta: f64,
    pub opt_price: f64,
    pub pv_dividend: f64,
    pub gamma: f64,
    pub vega: f64,
    pub theta: f64,
    pub und_price: f64,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct AccountSummaryEndMsg {
    pub req_id: i32,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct AccountSummaryMsg {
    pub req_id: i32,
    pub account: String,
    pub tag: String,
    pub value: String,
    pub currency: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct PositionEndMsg {}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct PositionMsg {
    pub account: String,
    pub contract: Contract,
    pub pos: f64,
    pub avg_cost: f64,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickSizeMsg {
    pub req_id: i32,
    pub tick_type: TickType,
    pub size: Decimal,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickPriceMsg {
    pub req_id: i32,
    pub tick_type: TickType,
    pub price: f64,
    pub size: Decimal,
    pub attribs: TickAttr,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct PositionMultiMsg {
    pub req_id: i32,
    pub account: String,
    pub model_code: String,
    pub contract: Contract,
    pub pos: f64,
    pub avg_cost: f64,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct PositionMultiEndMsg {
    pub req_id: i32,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct AccountUpdateMultiMsg {
    pub req_id: i32,
    pub account: String,
    pub model_code: String,
    pub key: String,
    pub value: String,
    pub currency: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct AccountUpdateMultiEndMsg {
    pub req_id: i32,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct SmartComponentsMsg {
    pub req_id: i32,
    pub map: HashMap<i32, (String, u8)>,
    //map: HashMap<i32, Entry<String, char>>,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickReqParamsMsg {
    pub req_id: i32,
    pub min_tick: f64,
    pub bbo_exchange: String,
    pub snapshot_permissions: i32,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickByTickAllLastMsg {
    pub req_id: i32,
    pub tick_type: TickByTickType,
    pub time: i64,
    pub price: f64,
    pub size: Decimal,
    pub attribs: TickAttr,
    pub exchange: String,
    pub special_conditions: String,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickByTickBidAskMsg {
    pub req_id: i32,
    pub time: i64,
    pub bid_price: f64,
    pub ask_price: f64,
    pub bid_size: Decimal,
    pub ask_size: Decimal,
    pub attribs: TickAttr,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickByTickMidPointMsg {
    pub req_id: i32,
    pub time: i64,
    pub mid_point: f64,
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TickByTickNoneMsg {}

impl Response {
    pub fn request_id(&self) -> Option<i32> {
        match self {
            Response::HandshakeAck(ref msg) => Some(OPCODE_HANDSHAKE),
            Response::HistoricalTickLastMsg(ref msg) => Some(msg.req_id),
            Response::HistoricalTickBidAskMsg(ref msg) => Some(msg.req_id),
            Response::HistoricalTicksMsg(ref msg) => Some(msg.req_id),
            Response::MarketRule(ref msg) => Some(OPCODE_REQ_MARKET_RULE),
            Response::RerouteMktDepthReq(ref msg) => Some(msg.req_id),
            Response::RerouteMktDataReq(ref msg) => Some(msg.req_id),
            Response::HistoricalDataUpdateMsg(ref msg) => Some(msg.req_id),
            Response::PnlSingleMsg(ref msg) => Some(msg.req_id),
            Response::PnlMsg(ref msg) => Some(msg.req_id),
            Response::HistogramDataMsg(ref msg) => Some(msg.req_id),
            Response::HistoricalNewsEndMsg(ref msg) => Some(msg.req_id),
            Response::HistoricalNewsMsg(ref msg) => Some(msg.req_id),
            Response::NewsArticleMsg(ref msg) => Some(msg.req_id),
            Response::NewsProviderMsg(ref msg) => Some(OPCODE_REQ_NEWS_PROVIDERS),
            Response::TickNewsMsg(ref msg) => Some(msg.req_id),
            Response::HeadTimestampMsg(ref msg) => Some(msg.req_id),
            Response::MktDepthExchangesMsg(ref msg) => Some(OPCODE_REQ_MKT_DEPTH_EXCHANGES),
            Response::SymbolSamplesMsg(ref msg) => Some(msg.req_id),
            Response::FamilyCodesMsg(ref msg) => Some(OPCODE_REQ_FAMILY_CODES),
            Response::SoftDollarTiersMsg(ref msg) => Some(msg.req_id),
            Response::SecurityDefinitionOptionalParameterEndMsg(ref msg) => Some(msg.req_id),
            Response::SecurityDefinitionOptionalParameterMsg(ref msg) => Some(msg.req_id),
            Response::VerifyAndAuthCompletedMsg(ref msg) => Some(OPCODE_VERIFY_AND_AUTH_REQUEST),
            Response::VerifyAndAuthMessageMsg(ref msg) => Some(OPCODE_VERIFY_AND_AUTH_MESSAGE),
            Response::DisplayGroupUpdatedMsg(ref msg) => Some(msg.req_id),
            Response::DisplayGroupListMsg(ref msg) => Some(msg.req_id),
            Response::VerifyCompletedMsg(ref msg) => Some(OPCODE_VERIFY_REQUEST),
            Response::VerifyMessageApiMsg(ref msg) => Some(OPCODE_VERIFY_MESSAGE),
            Response::CommissionReportMsg(ref msg) => None,
            Response::MarketDataTypeMsg(ref msg) => Some(msg.req_id),
            Response::TickSnapshotEndMsg(ref msg) => Some(msg.req_id),
            Response::DeltaNeutralValidationMsg(ref msg) => Some(msg.req_id),
            Response::ExecutionDataEndMsg(ref msg) => Some(msg.req_id),
            Response::AcctDownloadEndMsg(ref msg) => None,
            Response::OpenOrderEndMsg(ref msg) => None,
            Response::ContractDataEndMsg(ref msg) => Some(msg.req_id),
            Response::FundamentalDataMsg(ref msg) => Some(msg.req_id),
            Response::RealTimeBarsMsg(ref msg) => Some(msg.req_id),
            Response::CurrentTimeMsg(ref msg) => Some(OPCODE_REQ_CURRENT_TIME),
            Response::ScannerDataMsg(ref msg) => Some(msg.req_id),
            Response::ScannerParametersMsg(ref msg) => Some(OPCODE_REQ_SCANNER_PARAMETERS),
            Response::HistoricalDataMsg(ref msg) => Some(msg.req_id),
            Response::ReceiveFaMsg(ref msg) => Some(OPCODE_REQUEST_FA),
            Response::ManagedAcctsMsg(ref msg) => Some(OPCODE_REQ_ACCOUNT_UPDATES),
            Response::NewsBulletinsMsg(ref msg) => Some(msg.req_id),
            Response::MarketDepthL2Msg(ref msg) => Some(msg.id),
            Response::MarketDepthMsg(ref msg) => Some(msg.id),
            Response::ExecutionDataMsg(ref msg) => Some(msg.req_id),
            Response::BondContractDataMsg(ref msg) => Some(msg.req_id),
            Response::ContractDataMsg(ref msg) => Some(msg.req_id),
            Response::NextValidIdMsg(ref msg) => Some(OPCODE_REQ_IDS),
            Response::OpenOrderMsg(ref msg) => Some(OPCODE_REQ_OPEN_ORDERS),
            Response::ErrMsgMsg(ref msg) => Some(msg.id),
            Response::AcctUpdateTimeMsg(ref msg) => None,
            Response::PortfolioValueMsg(ref msg) => None,
            Response::AcctValueMsg(ref msg) => None,
            Response::OrderStatusMsg(ref msg) => None,
            Response::TickEFPMsg(ref msg) => Some(msg.req_id),
            Response::TickStringMsg(ref msg) => Some(msg.req_id),
            Response::TickGenericMsg(ref msg) => Some(msg.req_id),
            Response::TickOptionComputationMsg(ref msg) => Some(msg.req_id),
            Response::AccountSummaryEndMsg(ref msg) => Some(msg.req_id),
            Response::AccountSummaryMsg(ref msg) => Some(msg.req_id),
            Response::PositionEndMsg(ref msg) => None,
            Response::PositionMsg(ref msg) => None,
            Response::TickSizeMsg(ref msg) => Some(msg.req_id),
            Response::TickPriceMsg(ref msg) => Some(msg.req_id),
            Response::PositionMultiMsg(ref msg) => Some(msg.req_id),
            Response::PositionMultiEndMsg(ref msg) => Some(msg.req_id),
            Response::AccountUpdateMultiMsg(ref msg) => Some(msg.req_id),
            Response::AccountUpdateMultiEndMsg(ref msg) => Some(msg.req_id),
            Response::TickReqParamsMsg(ref msg) => Some(msg.req_id),
            Response::TickByTickAllLastMsg(ref msg) => Some(msg.req_id),
            Response::TickByTickBidAskMsg(ref msg) => Some(msg.req_id),
            Response::TickByTickMidPointMsg(ref msg) => Some(msg.req_id),
            Response::TickByTickNoneMsg(ref msg) => None,
            Response::SmartComponentsMsg(ref msg) => Some(msg.req_id),
        }
    }
}