Skip to main content

rhood_core/models/
option.rs

1//! Options-related model types for the Robinhood API.
2//!
3//! Contains structs for option chains, option instruments, and option
4//! positions (calls and puts).
5
6use std::fmt;
7
8use serde::{Deserialize, Serialize};
9
10/// Type of option contract.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
12#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
13#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
14#[serde(rename_all = "lowercase")]
15pub enum OptionType {
16    /// A call option - the right to buy at the strike price.
17    Call,
18    /// A put option - the right to sell at the strike price.
19    Put,
20}
21
22impl fmt::Display for OptionType {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            Self::Call => write!(f, "call"),
26            Self::Put => write!(f, "put"),
27        }
28    }
29}
30
31/// Represents an options chain for an underlying stock symbol.
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct OptionChain {
34    /// Unique identifier for the option chain.
35    pub id: Option<String>,
36    /// Ticker symbol of the underlying stock.
37    pub symbol: Option<String>,
38    /// Indicates whether the user can open a new position in this chain.
39    pub can_open_position: Option<bool>,
40    /// Cash component of the option (for adjusted options).
41    pub cash_component: Option<String>,
42    /// Available expiration dates for this chain (YYYY-MM-DD).
43    pub expiration_dates: Option<Vec<String>>,
44    /// Contract multiplier applied to the trade value (typically "100.0000").
45    pub trade_value_multiplier: Option<String>,
46    /// Underlying instruments associated with this chain.
47    pub underlying_instruments: Option<Vec<serde_json::Value>>,
48    /// Minimum tick size configuration for the chain.
49    pub min_ticks: Option<serde_json::Value>,
50}
51
52/// Represents a specific option contract (call or put) at a given strike and expiration.
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct OptionInstrument {
55    /// Identifier for the parent option chain.
56    pub chain_id: Option<String>,
57    /// Ticker symbol of the underlying stock.
58    pub chain_symbol: Option<String>,
59    /// Timestamp when the instrument record was created.
60    pub created_at: Option<String>,
61    /// Expiration date of the contract (YYYY-MM-DD).
62    pub expiration_date: Option<String>,
63    /// Unique identifier for this option instrument.
64    pub id: Option<String>,
65    /// Date the option was issued.
66    pub issue_date: Option<String>,
67    /// Minimum tick size configuration for this instrument.
68    pub min_ticks: Option<serde_json::Value>,
69    /// Robinhood-specific tradability status.
70    pub rhs_tradability: Option<String>,
71    /// Current state of the instrument (e.g., "active", "expired").
72    pub state: Option<String>,
73    /// Strike price of the option contract.
74    pub strike_price: Option<String>,
75    /// General tradability status.
76    pub tradability: Option<String>,
77    /// Type of option contract ("call" or "put").
78    #[serde(rename = "type")]
79    pub option_type: Option<String>,
80    /// Timestamp when the instrument was last updated.
81    pub updated_at: Option<String>,
82    /// API URL for this option instrument resource.
83    pub url: Option<String>,
84}
85
86/// Represents an option position held in a Robinhood account.
87#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct OptionPosition {
89    /// API URL for the account holding this position.
90    pub account: Option<String>,
91    /// Average price paid per contract.
92    pub average_price: Option<String>,
93    /// Identifier for the parent option chain.
94    pub chain_id: Option<String>,
95    /// Ticker symbol of the underlying stock.
96    pub chain_symbol: Option<String>,
97    /// Unique identifier for this option position.
98    pub id: Option<String>,
99    /// API URL for the associated option instrument.
100    pub option: Option<String>,
101    /// Number of contracts held.
102    pub quantity: Option<String>,
103    /// Position type (e.g., "long", "short").
104    #[serde(rename = "type")]
105    pub position_type: Option<String>,
106    /// Timestamp when the position was created.
107    pub created_at: Option<String>,
108    /// Timestamp when the position was last updated.
109    pub updated_at: Option<String>,
110}
111
112/// Input specification for looking up a specific option contract.
113///
114/// Used with [`RobinhoodClient::get_option_market_data`](crate::client::RobinhoodClient)
115/// to identify contracts by strike, expiration, and type.
116#[derive(Debug, Clone)]
117pub struct OptionContractSpec<'a> {
118    /// Strike price as a string (e.g., `"50.0000"`).
119    pub strike_price: &'a str,
120    /// Expiration date in YYYY-MM-DD format.
121    pub expiration_date: &'a str,
122    /// Contract type: `"call"` or `"put"`.
123    pub option_type: &'a str,
124}
125
126/// Live market data for a specific option contract.
127///
128/// Returned by the `/marketdata/options/` endpoint. Contains quote prices,
129/// Greeks, volume, open interest, and probability estimates.
130#[derive(Debug, Clone, Serialize, Deserialize)]
131pub struct OptionMarketData {
132    /// API URL of the option instrument.
133    pub instrument: Option<String>,
134    /// Unique identifier for the option instrument.
135    pub instrument_id: Option<String>,
136
137    /// Current bid price.
138    pub bid_price: Option<String>,
139    /// Current ask price.
140    pub ask_price: Option<String>,
141    /// Price of the most recent trade.
142    pub last_trade_price: Option<String>,
143    /// Mid-point of bid and ask (mark price).
144    pub mark_price: Option<String>,
145    /// Break-even price at expiration.
146    pub break_even_price: Option<String>,
147    /// Adjusted mark price.
148    pub adjusted_mark_price: Option<String>,
149    /// Closing price from the previous trading session.
150    pub previous_close_price: Option<String>,
151    /// Highest trade price today.
152    pub high_price: Option<String>,
153    /// Lowest trade price today.
154    pub low_price: Option<String>,
155
156    /// Delta (rate of change vs underlying price).
157    pub delta: Option<String>,
158    /// Gamma (rate of change of delta).
159    pub gamma: Option<String>,
160    /// Theta (time decay per day).
161    pub theta: Option<String>,
162    /// Vega (sensitivity to implied volatility).
163    pub vega: Option<String>,
164    /// Rho (sensitivity to interest rate changes).
165    pub rho: Option<String>,
166    /// Implied volatility of the contract.
167    pub implied_volatility: Option<String>,
168
169    /// Number of contracts traded today.
170    pub volume: Option<i64>,
171    /// Total outstanding contracts.
172    pub open_interest: Option<i64>,
173
174    /// Probability of profit for a long position (0.0-1.0).
175    pub chance_of_profit_long: Option<String>,
176    /// Probability of profit for a short position (0.0-1.0).
177    pub chance_of_profit_short: Option<String>,
178
179    /// Timestamp when the market data was last updated.
180    pub updated_at: Option<String>,
181}