litch 0.0.1

Simple parser for ITCH 5.0, oriented toward live messages.
Documentation
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

use nom::number::streaming::be_u32;
use nsdq_util::{ 
    define_enum,
    parse_bool,
    parse_ternary,
    StockSymbol,
    NaiveTime,
    parse_itch_time_bold,
    Price,
    Mpid,
};

/// At the start of each trading day, Nasdaq disseminates stock directory 
/// messages for all active symbols in their execution system.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct StockDirectory {

    /// Security symbol for the issue in the NASDAQ execution system.
    pub stock: StockSymbol,

    /// Listing market or listing market tier for the issue.
    pub market_category: MarketCategory,

    /// Firm compliance with continued listing requirements.
    pub financial_status: FinancialStatus,

    /// Number of shares that represent a round lot for the issue.
    pub round_lot_size: u32,

    /// Indicates if Nasdaq system limits order entry for issue.
    pub round_lots_only: bool,

    /// Identifies the security class for the issue.
    pub class: IssueClassification,

    /// Security sub-type for the issue.
    pub subtype: IssueSubType,

    /// Denotes if an issue or quoting participant record is set-up in a 
    /// live/production, test, or demo state.
    /// Please note that firms should only show live issues and quoting
    /// participants on public quotation displays.
    pub authenticity: Authenticity,

    /// If `Some(true)`, the security is subject to mandatory close-out of 
    /// short sales under SEC Rule 203(b)(3).
    /// If `None`, the information is not available.
    pub short_sale_threshold: Option<bool>,

    /// This field is intended to help Nasdaq market participant firms comply 
    /// with FINRA Rule 5131(b).
    /// If `Some(true)`, the security is set up for IPO release. 
    /// If `None`, the information is not available.
    pub ipo_flag: Option<bool>,

    /// Indicates which Limit Up / Limit Down price band calculation parameter 
    /// is to be used for the instrument. 
    pub luld_tier: LuldTier,

    /// If `Some(true)`, the security is an exchange traded product (ETP).
    /// If `None`, the information is not available.
    pub etp_flag: Option<bool>,

    /// Tracks the integral relationship of the ETP to the underlying index.
    ///
    /// (Example: If the underlying Index increases by a value of 1 and
    /// the ETP’s Leverage factor is 3, indicates the ETF will
    /// increase/decrease (see Inverse) by 3.)
    ///
    /// Leverage Factor is rounded to the nearest integer below, 
    /// e.g., leverage factor 1 would represent leverage factors of 1 to 1.99.
    ///
    /// This field is used for LULD Tier I price band calculation purposes.
    pub etp_leverage_factor: u32,

    /// Direction of the relationship between the ETP and Underlying index.
    /// If `true`, ETP is an Inverse ETP.
    pub inverse: bool,
}

impl StockDirectory {

    pub(crate) fn parse(input: &[u8]) -> nom::IResult<&[u8], Self> {

        let (input, stock) = StockSymbol::parse(input)?;
        let (input, market_category) = MarketCategory::parse(input)?;
        let (input, financial_status) = FinancialStatus::parse(input)?;
        let (input, round_lot_size) = be_u32(input)?;
        let (input, round_lots_only) = parse_bool(input)?;
        let (input, class) = IssueClassification::parse(input)?;
        let (input, subtype) = IssueSubType::parse(input)?;
        let (input, authenticity) = Authenticity::parse(input)?;
        let (input, short_sale_threshold) = parse_ternary(input)?;
        let (input, ipo_flag) = parse_ternary(input)?;
        let (input, luld_tier) = LuldTier::parse(input)?;
        let (input, etp_flag) = parse_ternary(input)?;
        let (input, etp_leverage_factor) = be_u32(input)?;
        let (input, inverse) = parse_bool(input)?;

        Ok((input, Self { 
            stock,
            market_category,
            financial_status,
            round_lot_size,
            round_lots_only,
            class,
            subtype,
            authenticity,
            short_sale_threshold,
            ipo_flag,
            luld_tier,
            etp_flag,
            etp_leverage_factor,
            inverse,
        }))
    }

}

define_enum!{

    MarketCategory:
        "Listing market or listing market tier for the issue.";

    ['Q'] NasdaqGlobalSelectMarket
        "Nasdaq Global Select Market",
    ['G'] NasdaqGlobalMarket
        "Nasdaq Global Market",
    ['S'] NasdaqCapitalMarket
        "Nasdaq Capital Market",
    ['N'] Nyse
        "New York Stock Exchange (NYSE)",
    ['A'] NyseAmerican
        "NYSE American",
    ['P'] NyseArca
        "NYSE Arca",
    ['Z'] BatsZExchange
        "BATS Z Exchange",
    ['V'] InvestorsExchange
        "Investors’ Exchange, LLC",
    [' '] NotAvailable
        "Not available.",
}

define_enum!{

    FinancialStatus:
        "Status of firm compliance with Nasdaq continued listing requirements.";

    ['D'] Deficient
        "Deficient",
    ['E'] Delinquent
        "Delinquent",
    ['Q'] Bankrupt
        "Bankrupt",
    ['S'] Suspended
        "Suspended",
    ['G'] DeficientBankrupt
        "Deficient and bankrupt.",
    ['H'] DeficientDelinquent
        "Deficient and delinquent.",
    ['J'] DelinquentBankrupt
        "Delinquent and bankrupt.",
    ['K'] DeficientDelinquentBankrupt
        "Deficient, delinquent, and bankrupt.",
    ['C'] CreateRedeemSuspended
        "Creations and/or Redemptions Suspended for Exchange Traded Product.",
    ['N'] Compliant
        "Normal/default. Not delinquent, deficient, or bankrupt.",
    [' '] NotAvailable
        "Not available. Firms should refer to SIAC feeds for code if needed.",
}

define_enum! {

    IssueClassification:
        "Identifies the security class for the issue as assigned by Nasdaq.";

    ['A'] AmericanDepositaryShare
        "",
    ['B'] Bond
        "",
    ['C'] CommonStock
        "",
    ['F'] DepositoryReceipt
        "",
    ['I'] _144A
        "",
    ['L'] LimitedPartnership
        "",
    ['N'] Notes
        "",
    ['O'] OrdinaryShare
        "",
    ['P'] PreferredStock
        "",
    ['Q'] OtherSecurities
        "",
    ['R'] Right
        "",
    ['S'] SharesOfBeneficialInterest
        "",
    ['T'] ConvertibleDebenture
        "",
    ['U'] Unit
        "",
    ['V'] UnitsBenifInt
        "",
    ['W'] Warrant
        "",
}

define_enum!{

    IssueSubType [2usize] "Security sub-type for the issue.";

    [b"A "] PreferredTrustSecurities "",
    [b"AI"] AlphaIndexEtns "",
    [b"B "] IndexBasedDerivative "",
    [b"C "] CommonShares "",
    [b"CB"] CommodityBasedTrustShares "",
    [b"CF"] CommodityFuturesTrustShares "",
    [b"CL"] CommodityLinkedSecurities "",
    [b"CM"] CommodityIndexTrustShares "",
    [b"CO"] CollateralizedMortgageObligation "",
    [b"CT"] CurrencyTrustShares "",
    [b"CU"] CommodityCurrencyLinkedSecurities "",
    [b"CW"] CurrencyWarrants "",
    [b"D "] GlobalDepositaryShares "",
    [b"E "] EtfPortfolioDepositaryReceipt "",
    [b"EG"] EquityGoldShares "",
    [b"EI"] EtnEquityIndexLinkedSecurities "",
    [b"EM"] NextSharesExchangeTradedManagedFund "",
    [b"EN"] ExchangeTradedNotes "",
    [b"EU"] EquityUnits "",
    [b"F "] Holdrs "",
    [b"FI"] EtnFixedIncomeLinkedSecurities "",
    [b"FL"] EtnFuturesLinkedSecurities "",
    [b"G "] GlobalShares "",
    [b"I "] EtfIndexFundShares "",
    [b"IR"] InterestRate "",
    [b"IW"] IndexWarrant "",
    [b"IX"] IndexLinkedExchangeableNotes "",
    [b"J "] CorporateBackedTrustSecurity "",
    [b"L "] ContingentLitigationRight "",
    [b"LL"] LimitedLiabilityCompany  "",
    [b"M "] EquityBasedDerivative "",
    [b"MF"] ManagedFundShares "",
    [b"ML"] EtnMultiFactorIndexLinkedSecurities "",
    [b"MT"] ManagedTrustSecurities "",
    [b"N "] NyRegistryShares "",
    [b"O "] OpenEndedMutualFund "",
    [b"P "] PrivatelyHeldSecurity "",
    [b"PP"] PoisonPill "",
    [b"PU"] PartnershipUnits "",
    [b"Q "] ClosedEndFunds "",
    [b"R "] RegS "",
    [b"RC"] CommodityRedeemableCommodityLinkedSecurities "",
    [b"RF"] EtnRedeemableFuturesLinkedSecurities "",
    [b"RT"] Reit "",
    [b"RU"] CommodityRedeemableCurrencyLinkedSecurities "",
    [b"S "] Seed "",
    [b"SC"] SpotRateClosing "",
    [b"SI"] SpotRateIntraday "",
    [b"T "] TrackingStock "",
    [b"TC"] TrustCertificates "",
    [b"TU"] TrustUnits "",
    [b"U "] Portal "",
    [b"V "] ContingentValueRight "",
    [b"W "] TrustIssuedReceipts "",
    [b"WC"] WorldCurrencyOption "",
    [b"X "] Trust "",
    [b"Y "] Other "",
    [b"Z "] NotApplicable "",
}

define_enum!{

    Authenticity:
        "Denotes if an issue or quoting participant record is set-up in \
        Nasdaq systems in a live/production, test, or demo state. \
        NOTE: Firms should only show live issues and quoting \
        participants on public quotation displays.";

    ['P'] Production
        "Live/Production",
    ['T'] Test
        "Test only",
}

define_enum!{

    LuldTier:
        "Indicates which Limit Up / Limit Down price band calculation \
        parameter is to be used for the instrument. \
        Refer to LULD Rule for details.";

    ['1'] Tier1
        "Tier 1 NMS Stocks and select ETPs.",
    ['2'] Tier2
        "Tier 2 NMS Stocks.",
    [' '] NotAvailable
        "Not available.",
}


/// In the pre-market spin, Nasdaq will send out a Trading Action message 
/// with the `TradingState::Trading` for all listed securities that are eligible
/// for trading at the start of the system hours. 
///
/// If a security is absent from the pre-opening Trading Action spin, 
/// assume that the security is being treated as halted in the Nasdaq
/// platform at the start of the system hours.
///
/// During the day, Nasdaq will use the Trading Action message to relay changes 
/// in trading status for an individual security.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TradingAction {

    /// Issue that has been affected by the trading action.
    pub stock: StockSymbol,
    /// Current trading state of the stock.
    pub state: TradingState,
    /// Reserved. 
    pub reserved: char, // TBD: Unclear purpose
    /// Reason for the change in trading status.
    pub reason: TradingActionReason,
}

impl TradingAction {

    pub(crate) fn parse(input: &[u8]) -> nom::IResult<&[u8], Self> {

        let (input, stock) = StockSymbol::parse(input)?;
        let (input, state) = TradingState::parse(input)?;
        let (input, rsvd) = nom::bytes::complete::take(1usize)(input)?;
        let (input, reason) = TradingActionReason::parse(input)?;

        Ok((input, Self { 
            stock, 
            state, 
            reserved: rsvd[0] as char,
            reason,
        }))
    }

}

define_enum!{

    TradingState:
        "Current trading state of the stock.";

    ['H'] Halted 
        "Halted across all U.S. equity markets / SROs.",
    ['P'] Paused
        "Paused across all U.S. equity markets / SROs \
        (Nasdaq---listed securities only).",
    ['Q'] QuoteOnly
        "Quotation only period for cross-SRO halt or pause.",
    ['T'] Trading
        "Trading on NASDAQ.",
}

define_enum!{

    TradingActionReason [4usize] 
        "Nasdaq will send out a trading action message to inform its market \
        participants when the trading status of an issue changes. \
        For informational purposes, Nasdaq also attempts to provide the reason \
        for each trading action update.";

    [b"T1  "] HaltNewsPending "",
    [b"T2  "] HaltNewsDisseminated "",
    [b"T5  "] SingleSecurityTradingPause "",
    [b"T6  "] ExtraordinaryMarketActivity "",
    [b"T8  "] HaltEtf "",
    [b"T12 "] TradingHalted "For Information Requested by Listing Market",
    [b"H4  "] HaltNonCompliance "",
    [b"H9  "] HaltFilingsNotCurrent "",
    [b"H10 "] HaltSecTradingSuspension "",
    [b"H11 "] HaltRegulatoryConcern "",
    [b"O1  "] OperationsHalt "Contact Market Operations",
    [b"LUDP"] VolatilityPause "",
    [b"LUDS"] VolatilityPauseStraddleCondition "",
    [b"MWC1"] MwcbHalt1 "",
    [b"MWC2"] MwcbHalt2 "",
    [b"MWC3"] MwcbHalt3 "",
    [b"MWC0"] MwcbHaltRemainInEffect "",
    [b"IPO1"] IpoIssue "Not Yet Trading",
    [b"M1  "] CorporateAction "",
    [b"M2  "] QuotationNotAvailable "",
    [b"    "] ReasonNotAvailable "",
    [b"T3  "] NewsAndResumptionTimes "",
    [b"T7  "] SingleSecurityQuotationPause "Quotation Only Period",
    [b"R4  "] QualificationsResolved "Trading to resume",
    [b"R9  "] FilingResolved "Trading to resume",
    [b"C3  "] IssuerNewsNotForthcoming "Trading to resume",
    [b"C4  "] MaintenanceRequirementsMet "Qualifications Halt ended",
    [b"C9  "] FilingsMet "Qualifications Halt Concluded",
    [b"C11 "] TradeHaltConcludedByRegulator "Trades Resume",
    [b"MWCQ"] MwcbResumption "",
    [b"R1  "] NewIssueAvailable "",
    [b"R2  "] IssueAvailable "",
    [b"IPOQ"] IpoSecurityReleased "(Nasdaq Securities Only)",
    [b"IPOE"] IpoPositioningWindowExtension "(Nasdaq Only)",
}


/// Reg SHO Short Sale Price Test Restricted Indicator.
/// Pre-opening spin indicates the Rule 201 status for all active issues. 
/// Nasdaq also sends this message in the event of an intraday status change.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RegShoRestriction {

    /// Issue to be described
    pub stock: StockSymbol,
    /// Restriction status
    pub action: RegShoAction,
}

impl RegShoRestriction {

    pub(crate) fn parse(input: &[u8]) -> nom::IResult<&[u8], Self> {

        let (input, stock) = StockSymbol::parse(input)?;
        let (input, action) = RegShoAction::parse(input)?;

        Ok((input, Self { stock, action }))
    }

}

define_enum!{
    RegShoAction: 
        "Regulation SHO Short Sale Price Test Restriction status.";

    ['0'] NoPriceTest 
        "No price test in place.",
    ['1'] PriceDrop 
        "Restriction in effect due to an intra-day price drop in security.",
    ['2'] RemainInEffect 
        "Restriction remains in effect.",
}


/// Provides the position of each market participant registered in an issue.
/// Typically sent in the spin at the start of day.
/// During the day, this message will only be sent if Nasdaq Operations 
/// manually changes the status of a market participant firm in an issue.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MarketParticipantPosition {

    /// Identifies the market participant firm.
    pub mpid: Mpid,
    /// Identifies the issue the firm has a position in.
    pub stock: StockSymbol,
    /// If `true`, firm qualifies as a Primary Market Maker.
    pub is_primary: bool,
    /// Quoting participant’s registration status in relation to 
    /// SEC Rules 101 and 104 of Regulation M.
    pub mode: MarketMakerMode,
    /// Market participant’s current registration status in the issue.
    pub state: MarketParticipantState,

}

impl MarketParticipantPosition {

    pub(crate) fn parse(input: &[u8]) -> nom::IResult<&[u8], Self> {

        let (input, mpid) = Mpid::parse(input)?;
        let (input, stock) = StockSymbol::parse(input)?;
        let (input, is_primary) = parse_bool(input)?;
        let (input, mode) = MarketMakerMode::parse(input)?;
        let (input, state) = MarketParticipantState::parse(input)?;

        Ok((input, Self { mpid, stock, is_primary, mode, state }))
    }

}

define_enum!{

    MarketMakerMode:
        "Quoting participant’s registration status in relation to \
        SEC Rules 101 and 104 of Regulation M.";

    ['N'] Normal
        "Normal",
    ['P'] Passive
        "Passive",
    ['S'] Syndicate
        "Syndicate",
    ['R'] PreSyndicate
        "Pre-syndicate",
    ['L'] Penalty
        "Penalty",
}

define_enum!{

    MarketParticipantState:
        "Market participant’s current registration status in the issue.";

    ['A'] Active
        "Active",
    ['E'] Excused
        "Excused/Withdrawn",
    ['W'] Withdrawn
        "Withdrawn",
    ['S'] Suspended
        "Suspended",
    ['D'] Deleted
        "Deleted",
}


/// Market-wide Circuit Breaker (MWCB) levels for the current trading day.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MwcbDeclineLevel {

    pub level_1: Price<u64, 8>,
    pub level_2: Price<u64, 8>,
    pub level_3: Price<u64, 8>,
}

impl MwcbDeclineLevel {

    pub(crate) fn parse(input: &[u8]) -> nom::IResult<&[u8], Self> {

        let (input, level_1) = Price::<u64, 8>::parse(input)?;
        let (input, level_2) = Price::<u64, 8>::parse(input)?;
        let (input, level_3) = Price::<u64, 8>::parse(input)?;

        Ok((input, Self { level_1, level_2, level_3 }))
    }

}


/// Sent when a Market-wide Circuit Breaker (MWCB) level has been breached.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MwcbStatus {

    /// Denotes the MWCB Level that was breached.
    pub level: BreachedLevel
}

impl MwcbStatus {

    pub(crate) fn parse(input: &[u8]) -> nom::IResult<&[u8], Self> {

        let (input, level) = BreachedLevel::parse(input)?;
        Ok((input, Self { level }))
    }
}

define_enum!{

    BreachedLevel:
        "Denotes the MWCB Level that was breached.";

    ['1'] _1
        "Level 1",
    ['2'] _2
        "Level 2",
    ['3'] _3
        "Level 3",
}


/// Indicates the anticipated IPO quotation release time of a security.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct QuotingPeriodUpdate {

    /// Timestamp of future release.
    pub release_time: NaiveTime,
    /// Status of the pending IPO release.
    pub qualifier: IpoQuotationReleaseQualifier,
    /// Price of the IPO.
    pub ipo_price: Price<u32, 4>,
}

impl QuotingPeriodUpdate {

    pub(crate) fn parse(input: &[u8]) -> nom::IResult<&[u8], Self> {

        let (input, release_time) = parse_itch_time_bold(input)?;
        let (input, qualifier) = IpoQuotationReleaseQualifier::parse(input)?;
        let (input, ipo_price) = Price::<u32, 4>::parse(input)?;

        Ok((input, Self { 
            release_time,
            qualifier, 
            ipo_price,
        }))
    }

}

define_enum!{

    IpoQuotationReleaseQualifier:
        "Status of the pending IPO release";

    ['A'] Anticipated
        "Nasdaq Market Operations has entered the IPO instrument for release",
    ['C'] Canceled
        "Nasdaq Market Operations has canceled or postponed the IPO release.",
}


/// Auction collar thresholds within which a paused security can reopen 
/// following a Limit-Up/Limit-down (LULD) Trading Pause.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct LuldAuctionCollar {

    /// Security which was paused.
    pub stock: StockSymbol,
    /// Reference price used to set the Auction Collars.
    pub reference_price: Price<u32, 4>,
    /// Upper Auction Collar Threshold
    pub upper_price: Price<u32, 4>,
    /// Lower Auction Collar Threshold
    pub lower_price: Price<u32, 4>,
    /// Indicates the number of the extensions to the Reopening Auction.
    pub extension: u32,
}

impl LuldAuctionCollar {

    pub(crate) fn parse(input: &[u8]) -> nom::IResult<&[u8], Self> {

        let (input, stock) = StockSymbol::parse(input)?;
        let (input, reference_price) = Price::<u32, 4>::parse(input)?;
        let (input, upper_price) = Price::<u32, 4>::parse(input)?;
        let (input, lower_price) = Price::<u32, 4>::parse(input)?;
        let (input, extension) = be_u32(input)?;

        Ok((input, Self {
            stock,
            reference_price,
            upper_price,
            lower_price,
            extension
        }))
    }
}


/// Interruption of service on `stock` impacting only the designated `market`. 
///
/// These Halts differ from the `TradingAction` message types since an 
/// Operational Halt is specific to the exchange for which it is declared, 
/// and does not interrupt the identified instrument on any other marketplace.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct OperationalHalt {

    /// Instrument for which the halt was imposed.
    pub stock: StockSymbol,
    /// Exchange on which the stock is halted.
    pub market: MarketCode,
    /// Status of the halted market.
    pub action: HaltAction,
}

impl OperationalHalt {

    pub(crate) fn parse(input: &[u8]) -> nom::IResult<&[u8], Self> {

        let (input, stock) = StockSymbol::parse(input)?;
        let (input, market) = MarketCode::parse(input)?;
        let (input, action) = HaltAction::parse(input)?;

        Ok((input, Self { stock, market, action }))
    }
}

define_enum!{

    MarketCode:
        "Market being halted:";

    ['Q'] Nasdaq
        "NASDAQ",
    ['B'] Bx
        "BX",
    ['X'] Psx
        "PSX"
}

define_enum!{

    HaltAction:
        "Market halt status:";

    ['H'] Halted
        "Operationally Halted on the identified Market.",
    ['T'] Trading
        "Operational Halt has been lifted and Trading resumed.",
}