#symbols #options #stock #date #stock-symbols

financial_symbols

Stock symbols & option contracts structs which implement the Copy trait

10 releases (4 stable)

1.0.3 Mar 14, 2025
1.0.2 Nov 25, 2024
0.1.5 Dec 12, 2023
0.1.4 Nov 30, 2023

#51 in Finance

Download history 17/week @ 2024-12-04 19/week @ 2024-12-11 3/week @ 2025-02-05 12/week @ 2025-02-12 4/week @ 2025-02-19 7/week @ 2025-02-26 124/week @ 2025-03-12 4/week @ 2025-03-19

136 downloads per month

MIT license

43KB
807 lines

Financial Symbols

Stock symbols & option contract symbols which implement the copy trait.

Build status Crates.io Documentation

use financial_symbols::{OptionContract, OptionType, Ticker};
use rust_decimal::Decimal;
use chrono::NaiveDate;
use std::str::FromStr;

let ticker = Ticker::try_from("AAPL").unwrap();

let ticker_copy = ticker;

assert_eq!(ticker, ticker_copy);
assert_eq!(ticker, "AAPL");

let contract = OptionContract::from_osi("SPXW231127C03850000").unwrap();

let contract_copy = contract;
assert_eq!(contract, contract_copy);

assert_eq!(contract.ticker(), "SPXW");
assert_eq!(contract.option_type(), OptionType::Call);
assert_eq!(contract.expiry(), NaiveDate::from_str("2023-11-27").unwrap());
assert_eq!(contract.strike(), Decimal::from(3850));

let contract = OptionContract::from_dx_feed(".SPXW231127C3850").unwrap();
assert_eq!(contract.to_osi(), "SPXW231127C03850000");

Benchmark

Tested on Apple M1 Pro 16GB Ram

from_osi SPXW231124P04060000
            time:   [10.557 ns 10.582 ns 10.629 ns]

from_osi TSLA240119C00066670
            time:   [10.559 ns 10.595 ns 10.667 ns]

from_osi A231215C00055000
            time:   [9.7667 ns 9.7743 ns 9.7830 ns]

Dependencies

~1.6–2.8MB
~51K SLoC