pub struct OptionSymbol { /* private fields */ }Expand description
An option contract in the 21-character OSI form Schwab uses for order
legs and quotes: the underlying padded to six characters, the expiration
as YYMMDD, C or P, and the strike times 1000 as eight digits
(AAPL 240517P00190000).
use chrono::NaiveDate;
use rustyschwab_types::Decimal;
use rustyschwab_types::trading::OptionSymbol;
let expiry = NaiveDate::from_ymd_opt(2024, 5, 17).unwrap();
let put = OptionSymbol::put("AAPL", expiry, Decimal::from(190)).unwrap();
assert_eq!(put.to_string(), "AAPL 240517P00190000");
assert_eq!("AAPL 240517P00190000".parse::<OptionSymbol>().unwrap(), put);Implementations§
Source§impl OptionSymbol
impl OptionSymbol
Sourcepub fn new(
underlying: impl AsRef<str>,
expiration: NaiveDate,
put_call: PutCall,
strike: Decimal,
) -> Result<Self, String>
pub fn new( underlying: impl AsRef<str>, expiration: NaiveDate, put_call: PutCall, strike: Decimal, ) -> Result<Self, String>
Build a symbol, rejecting anything the OSI format cannot express: an underlying longer than six ASCII letters or digits, an expiration outside 2000–2099 (the symbol keeps two year digits, read as 20YY), a strike that is not positive, above 99999.999, or finer than a tenth of a cent.
Sourcepub fn call(
underlying: impl AsRef<str>,
expiration: NaiveDate,
strike: Decimal,
) -> Result<Self, String>
pub fn call( underlying: impl AsRef<str>, expiration: NaiveDate, strike: Decimal, ) -> Result<Self, String>
A call contract; see OptionSymbol::new for the validation rules.
Sourcepub fn put(
underlying: impl AsRef<str>,
expiration: NaiveDate,
strike: Decimal,
) -> Result<Self, String>
pub fn put( underlying: impl AsRef<str>, expiration: NaiveDate, strike: Decimal, ) -> Result<Self, String>
A put contract; see OptionSymbol::new for the validation rules.
pub fn underlying(&self) -> &str
pub fn expiration(&self) -> NaiveDate
pub fn put_call(&self) -> PutCall
pub fn strike(&self) -> Decimal
Trait Implementations§
Source§impl Clone for OptionSymbol
impl Clone for OptionSymbol
Source§impl Debug for OptionSymbol
impl Debug for OptionSymbol
Source§impl Display for OptionSymbol
impl Display for OptionSymbol
impl Eq for OptionSymbol
Source§impl From<&OptionSymbol> for String
impl From<&OptionSymbol> for String
Source§fn from(symbol: &OptionSymbol) -> Self
fn from(symbol: &OptionSymbol) -> Self
Source§impl From<OptionSymbol> for String
impl From<OptionSymbol> for String
Source§fn from(symbol: OptionSymbol) -> Self
fn from(symbol: OptionSymbol) -> Self
Source§impl FromStr for OptionSymbol
impl FromStr for OptionSymbol
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses exactly the canonical form Display writes:
an upper-case root padded on the right to six characters, so a symbol
round-trips unchanged. The two-digit year is 20YY: listed options do
not expire in the last century, and %y would read 70–99 as 19YY.