Crate eeyf

Crate eeyf 

Source
Expand description

This project provides a set of functions to receive data from the the yahoo! finance website via their API.

This project is licensed under Apache 2.0 or MIT license (see files LICENSE-Apache2.0 and LICENSE-MIT).

All requests to the yahoo API return async futures. Therefore, the functions need to be called from an async function with .await or via functions like block_on. The examples are based on the tokio runtime applying the tokio-test crate.

§Get the latest available quote:

use eeyf as yahoo;
use time::OffsetDateTime;
use tokio_test;

fn main() {
    let provider = yahoo::YahooConnector::new().unwrap();
    // get the latest quotes in 1 minute intervals
    let response = tokio_test::block_on(provider.get_latest_quotes("AAPL",
"1d")).unwrap();     // extract just the latest valid quote summery
    // including timestamp,open,close,high,low,volume
    let quote = response.last_quote().unwrap();
    let time: OffsetDateTime =
OffsetDateTime::from_unix_timestamp(quote.timestamp).unwrap();     println!
("At {} quote price of Apple was {}", time, quote.close); }

§Get history of quotes for given time period:

use eeyf as yahoo;
use time::{macros::datetime, OffsetDateTime};
use tokio_test;

fn main() {
    let provider = yahoo::YahooConnector::new().unwrap();
    let start = datetime!(2020-1-1 0:00:00.00 UTC);
    let end = datetime!(2020-1-31 23:59:59.99 UTC);
    // returns historic quotes with daily interval
    let resp = tokio_test::block_on(provider.get_quote_history("AAPL",
start, end)).unwrap();     let quotes = resp.quotes().unwrap();
    println!("Apple's quotes in January: {:?}", quotes);
}

§Get the history of quotes for time range

Another method to retrieve a range of quotes is by requesting the quotes for a given period and lookup frequency. Here is an example retrieving the daily quotes for the last month: ```rust use eeyf as yahoo; use tokio_test;

fn main() { let provider = yahoo::YahooConnector::new().unwrap(); let response = tokio_test::block_on(provider.get_quote_range(“AAPL”, “1d”, “1mo”)).unwrap(); let quotes = response.quotes().unwrap(); println!(“Apple’s quotes of the last month: {:?}”, quotes); }


```rust
use eeyf as yahoo;
use tokio_test;

fn main() {
    let provider = yahoo::YahooConnector::new().unwrap();
    let resp = tokio_test::block_on(provider.search_ticker("Apple")).unwrap();

    let mut apple_found = false;
    println!("All tickers found while searching for 'Apple':");
    for item in resp.quotes {
        println!("{}", item.symbol)
    }
}

Some fields like longname are only optional and will be replaced by default values if missing (e.g. empty string). If you do not like this behavior, use search_ticker_opt instead which contains Option<String> fields, returning None if the field found missing in the response.

Re-exports§

pub use builder::YahooConnectorBuilder as EnterpriseYahooConnectorBuilder;
pub use circuit_breaker::CircuitBreaker;
pub use circuit_breaker::CircuitBreakerConfig;
pub use circuit_breaker::CircuitBreakerStats;
pub use circuit_breaker::CircuitState;
pub use connection_pool::ConnectionPool;
pub use connection_pool::ConnectionPoolConfig;
pub use connection_pool::ConnectionStats;
pub use enterprise::EnterpriseConfig;
pub use enterprise::EnterpriseHealthStatus;
pub use enterprise::EnterpriseMetrics;
pub use enterprise::EnterpriseYahooConnector;
pub use error_categories::ErrorCategorizer;
pub use error_categories::ErrorCategory;
pub use error_categories::ErrorInfo;
pub use observability::HealthCheck;
pub use observability::HealthStatus;
pub use observability::LibraryMetrics;
pub use observability::ObservabilityConfig;
pub use observability::ObservabilityManager;
pub use observability::RequestContext;
pub use presets::PresetConfig;
pub use presets::PresetFormat;
pub use presets::PresetManager;
pub use rate_limiter::RateLimitConfig;
pub use rate_limiter::RateLimitError;
pub use rate_limiter::RateLimitStatus;
pub use rate_limiter::RateLimiter;
pub use request_deduplication::DeduplicationConfig;
pub use request_deduplication::DeduplicationStats;
pub use request_deduplication::RequestDeduplicator;
pub use response_cache::CacheStats;
pub use response_cache::ResponseCache;
pub use response_cache::ResponseCacheConfig;
pub use retry::RetryConfig;
pub use retry::RetryPolicy;
pub use retry::RetryStats;
pub use yahoo_error::ErrorContext;
pub use yahoo_error::YahooError;
pub use yahoo_error::YahooErrorCode;
pub use yahoo_error::YahooErrorWithContext;
pub use time;

Modules§

async_impl
batch
Batch operations for fetching multiple symbols in parallel with automatic rate limiting.
builder
Builder pattern for YahooConnector with fluent API and preset support.
circuit_breaker
Circuit breaker pattern implementation for fault tolerance
connection_pool
Connection pooling for efficient HTTP connection management
enterprise
Enterprise-grade integration module
error_categories
Enhanced error categorization for improved error handling and retry logic
export
Data export utilities for financial data.
health
Health check implementation for EEYF
market_hours
Market hours checking module for Yahoo Finance API
metrics
Prometheus metrics collection and exposition
observability
Comprehensive logging and metrics for observability
presets
Preset configuration management for YahooConnector.
rate_limiter
request_deduplication
Request deduplication to prevent duplicate API calls
response_cache
Response caching with TTL and LRU eviction
retry
Exponential backoff retry logic for resilient API calls
runtime
Runtime abstraction layer for EEYF
screener
Stock Screener Module
tracing
Distributed tracing implementation for EEYF
validation
Symbol validation and lookup using Yahoo Finance search API.
yahoo_error

Macros§

retry_operation
Convenience macro for retrying operations

Structs§

AdjClose
AssetProfile
CapitalGain
This structure simply models a capital gain which has been recorded.
CurrentTradingPeriod
DefaultKeyStatistics
Dividend
This structure simply models a dividend which has been recorded.
ExtendedQuoteSummary
FinancialData
FinancialEvent
PeriodInfo
Quote
Struct for single quote
QuoteBlock
QuoteList
QuoteType
Split
This structure simply models a split that has occured.
SummaryDetail
TradingPeriods
YChart
YMetaData
YNewsItem
YOptionChain
YOptionChainData
YOptionChainResult
YOptionContract
YOptionDetails
YQuote
YQuoteBlock
YQuoteItem
YQuoteItemOpt
YQuoteSummary
YResponse
YSearchResult
YSearchResultOpt
YSummaryData
YahooConnector
Container for connection parameters to yahoo! finance server
YahooConnectorBuilderLegacy

Type Aliases§

Decimal