Skip to main content

ibapi/contracts/
tick_types.rs

1use std::fmt;
2
3/// Market data tick types available from the TWS API.
4///
5/// These represent different types of market data that can be requested
6/// and received from Interactive Brokers. Each tick type corresponds to
7/// a specific piece of market information like bid, ask, last trade, volume, etc.
8#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
9#[derive(Debug, PartialEq, Default)]
10pub enum TickType {
11    /// Unknown or invalid tick type.
12    #[default]
13    Unknown = -1,
14    /// Number of contracts or shares offered at the bid price.
15    BidSize = 0,
16    /// Highest price a buyer is willing to pay.
17    Bid = 1,
18    /// Lowest price a seller is willing to accept.
19    Ask = 2,
20    /// Number of contracts or shares offered at the ask price.
21    AskSize = 3,
22    /// Price of the last trade.
23    Last = 4,
24    /// Number of contracts or shares traded in the last trade.
25    LastSize = 5,
26    /// Highest price of the day.
27    High = 6,
28    /// Lowest price of the day.
29    Low = 7,
30    /// Total trading volume for the day.
31    Volume = 8,
32    /// Previous day's closing price.
33    Close = 9,
34    /// Bid price for options.
35    BidOption = 10,
36    /// Ask price for options.
37    AskOption = 11,
38    /// Last traded price for options.
39    LastOption = 12,
40    /// Model-based option price.
41    ModelOption = 13,
42    /// Opening price of the day.
43    Open = 14,
44    /// Lowest price in the last 13 weeks.
45    Low13Week = 15,
46    /// Highest price in the last 13 weeks.
47    High13Week = 16,
48    /// Lowest price in the last 26 weeks.
49    Low26Week = 17,
50    /// Highest price in the last 26 weeks.
51    High26Week = 18,
52    /// Lowest price in the last 52 weeks.
53    Low52Week = 19,
54    /// Highest price in the last 52 weeks.
55    High52Week = 20,
56    /// Average daily trading volume.
57    AvgVolume = 21,
58    /// Total number of outstanding contracts.
59    OpenInterest = 22,
60    /// Historical volatility for options.
61    OptionHistoricalVol = 23,
62    /// Implied volatility for options.
63    OptionImpliedVol = 24,
64    /// Exchange code from which the option bid quote originated.
65    OptionBidExch = 25,
66    /// Exchange code from which the option ask quote originated.
67    OptionAskExch = 26,
68    /// Current open interest for call options.
69    OptionCallOpenInterest = 27,
70    /// Current open interest for put options.
71    OptionPutOpenInterest = 28,
72    /// Trading volume for call options.
73    OptionCallVolume = 29,
74    /// Trading volume for put options.
75    OptionPutVolume = 30,
76    /// Premium of the index future over fair value.
77    IndexFuturePremium = 31,
78    /// Exchange code supplying the top-of-book bid.
79    BidExch = 32,
80    /// Exchange code supplying the top-of-book ask.
81    AskExch = 33,
82    /// Shares/contracts offered during the auction.
83    AuctionVolume = 34,
84    /// Indicative auction clearing price.
85    AuctionPrice = 35,
86    /// Imbalance between buy and sell interest in the auction.
87    AuctionImbalance = 36,
88    /// Mark price (used for margining in futures).
89    MarkPrice = 37,
90    /// Bid-side exchange for EFP (Exchange for Physical) computations.
91    BidEfpComputation = 38,
92    /// Ask-side exchange for EFP computations.
93    AskEfpComputation = 39,
94    /// Last trade exchange for EFP computations.
95    LastEfpComputation = 40,
96    /// Opening price exchange for EFP computations.
97    OpenEfpComputation = 41,
98    /// High price exchange for EFP computations.
99    HighEfpComputation = 42,
100    /// Low price exchange for EFP computations.
101    LowEfpComputation = 43,
102    /// Closing price exchange for EFP computations.
103    CloseEfpComputation = 44,
104    /// Timestamp (epoch seconds) for the last tick.
105    LastTimestamp = 45,
106    /// Number of shares available for shorting.
107    Shortable = 46,
108    /// Fundamental ratios snapshot (PE, EPS, etc.).
109    FundamentalRatios = 47,
110    /// Real-time consolidated volume message.
111    RtVolume = 48,
112    /// Indicates if trading is halted (0 = not halted, 1 = halted).
113    Halted = 49,
114    /// Yield computed from the bid price (fixed income).
115    BidYield = 50,
116    /// Yield computed from the ask price (fixed income).
117    AskYield = 51,
118    /// Yield of the last trade (fixed income).
119    LastYield = 52,
120    /// Custom option computation values supplied by IB.
121    CustOptionComputation = 53,
122    /// Number of trades over the reporting interval.
123    TradeCount = 54,
124    /// Trades per minute over the interval.
125    TradeRate = 55,
126    /// Volume per minute over the interval.
127    VolumeRate = 56,
128    /// Last regular trading hours trade details.
129    LastRthTrade = 57,
130    /// Real-time historical volatility value.
131    RtHistoricalVol = 58,
132    /// Projected dividend information.
133    IbDividends = 59,
134    /// Factor multiplier used for bonds.
135    BondFactorMultiplier = 60,
136    /// Regulatory imbalance indicator from exchanges.
137    RegulatoryImbalance = 61,
138    /// Exchange-issued news headline.
139    NewsTick = 62,
140    /// Short-term volume averaged over 3 minutes.
141    ShortTermVolume3Min = 63,
142    /// Short-term volume averaged over 5 minutes.
143    ShortTermVolume5Min = 64,
144    /// Short-term volume averaged over 10 minutes.
145    ShortTermVolume10Min = 65,
146    /// Delayed bid price.
147    DelayedBid = 66,
148    /// Delayed ask price.
149    DelayedAsk = 67,
150    /// Delayed last traded price.
151    DelayedLast = 68,
152    /// Delayed bid size.
153    DelayedBidSize = 69,
154    /// Delayed ask size.
155    DelayedAskSize = 70,
156    /// Delayed last trade size.
157    DelayedLastSize = 71,
158    /// Delayed session high.
159    DelayedHigh = 72,
160    /// Delayed session low.
161    DelayedLow = 73,
162    /// Delayed volume.
163    DelayedVolume = 74,
164    /// Delayed session close.
165    DelayedClose = 75,
166    /// Delayed session open.
167    DelayedOpen = 76,
168    /// Real-time trade volume (aggregate).
169    RtTrdVolume = 77,
170    /// Credit manager mark price.
171    CreditmanMarkPrice = 78,
172    /// Credit manager slow mark price.
173    CreditmanSlowMarkPrice = 79,
174    /// Delayed option bid computation.
175    DelayedBidOption = 80,
176    /// Delayed option ask computation.
177    DelayedAskOption = 81,
178    /// Delayed option last computation.
179    DelayedLastOption = 82,
180    /// Delayed option model price.
181    DelayedModelOption = 83,
182    /// Exchange code for the last trade.
183    LastExch = 84,
184    /// Time of the last regular trade.
185    LastRegTime = 85,
186    /// Open interest for futures contracts.
187    FuturesOpenInterest = 86,
188    /// Average option volume over 90 days.
189    AvgOptVolume = 87,
190    /// Timestamp associated with delayed last price.
191    DelayedLastTimestamp = 88,
192    /// Number of shares available to short.
193    ShortableShares = 89,
194    /// Delayed trading halt status.
195    DelayedHalted = 90,
196    /// Reuters mutual fund indicative value.
197    Reuters2MutualFunds = 91,
198    /// ETF net asset value (NAV) close.
199    EtfNavClose = 92,
200    /// Prior day ETF NAV close.
201    EtfNavPriorClose = 93,
202    /// ETF NAV bid.
203    EtfNavBid = 94,
204    /// ETF NAV ask.
205    EtfNavAsk = 95,
206    /// ETF NAV last.
207    EtfNavLast = 96,
208    /// Frozen ETF NAV last value.
209    EtfFrozenNavLast = 97,
210    /// Intraday high estimate for ETF NAV.
211    EtfNavHigh = 98,
212    /// Intraday low estimate for ETF NAV.
213    EtfNavLow = 99,
214    /// Social market analytics sentiment score.
215    SocialMarketAnalytics = 100,
216    /// Estimated midpoint for an IPO.
217    EstimatedIpoMidpoint = 101,
218    /// Final pricing for an IPO.
219    FinalIpoLast = 102,
220    /// Delayed bid yield.
221    DelayedYieldBid = 103,
222    /// Delayed ask yield.
223    DelayedYieldAsk = 104,
224}
225
226impl From<i32> for TickType {
227    fn from(value: i32) -> Self {
228        match value {
229            -1 => Self::Unknown,
230            0 => Self::BidSize,
231            1 => Self::Bid,
232            2 => Self::Ask,
233            3 => Self::AskSize,
234            4 => Self::Last,
235            5 => Self::LastSize,
236            6 => Self::High,
237            7 => Self::Low,
238            8 => Self::Volume,
239            9 => Self::Close,
240            10 => Self::BidOption,
241            11 => Self::AskOption,
242            12 => Self::LastOption,
243            13 => Self::ModelOption,
244            14 => Self::Open,
245            15 => Self::Low13Week,
246            16 => Self::High13Week,
247            17 => Self::Low26Week,
248            18 => Self::High26Week,
249            19 => Self::Low52Week,
250            20 => Self::High52Week,
251            21 => Self::AvgVolume,
252            22 => Self::OpenInterest,
253            23 => Self::OptionHistoricalVol,
254            24 => Self::OptionImpliedVol,
255            25 => Self::OptionBidExch,
256            26 => Self::OptionAskExch,
257            27 => Self::OptionCallOpenInterest,
258            28 => Self::OptionPutOpenInterest,
259            29 => Self::OptionCallVolume,
260            30 => Self::OptionPutVolume,
261            31 => Self::IndexFuturePremium,
262            32 => Self::BidExch,
263            33 => Self::AskExch,
264            34 => Self::AuctionVolume,
265            35 => Self::AuctionPrice,
266            36 => Self::AuctionImbalance,
267            37 => Self::MarkPrice,
268            38 => Self::BidEfpComputation,
269            39 => Self::AskEfpComputation,
270            40 => Self::LastEfpComputation,
271            41 => Self::OpenEfpComputation,
272            42 => Self::HighEfpComputation,
273            43 => Self::LowEfpComputation,
274            44 => Self::CloseEfpComputation,
275            45 => Self::LastTimestamp,
276            46 => Self::Shortable,
277            47 => Self::FundamentalRatios,
278            48 => Self::RtVolume,
279            49 => Self::Halted,
280            50 => Self::BidYield,
281            51 => Self::AskYield,
282            52 => Self::LastYield,
283            53 => Self::CustOptionComputation,
284            54 => Self::TradeCount,
285            55 => Self::TradeRate,
286            56 => Self::VolumeRate,
287            57 => Self::LastRthTrade,
288            58 => Self::RtHistoricalVol,
289            59 => Self::IbDividends,
290            60 => Self::BondFactorMultiplier,
291            61 => Self::RegulatoryImbalance,
292            62 => Self::NewsTick,
293            63 => Self::ShortTermVolume3Min,
294            64 => Self::ShortTermVolume5Min,
295            65 => Self::ShortTermVolume10Min,
296            66 => Self::DelayedBid,
297            67 => Self::DelayedAsk,
298            68 => Self::DelayedLast,
299            69 => Self::DelayedBidSize,
300            70 => Self::DelayedAskSize,
301            71 => Self::DelayedLastSize,
302            72 => Self::DelayedHigh,
303            73 => Self::DelayedLow,
304            74 => Self::DelayedVolume,
305            75 => Self::DelayedClose,
306            76 => Self::DelayedOpen,
307            77 => Self::RtTrdVolume,
308            78 => Self::CreditmanMarkPrice,
309            79 => Self::CreditmanSlowMarkPrice,
310            80 => Self::DelayedBidOption,
311            81 => Self::DelayedAskOption,
312            82 => Self::DelayedLastOption,
313            83 => Self::DelayedModelOption,
314            84 => Self::LastExch,
315            85 => Self::LastRegTime,
316            86 => Self::FuturesOpenInterest,
317            87 => Self::AvgOptVolume,
318            88 => Self::DelayedLastTimestamp,
319            89 => Self::ShortableShares,
320            90 => Self::DelayedHalted,
321            91 => Self::Reuters2MutualFunds,
322            92 => Self::EtfNavClose,
323            93 => Self::EtfNavPriorClose,
324            94 => Self::EtfNavBid,
325            95 => Self::EtfNavAsk,
326            96 => Self::EtfNavLast,
327            97 => Self::EtfFrozenNavLast,
328            98 => Self::EtfNavHigh,
329            99 => Self::EtfNavLow,
330            100 => Self::SocialMarketAnalytics,
331            101 => Self::EstimatedIpoMidpoint,
332            102 => Self::FinalIpoLast,
333            103 => Self::DelayedYieldBid,
334            104 => Self::DelayedYieldAsk,
335            _ => Self::Unknown,
336        }
337    }
338}
339
340impl From<&str> for TickType {
341    fn from(value: &str) -> Self {
342        match value {
343            "bidSize" => Self::BidSize,
344            "bidPrice" => Self::Bid,
345            "askPrice" => Self::Ask,
346            "askSize" => Self::AskSize,
347            "lastPrice" => Self::Last,
348            "lastSize" => Self::LastSize,
349            "high" => Self::High,
350            "low" => Self::Low,
351            "volume" => Self::Volume,
352            "close" => Self::Close,
353            "bidOptComp" => Self::BidOption,
354            "askOptComp" => Self::AskOption,
355            "lastOptComp" => Self::LastOption,
356            "modelOptComp" => Self::ModelOption,
357            "open" => Self::Open,
358            "13WeekLow" => Self::Low13Week,
359            "13WeekHigh" => Self::High13Week,
360            "26WeekLow" => Self::Low26Week,
361            "26WeekHigh" => Self::High26Week,
362            "52WeekLow" => Self::Low52Week,
363            "52WeekHigh" => Self::High52Week,
364            "AvgVolume" => Self::AvgVolume,
365            "OpenInterest" => Self::OpenInterest,
366            "OptionHistoricalVolatility" => Self::OptionHistoricalVol,
367            "OptionImpliedVolatility" => Self::OptionImpliedVol,
368            "OptionBidExchStr" => Self::OptionBidExch,
369            "OptionAskExchStr" => Self::OptionAskExch,
370            "OptionCallOpenInterest" => Self::OptionCallOpenInterest,
371            "OptionPutOpenInterest" => Self::OptionPutOpenInterest,
372            "OptionCallVolume" => Self::OptionCallVolume,
373            "OptionPutVolume" => Self::OptionPutVolume,
374            "IndexFuturePremium" => Self::IndexFuturePremium,
375            "bidExch" => Self::BidExch,
376            "askExch" => Self::AskExch,
377            "auctionVolume" => Self::AuctionVolume,
378            "auctionPrice" => Self::AuctionPrice,
379            "auctionImbalance" => Self::AuctionImbalance,
380            "markPrice" => Self::MarkPrice,
381            "bidEFP" => Self::BidEfpComputation,
382            "askEFP" => Self::AskEfpComputation,
383            "lastEFP" => Self::LastEfpComputation,
384            "openEFP" => Self::OpenEfpComputation,
385            "highEFP" => Self::HighEfpComputation,
386            "lowEFP" => Self::LowEfpComputation,
387            "closeEFP" => Self::CloseEfpComputation,
388            "lastTimestamp" => Self::LastTimestamp,
389            "shortable" => Self::Shortable,
390            "fundamentals" => Self::FundamentalRatios,
391            "RTVolume" => Self::RtVolume,
392            "halted" => Self::Halted,
393            "bidYield" => Self::BidYield,
394            "askYield" => Self::AskYield,
395            "lastYield" => Self::LastYield,
396            "custOptComp" => Self::CustOptionComputation,
397            "trades" => Self::TradeCount,
398            "trades/min" => Self::TradeRate,
399            "volume/min" => Self::VolumeRate,
400            "lastRTHTrade" => Self::LastRthTrade,
401            "RTHistoricalVol" => Self::RtHistoricalVol,
402            "IBDividends" => Self::IbDividends,
403            "bondFactorMultiplier" => Self::BondFactorMultiplier,
404            "regulatoryImbalance" => Self::RegulatoryImbalance,
405            "newsTick" => Self::NewsTick,
406            "shortTermVolume3Min" => Self::ShortTermVolume3Min,
407            "shortTermVolume5Min" => Self::ShortTermVolume5Min,
408            "shortTermVolume10Min" => Self::ShortTermVolume10Min,
409            "delayedBid" => Self::DelayedBid,
410            "delayedAsk" => Self::DelayedAsk,
411            "delayedLast" => Self::DelayedLast,
412            "delayedBidSize" => Self::DelayedBidSize,
413            "delayedAskSize" => Self::DelayedAskSize,
414            "delayedLastSize" => Self::DelayedLastSize,
415            "delayedHigh" => Self::DelayedHigh,
416            "delayedLow" => Self::DelayedLow,
417            "delayedVolume" => Self::DelayedVolume,
418            "delayedClose" => Self::DelayedClose,
419            "delayedOpen" => Self::DelayedOpen,
420            "rtTrdVolume" => Self::RtTrdVolume,
421            "creditmanMarkPrice" => Self::CreditmanMarkPrice,
422            "creditmanSlowMarkPrice" => Self::CreditmanSlowMarkPrice,
423            "delayedBidOptComp" => Self::DelayedBidOption,
424            "delayedAskOptComp" => Self::DelayedAskOption,
425            "delayedLastOptComp" => Self::DelayedLastOption,
426            "delayedModelOptComp" => Self::DelayedModelOption,
427            "lastExchange" => Self::LastExch,
428            "lastRegTime" => Self::LastRegTime,
429            "futuresOpenInterest" => Self::FuturesOpenInterest,
430            "avgOptVolume" => Self::AvgOptVolume,
431            "delayedLastTimestamp" => Self::DelayedLastTimestamp,
432            "shortableShares" => Self::ShortableShares,
433            "delayedHalted" => Self::DelayedHalted,
434            "reuters2MutualFunds" => Self::Reuters2MutualFunds,
435            "etfNavClose" => Self::EtfNavClose,
436            "etfNavPriorClose" => Self::EtfNavPriorClose,
437            "etfNavBid" => Self::EtfNavBid,
438            "etfNavAsk" => Self::EtfNavAsk,
439            "etfNavLast" => Self::EtfNavLast,
440            "etfFrozenNavLast" => Self::EtfFrozenNavLast,
441            "etfNavHigh" => Self::EtfNavHigh,
442            "etfNavLow" => Self::EtfNavLow,
443            "socialMarketAnalytics" => Self::SocialMarketAnalytics,
444            "estimatedIPOMidpoint" => Self::EstimatedIpoMidpoint,
445            "finalIPOLast" => Self::FinalIpoLast,
446            "delayedYieldBid" => Self::DelayedYieldBid,
447            "delayedYieldAsk" => Self::DelayedYieldAsk,
448            _ => Self::Unknown,
449        }
450    }
451}
452
453impl fmt::Display for TickType {
454    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
455        match self {
456            Self::Unknown => write!(f, "Unknown"),
457            Self::BidSize => write!(f, "Bid Size"),
458            Self::Bid => write!(f, "Bid"),
459            Self::Ask => write!(f, "Ask"),
460            Self::AskSize => write!(f, "Ask Size"),
461            Self::Last => write!(f, "Last"),
462            Self::LastSize => write!(f, "Last Size"),
463            Self::High => write!(f, "High"),
464            Self::Low => write!(f, "Low"),
465            Self::Volume => write!(f, "Volume"),
466            Self::Close => write!(f, "Close"),
467            Self::BidOption => write!(f, "Bid Option"),
468            Self::AskOption => write!(f, "Ask Option"),
469            Self::LastOption => write!(f, "Last Option"),
470            Self::ModelOption => write!(f, "Model Option"),
471            Self::Open => write!(f, "Open"),
472            Self::Low13Week => write!(f, "13 Week Low"),
473            Self::High13Week => write!(f, "13 Week High"),
474            Self::Low26Week => write!(f, "26 Week Low"),
475            Self::High26Week => write!(f, "26 Week High"),
476            Self::Low52Week => write!(f, "52 Week Low"),
477            Self::High52Week => write!(f, "52 Week High"),
478            Self::AvgVolume => write!(f, "Average Volume"),
479            Self::OpenInterest => write!(f, "Open Interest"),
480            Self::OptionHistoricalVol => write!(f, "Option Historical Volatility"),
481            Self::OptionImpliedVol => write!(f, "Option Implied Volatility"),
482            Self::OptionBidExch => write!(f, "Option Bid Exchange"),
483            Self::OptionAskExch => write!(f, "Option Ask Exchange"),
484            Self::OptionCallOpenInterest => write!(f, "Option Call Open Interest"),
485            Self::OptionPutOpenInterest => write!(f, "Option Put Open Interest"),
486            Self::OptionCallVolume => write!(f, "Option Call Volume"),
487            Self::OptionPutVolume => write!(f, "Option Put Volume"),
488            Self::IndexFuturePremium => write!(f, "Index Future Premium"),
489            Self::BidExch => write!(f, "Bid Exchange"),
490            Self::AskExch => write!(f, "Ask Exchange"),
491            Self::AuctionVolume => write!(f, "Auction Volume"),
492            Self::AuctionPrice => write!(f, "Auction Price"),
493            Self::AuctionImbalance => write!(f, "Auction Imbalance"),
494            Self::MarkPrice => write!(f, "Mark Price"),
495            Self::BidEfpComputation => write!(f, "Bid EFP Computation"),
496            Self::AskEfpComputation => write!(f, "Ask EFP Computation"),
497            Self::LastEfpComputation => write!(f, "Last EFP Computation"),
498            Self::OpenEfpComputation => write!(f, "Open EFP Computation"),
499            Self::HighEfpComputation => write!(f, "High EFP Computation"),
500            Self::LowEfpComputation => write!(f, "Low EFP Computation"),
501            Self::CloseEfpComputation => write!(f, "Close EFP Computation"),
502            Self::LastTimestamp => write!(f, "Last Timestamp"),
503            Self::Shortable => write!(f, "Shortable"),
504            Self::FundamentalRatios => write!(f, "Fundamental Ratios"),
505            Self::RtVolume => write!(f, "RT Volume"),
506            Self::Halted => write!(f, "Halted"),
507            Self::BidYield => write!(f, "Bid Yield"),
508            Self::AskYield => write!(f, "Ask Yield"),
509            Self::LastYield => write!(f, "Last Yield"),
510            Self::CustOptionComputation => write!(f, "Custom Option Computation"),
511            Self::TradeCount => write!(f, "Trade Count"),
512            Self::TradeRate => write!(f, "Trade Rate"),
513            Self::VolumeRate => write!(f, "Volume Rate"),
514            Self::LastRthTrade => write!(f, "Last RTH Trade"),
515            Self::RtHistoricalVol => write!(f, "RT Historical Volatility"),
516            Self::IbDividends => write!(f, "IB Dividends"),
517            Self::BondFactorMultiplier => write!(f, "Bond Factor Multiplier"),
518            Self::RegulatoryImbalance => write!(f, "Regulatory Imbalance"),
519            Self::NewsTick => write!(f, "News Tick"),
520            Self::ShortTermVolume3Min => write!(f, "Short Term Volume 3 Min"),
521            Self::ShortTermVolume5Min => write!(f, "Short Term Volume 5 Min"),
522            Self::ShortTermVolume10Min => write!(f, "Short Term Volume 10 Min"),
523            Self::DelayedBid => write!(f, "Delayed Bid"),
524            Self::DelayedAsk => write!(f, "Delayed Ask"),
525            Self::DelayedLast => write!(f, "Delayed Last"),
526            Self::DelayedBidSize => write!(f, "Delayed Bid Size"),
527            Self::DelayedAskSize => write!(f, "Delayed Ask Size"),
528            Self::DelayedLastSize => write!(f, "Delayed Last Size"),
529            Self::DelayedHigh => write!(f, "Delayed High"),
530            Self::DelayedLow => write!(f, "Delayed Low"),
531            Self::DelayedVolume => write!(f, "Delayed Volume"),
532            Self::DelayedClose => write!(f, "Delayed Close"),
533            Self::DelayedOpen => write!(f, "Delayed Open"),
534            Self::RtTrdVolume => write!(f, "RT Trade Volume"),
535            Self::CreditmanMarkPrice => write!(f, "Creditman Mark Price"),
536            Self::CreditmanSlowMarkPrice => write!(f, "Creditman Slow Mark Price"),
537            Self::DelayedBidOption => write!(f, "Delayed Bid Option"),
538            Self::DelayedAskOption => write!(f, "Delayed Ask Option"),
539            Self::DelayedLastOption => write!(f, "Delayed Last Option"),
540            Self::DelayedModelOption => write!(f, "Delayed Model Option"),
541            Self::LastExch => write!(f, "Last Exchange"),
542            Self::LastRegTime => write!(f, "Last Reg Time"),
543            Self::FuturesOpenInterest => write!(f, "Futures Open Interest"),
544            Self::AvgOptVolume => write!(f, "Average Option Volume"),
545            Self::DelayedLastTimestamp => write!(f, "Delayed Last Timestamp"),
546            Self::ShortableShares => write!(f, "Shortable Shares"),
547            Self::DelayedHalted => write!(f, "Delayed Halted"),
548            Self::Reuters2MutualFunds => write!(f, "Reuters2 Mutual Funds"),
549            Self::EtfNavClose => write!(f, "ETF NAV Close"),
550            Self::EtfNavPriorClose => write!(f, "ETF NAV Prior Close"),
551            Self::EtfNavBid => write!(f, "ETF NAV Bid"),
552            Self::EtfNavAsk => write!(f, "ETF NAV Ask"),
553            Self::EtfNavLast => write!(f, "ETF NAV Last"),
554            Self::EtfFrozenNavLast => write!(f, "ETF Frozen NAV Last"),
555            Self::EtfNavHigh => write!(f, "ETF NAV High"),
556            Self::EtfNavLow => write!(f, "ETF NAV Low"),
557            Self::SocialMarketAnalytics => write!(f, "Social Market Analytics"),
558            Self::EstimatedIpoMidpoint => write!(f, "Estimated IPO Midpoint"),
559            Self::FinalIpoLast => write!(f, "Final IPO Last"),
560            Self::DelayedYieldBid => write!(f, "Delayed Yield Bid"),
561            Self::DelayedYieldAsk => write!(f, "Delayed Yield Ask"),
562        }
563    }
564}
565
566#[cfg(test)]
567mod test {
568    #[cfg(test)]
569    use super::*;
570
571    #[test]
572    fn test_from_i32_all_values() {
573        let test_cases = vec![
574            (-1, TickType::Unknown),
575            (0, TickType::BidSize),
576            (1, TickType::Bid),
577            (2, TickType::Ask),
578            (3, TickType::AskSize),
579            (4, TickType::Last),
580            (5, TickType::LastSize),
581            (6, TickType::High),
582            (7, TickType::Low),
583            (8, TickType::Volume),
584            (9, TickType::Close),
585            (10, TickType::BidOption),
586            (11, TickType::AskOption),
587            (12, TickType::LastOption),
588            (13, TickType::ModelOption),
589            (14, TickType::Open),
590            (15, TickType::Low13Week),
591            (16, TickType::High13Week),
592            (17, TickType::Low26Week),
593            (18, TickType::High26Week),
594            (19, TickType::Low52Week),
595            (20, TickType::High52Week),
596            (21, TickType::AvgVolume),
597            (22, TickType::OpenInterest),
598            (23, TickType::OptionHistoricalVol),
599            (24, TickType::OptionImpliedVol),
600            (25, TickType::OptionBidExch),
601            (26, TickType::OptionAskExch),
602            (27, TickType::OptionCallOpenInterest),
603            (28, TickType::OptionPutOpenInterest),
604            (29, TickType::OptionCallVolume),
605            (30, TickType::OptionPutVolume),
606            (31, TickType::IndexFuturePremium),
607            (32, TickType::BidExch),
608            (33, TickType::AskExch),
609            (34, TickType::AuctionVolume),
610            (35, TickType::AuctionPrice),
611            (36, TickType::AuctionImbalance),
612            (37, TickType::MarkPrice),
613            (38, TickType::BidEfpComputation),
614            (39, TickType::AskEfpComputation),
615            (40, TickType::LastEfpComputation),
616            (41, TickType::OpenEfpComputation),
617            (42, TickType::HighEfpComputation),
618            (43, TickType::LowEfpComputation),
619            (44, TickType::CloseEfpComputation),
620            (45, TickType::LastTimestamp),
621            (46, TickType::Shortable),
622            (47, TickType::FundamentalRatios),
623            (48, TickType::RtVolume),
624            (49, TickType::Halted),
625            (50, TickType::BidYield),
626            (51, TickType::AskYield),
627            (52, TickType::LastYield),
628            (53, TickType::CustOptionComputation),
629            (54, TickType::TradeCount),
630            (55, TickType::TradeRate),
631            (56, TickType::VolumeRate),
632            (57, TickType::LastRthTrade),
633            (58, TickType::RtHistoricalVol),
634            (59, TickType::IbDividends),
635            (60, TickType::BondFactorMultiplier),
636            (61, TickType::RegulatoryImbalance),
637            (62, TickType::NewsTick),
638            (63, TickType::ShortTermVolume3Min),
639            (64, TickType::ShortTermVolume5Min),
640            (65, TickType::ShortTermVolume10Min),
641            (66, TickType::DelayedBid),
642            (67, TickType::DelayedAsk),
643            (68, TickType::DelayedLast),
644            (69, TickType::DelayedBidSize),
645            (70, TickType::DelayedAskSize),
646            (71, TickType::DelayedLastSize),
647            (72, TickType::DelayedHigh),
648            (73, TickType::DelayedLow),
649            (74, TickType::DelayedVolume),
650            (75, TickType::DelayedClose),
651            (76, TickType::DelayedOpen),
652            (77, TickType::RtTrdVolume),
653            (78, TickType::CreditmanMarkPrice),
654            (79, TickType::CreditmanSlowMarkPrice),
655            (80, TickType::DelayedBidOption),
656            (81, TickType::DelayedAskOption),
657            (82, TickType::DelayedLastOption),
658            (83, TickType::DelayedModelOption),
659            (84, TickType::LastExch),
660            (85, TickType::LastRegTime),
661            (86, TickType::FuturesOpenInterest),
662            (87, TickType::AvgOptVolume),
663            (88, TickType::DelayedLastTimestamp),
664            (89, TickType::ShortableShares),
665            (90, TickType::DelayedHalted),
666            (91, TickType::Reuters2MutualFunds),
667            (92, TickType::EtfNavClose),
668            (93, TickType::EtfNavPriorClose),
669            (94, TickType::EtfNavBid),
670            (95, TickType::EtfNavAsk),
671            (96, TickType::EtfNavLast),
672            (97, TickType::EtfFrozenNavLast),
673            (98, TickType::EtfNavHigh),
674            (99, TickType::EtfNavLow),
675            (100, TickType::SocialMarketAnalytics),
676            (101, TickType::EstimatedIpoMidpoint),
677            (102, TickType::FinalIpoLast),
678            (103, TickType::DelayedYieldBid),
679            (104, TickType::DelayedYieldAsk),
680            (105, TickType::Unknown),
681            (-2, TickType::Unknown),
682            (1000, TickType::Unknown),
683        ];
684
685        for (input, expected) in test_cases {
686            assert_eq!(TickType::from(input), expected, "Failed for input: {}", input);
687        }
688    }
689
690    #[test]
691    fn test_from_str_all_values() {
692        let test_cases = vec![
693            ("bidSize", TickType::BidSize),
694            ("bidPrice", TickType::Bid),
695            ("askPrice", TickType::Ask),
696            ("askSize", TickType::AskSize),
697            ("lastPrice", TickType::Last),
698            ("lastSize", TickType::LastSize),
699            ("high", TickType::High),
700            ("low", TickType::Low),
701            ("volume", TickType::Volume),
702            ("close", TickType::Close),
703            ("bidOptComp", TickType::BidOption),
704            ("askOptComp", TickType::AskOption),
705            ("lastOptComp", TickType::LastOption),
706            ("modelOptComp", TickType::ModelOption),
707            ("open", TickType::Open),
708            ("13WeekLow", TickType::Low13Week),
709            ("13WeekHigh", TickType::High13Week),
710            ("26WeekLow", TickType::Low26Week),
711            ("26WeekHigh", TickType::High26Week),
712            ("52WeekLow", TickType::Low52Week),
713            ("52WeekHigh", TickType::High52Week),
714            ("AvgVolume", TickType::AvgVolume),
715            ("OpenInterest", TickType::OpenInterest),
716            ("OptionHistoricalVolatility", TickType::OptionHistoricalVol),
717            ("OptionImpliedVolatility", TickType::OptionImpliedVol),
718            ("OptionBidExchStr", TickType::OptionBidExch),
719            ("OptionAskExchStr", TickType::OptionAskExch),
720            ("OptionCallOpenInterest", TickType::OptionCallOpenInterest),
721            ("OptionPutOpenInterest", TickType::OptionPutOpenInterest),
722            ("OptionCallVolume", TickType::OptionCallVolume),
723            ("OptionPutVolume", TickType::OptionPutVolume),
724            ("IndexFuturePremium", TickType::IndexFuturePremium),
725            ("bidExch", TickType::BidExch),
726            ("askExch", TickType::AskExch),
727            ("auctionVolume", TickType::AuctionVolume),
728            ("auctionPrice", TickType::AuctionPrice),
729            ("auctionImbalance", TickType::AuctionImbalance),
730            ("markPrice", TickType::MarkPrice),
731            ("bidEFP", TickType::BidEfpComputation),
732            ("askEFP", TickType::AskEfpComputation),
733            ("lastEFP", TickType::LastEfpComputation),
734            ("openEFP", TickType::OpenEfpComputation),
735            ("highEFP", TickType::HighEfpComputation),
736            ("lowEFP", TickType::LowEfpComputation),
737            ("closeEFP", TickType::CloseEfpComputation),
738            ("lastTimestamp", TickType::LastTimestamp),
739            ("shortable", TickType::Shortable),
740            ("fundamentals", TickType::FundamentalRatios),
741            ("RTVolume", TickType::RtVolume),
742            ("halted", TickType::Halted),
743            ("bidYield", TickType::BidYield),
744            ("askYield", TickType::AskYield),
745            ("lastYield", TickType::LastYield),
746            ("custOptComp", TickType::CustOptionComputation),
747            ("trades", TickType::TradeCount),
748            ("trades/min", TickType::TradeRate),
749            ("volume/min", TickType::VolumeRate),
750            ("lastRTHTrade", TickType::LastRthTrade),
751            ("RTHistoricalVol", TickType::RtHistoricalVol),
752            ("IBDividends", TickType::IbDividends),
753            ("bondFactorMultiplier", TickType::BondFactorMultiplier),
754            ("regulatoryImbalance", TickType::RegulatoryImbalance),
755            ("newsTick", TickType::NewsTick),
756            ("shortTermVolume3Min", TickType::ShortTermVolume3Min),
757            ("shortTermVolume5Min", TickType::ShortTermVolume5Min),
758            ("shortTermVolume10Min", TickType::ShortTermVolume10Min),
759            ("delayedBid", TickType::DelayedBid),
760            ("delayedAsk", TickType::DelayedAsk),
761            ("delayedLast", TickType::DelayedLast),
762            ("delayedBidSize", TickType::DelayedBidSize),
763            ("delayedAskSize", TickType::DelayedAskSize),
764            ("delayedLastSize", TickType::DelayedLastSize),
765            ("delayedHigh", TickType::DelayedHigh),
766            ("delayedLow", TickType::DelayedLow),
767            ("delayedVolume", TickType::DelayedVolume),
768            ("delayedClose", TickType::DelayedClose),
769            ("delayedOpen", TickType::DelayedOpen),
770            ("rtTrdVolume", TickType::RtTrdVolume),
771            ("creditmanMarkPrice", TickType::CreditmanMarkPrice),
772            ("creditmanSlowMarkPrice", TickType::CreditmanSlowMarkPrice),
773            ("delayedBidOptComp", TickType::DelayedBidOption),
774            ("delayedAskOptComp", TickType::DelayedAskOption),
775            ("delayedLastOptComp", TickType::DelayedLastOption),
776            ("delayedModelOptComp", TickType::DelayedModelOption),
777            ("lastExchange", TickType::LastExch),
778            ("lastRegTime", TickType::LastRegTime),
779            ("futuresOpenInterest", TickType::FuturesOpenInterest),
780            ("avgOptVolume", TickType::AvgOptVolume),
781            ("delayedLastTimestamp", TickType::DelayedLastTimestamp),
782            ("shortableShares", TickType::ShortableShares),
783            ("delayedHalted", TickType::DelayedHalted),
784            ("reuters2MutualFunds", TickType::Reuters2MutualFunds),
785            ("etfNavClose", TickType::EtfNavClose),
786            ("etfNavPriorClose", TickType::EtfNavPriorClose),
787            ("etfNavBid", TickType::EtfNavBid),
788            ("etfNavAsk", TickType::EtfNavAsk),
789            ("etfNavLast", TickType::EtfNavLast),
790            ("etfFrozenNavLast", TickType::EtfFrozenNavLast),
791            ("etfNavHigh", TickType::EtfNavHigh),
792            ("etfNavLow", TickType::EtfNavLow),
793            ("socialMarketAnalytics", TickType::SocialMarketAnalytics),
794            ("estimatedIPOMidpoint", TickType::EstimatedIpoMidpoint),
795            ("finalIPOLast", TickType::FinalIpoLast),
796            ("delayedYieldBid", TickType::DelayedYieldBid),
797            ("delayedYieldAsk", TickType::DelayedYieldAsk),
798            ("nonexistent", TickType::Unknown),
799            ("", TickType::Unknown),
800            ("  ", TickType::Unknown),
801            ("BIDSIZE", TickType::Unknown),
802            ("BidSize", TickType::Unknown),
803        ];
804
805        for (input, expected) in test_cases {
806            assert_eq!(TickType::from(input), expected, "Failed for input: {}", input);
807        }
808    }
809
810    #[test]
811    fn test_default() {
812        assert_eq!(TickType::default(), TickType::Unknown);
813    }
814
815    #[test]
816    fn test_debug_output() {
817        assert_eq!(format!("{:?}", TickType::Bid), "Bid");
818        assert_eq!(format!("{:?}", TickType::AskSize), "AskSize");
819        assert_eq!(format!("{:?}", TickType::DelayedYieldAsk), "DelayedYieldAsk");
820    }
821
822    #[test]
823    fn test_partial_eq() {
824        assert_eq!(TickType::Last, TickType::Last);
825        assert_ne!(TickType::High, TickType::Low);
826    }
827
828    #[test]
829    fn test_edge_cases() {
830        // Test the lowest and highest defined values
831        assert_eq!(TickType::from(0), TickType::BidSize);
832        assert_eq!(TickType::from(104), TickType::DelayedYieldAsk);
833
834        // Test values just outside the defined range
835        assert_eq!(TickType::from(-2), TickType::Unknown);
836        assert_eq!(TickType::from(105), TickType::Unknown);
837
838        // Test with empty string and whitespace
839        assert_eq!(TickType::from(""), TickType::Unknown);
840        assert_eq!(TickType::from("  "), TickType::Unknown);
841    }
842
843    #[test]
844    fn test_case_sensitivity() {
845        assert_eq!(TickType::from("BIDSIZE"), TickType::Unknown);
846        assert_eq!(TickType::from("bidSize"), TickType::BidSize);
847        assert_eq!(TickType::from("BidSize"), TickType::Unknown);
848    }
849
850    #[test]
851    fn test_display_output() {
852        assert_eq!(format!("{}", TickType::Bid), "Bid");
853        assert_eq!(format!("{}", TickType::AskSize), "Ask Size");
854        assert_eq!(format!("{}", TickType::Last), "Last");
855        assert_eq!(format!("{}", TickType::Volume), "Volume");
856        assert_eq!(format!("{}", TickType::DelayedYieldAsk), "Delayed Yield Ask");
857        assert_eq!(format!("{}", TickType::Unknown), "Unknown");
858        assert_eq!(format!("{}", TickType::OptionImpliedVol), "Option Implied Volatility");
859        assert_eq!(format!("{}", TickType::ShortableShares), "Shortable Shares");
860    }
861}