pub struct OptionChain {Show 34 fields
pub delta: Option<String>,
pub theta: Option<String>,
pub gamma: Option<String>,
pub rho: Option<String>,
pub vega: Option<String>,
pub implied_volatility: Option<String>,
pub intrinsic_value: String,
pub extrinsic_value: String,
pub theoretical_value: String,
pub probability_itm: Option<String>,
pub probability_otm: Option<String>,
pub probability_be: Option<String>,
pub probability_itm_iv: Option<String>,
pub probability_otm_iv: Option<String>,
pub probability_be_iv: Option<String>,
pub theoretical_value_iv: Option<String>,
pub daily_open_interest: i32,
pub ask: String,
pub bid: String,
pub mid: String,
pub ask_size: i32,
pub bid_size: i32,
pub close: String,
pub high: String,
pub last: String,
pub low: String,
pub net_change: String,
pub net_change_pct: String,
pub open: String,
pub previous_close: String,
pub volume: i32,
pub side: OptionChainSide,
pub strikes: Vec<String>,
pub legs: Vec<OptionSpreadLeg>,
}Expand description
A chain of option spreads for a given underlying symbol, spread type, and expiration.
Fields§
§delta: Option<String>The expected change in an option position’s value resulting from a one point increase in the price of the underlying security.
theta: Option<String>The expected decline in an option position’s value resulting from the passage of one day’s time, holding all other variables (price of the underlying, volatility, etc.) constant.
gamma: Option<String>The expected change in an option position’s delta resulting from a one point increase in the price of the underlying security.
rho: Option<String>The expected change in an option position’s value resulting from an increase of one percentage point in the risk-free interest rate (e.g. an increase from 3% to 4%).
vega: Option<String>The expected change in an option position’s value resulting from an increase of one percentage point in the volatility of the underlying security (e.g. an increase from 26% to 27%).
implied_volatility: Option<String>The volatility of the underlying implied by an option position’s current price.
intrinsic_value: StringThe value of an option position exclusive of the position’s time value. The value of the option position if it were to expire immediately.
extrinsic_value: StringThe time value of an option position.
NOTE: The market value of an option position minus the position’s intrinsic value.
theoretical_value: StringThe value of an option position based on a theoretical model of option prices (the Bjerksund-Stensland model).
NOTE: Calculated using volatility of the underlying.
probability_itm: Option<String>The calculated probability that an option position will have intrinsic value at expiration.
NOTE: Calculated using volatility of the underlying.
probability_otm: Option<String>The calculated probability that an option position will not have intrinsic value at expiration.
NOTE: Calculated using volatility of the underlying.
probability_be: Option<String>The calculated probability that an option position will have a value at expiration that is equal to or greater than the position’s current cost.
NOTE: Calculated using volatility of the underlying.
probability_itm_iv: Option<String>The calculated probability that an option position will have intrinsic value at expiration.
NOTE: Calculated using implied volatility.
probability_otm_iv: Option<String>The calculated probability that an option position will not have intrinsic value at expiration.
NOTE: Calculated using implied volatility.
probability_be_iv: Option<String>The calculated probability that an option position will have a value at expiration that is equal to or greater than the position’s current cost.
NOTE: Calculated using implied volatility.
theoretical_value_iv: Option<String>The value of an option position based on a theoretical model of option prices (the Bjerksund-Stensland model).
NOTE: Calculated using implied volatility.
daily_open_interest: i32Total number of open contracts for the option spread.
NOTE: This value is updated daily.
ask: StringAsk price. The price a seller is willing to accept for the option spread.
bid: StringBid price. The price a buyer is willing to pay for the option spread.
mid: StringAverage between ask and bid.
ask_size: i32Amount of contracts at the given ask price.
bid_size: i32Amount of contracts at the given bid price.
close: StringThe last traded price for the option spread.
NOTE: This value only updates during the official market session.
high: StringToday’s highest price for the option spread.
last: StringThe last traded price for the option spread.
low: StringToday’s lowest traded price for the option spread.
net_change: StringDifference between prior Close price and current Close price for the option spread.
net_change_pct: StringPercentage changed between prior close price and current close price
for the option spread.
open: StringThe initial price for the option spread during the official market session.
previous_close: StringPrior day’s Closing price.
volume: i32The number of contracts traded today.
side: OptionChainSideThe side of the option chain.
strikes: Vec<String>The strike prices for the option contracts in the legs of this spread.
legs: Vec<OptionSpreadLeg>The legs of the option spread.
Implementations§
Source§impl OptionChain
impl OptionChain
Sourcepub fn stream<'a>(
client: &'a Client,
query: &'a OptionChainQuery,
) -> impl Stream<Item = Result<StreamOptionChainResp, Error>> + 'a
pub fn stream<'a>( client: &'a Client, query: &'a OptionChainQuery, ) -> impl Stream<Item = Result<StreamOptionChainResp, Error>> + 'a
Stream an options chain for a given query OptionChainQuery.
NOTE: You need to provide a function to handle each stream chunk.
§Example
Example: Stream an option chain for Apple "AAPL".
let stream_aapl_option_chain_query = market_data::OptionChainQueryBuilder::new()
.underlying("AAPL")
.build()?;
let mut collected_chains = Vec::new();
// Start the stream and pin it to the stack
let mut option_chain_stream = OptionChain::stream(&stream_appl_option_chain_query);
tokio::pin!(option_chain_stream); // NOTE: You must pin the stream to poll it
while let Some(stream_resp) = option_chain_stream.next().await {
// The response type is `responses::market_data::StreamOptionQuotesResp`
// which has multiple variants. The main one you care about is `OptionQuotes`
// which will contain option quote data sent from the stream.
match stream_resp {
Ok(StreamOptionChainResp::OptionChain(chain)) => {
// Do something with the option quote like
// send a text / email alert based on some
// data from the quote like a certain price,
// market spread, volatility change, or something.
println!("{chain:?}");
collected_chains.push(chain);
}
Ok(StreamOptionChainResp::Heartbeat(heartbeat)) => {
// Response for periodic signals letting you know the connection is
// still alive. A heartbeat is sent every 5 seconds of inactivity.
println!("{heartbeat:?}");
// For the sake of this example, after we receive the
// tenth heartbeat, we will stop the stream session.
if heartbeat.heartbeat > 10 {
// Example: stopping a stream connection
return Err(Error::StopStream);
}
}
Ok(StreamOptionChainResp::Status(status)) => {
// Signal sent on state changes in the stream
// (closed, opened, paused, resumed)
println!("{status:?}");
}
Ok(StreamOptionChainResp::Error(err)) => {
// Response for when an error was encountered,
// with details on the error
eprintln!("{err:?}");
}
Err(err) => {
// Stream / Network error
eprintln!("{err:?}");
}
}
}
// After the stream ends print all the collected option chains
println!("{streamed_chains:?}");Sourcepub async fn stream_into(
client: &Client,
query: &OptionChainQuery,
callback: impl FnMut(StreamOptionChainResp) -> Result<(), Error>,
) -> Result<(), Error>
pub async fn stream_into( client: &Client, query: &OptionChainQuery, callback: impl FnMut(StreamOptionChainResp) -> Result<(), Error>, ) -> Result<(), Error>
Streams OptionChain’s for the provided OptionChainQuery.
This method builds a stream connection and continuously passes
incoming stream events (StreamOptionChainResp) to the provided
callback closure for processing.
§Stopping the stream
To stop the stream gracefully from within the callback, return
Err(Error::StopStream). This is treated as a control signal and will
terminate the stream without propagating an error. Any other error
returned from the callback will abort the stream and be returned to
the caller.
§Errors
Returns an Error if:
- the underlying HTTP/WebSocket stream fails,
- deserialization of a stream event into
StreamOptionChainRespfails, - or the
callbackreturns an error other thanError::StopStream.
§Examples
Stream events on an options chain.
OptionChain::stream_into(client, query, |stream_event| {
println!("Option Chain Stream Event: {stream_event:?}");
Ok(())
}).await?;Trait Implementations§
Source§impl Clone for OptionChain
impl Clone for OptionChain
Source§fn clone(&self) -> OptionChain
fn clone(&self) -> OptionChain
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more