use nom::number::streaming::be_u32;
use nsdq_util::{
define_enum,
parse_bool,
parse_ternary,
StockSymbol,
NaiveTime,
parse_itch_time_bold,
Price,
Mpid,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct StockDirectory {
pub stock: StockSymbol,
pub market_category: MarketCategory,
pub financial_status: FinancialStatus,
pub round_lot_size: u32,
pub round_lots_only: bool,
pub class: IssueClassification,
pub subtype: IssueSubType,
pub authenticity: Authenticity,
pub short_sale_threshold: Option<bool>,
pub ipo_flag: Option<bool>,
pub luld_tier: LuldTier,
pub etp_flag: Option<bool>,
pub etp_leverage_factor: u32,
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.",
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TradingAction {
pub stock: StockSymbol,
pub state: TradingState,
pub reserved: char, 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)",
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RegShoRestriction {
pub stock: StockSymbol,
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.",
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MarketParticipantPosition {
pub mpid: Mpid,
pub stock: StockSymbol,
pub is_primary: bool,
pub mode: MarketMakerMode,
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",
}
#[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 }))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MwcbStatus {
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",
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct QuotingPeriodUpdate {
pub release_time: NaiveTime,
pub qualifier: IpoQuotationReleaseQualifier,
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.",
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct LuldAuctionCollar {
pub stock: StockSymbol,
pub reference_price: Price<u32, 4>,
pub upper_price: Price<u32, 4>,
pub lower_price: Price<u32, 4>,
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
}))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct OperationalHalt {
pub stock: StockSymbol,
pub market: MarketCode,
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.",
}