OptionChain

Struct OptionChain 

Source
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: String

The 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: String

The time value of an option position.

NOTE: The market value of an option position minus the position’s intrinsic value.

§theoretical_value: String

The 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: i32

Total number of open contracts for the option spread.

NOTE: This value is updated daily.

§ask: String

Ask price. The price a seller is willing to accept for the option spread.

§bid: String

Bid price. The price a buyer is willing to pay for the option spread.

§mid: String

Average between ask and bid.

§ask_size: i32

Amount of contracts at the given ask price.

§bid_size: i32

Amount of contracts at the given bid price.

§close: String

The last traded price for the option spread.

NOTE: This value only updates during the official market session.

§high: String

Today’s highest price for the option spread.

§last: String

The last traded price for the option spread.

§low: String

Today’s lowest traded price for the option spread.

§net_change: String

Difference between prior Close price and current Close price for the option spread.

§net_change_pct: String

Percentage changed between prior close price and current close price for the option spread.

§open: String

The initial price for the option spread during the official market session.

§previous_close: String

Prior day’s Closing price.

§volume: i32

The number of contracts traded today.

§side: OptionChainSide

The 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

Source

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:?}");
Source

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:

§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

Source§

fn clone(&self) -> OptionChain

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OptionChain

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for OptionChain

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for OptionChain

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,