xemwebe / yahoo_finance_api

Simple wrapper to yahoo! finance API to retrieve latest quotes and end-of-day quote histories
Apache License 2.0
64 stars 29 forks source link

Provide an example in the Readme on how to access specific quotes withing the quote summary. #19

Closed ts7even closed 1 year ago

ts7even commented 1 year ago

I was wondering if you could provide an example how to access (print) certain quotes within the quotes summary. For example, only print adjclose and timestamp, not the entire quote summary (high, low, open, ect)

fn main() {
    let ticker = ["AAPL", "T", "GOOGL"];
    let provider = yahoo::YahooConnector::new();
    for t in ticker {
        let response = tokio_test::block_on(provider.get_quote_range(t, "1d", "1mo")).unwrap();
        let quotes = response.quotes().unwrap();
        println!("{}", t);
        for item in quotes
        {
            println!("{}: {:.2}",item.timestamp ,item.adjclose)
    }
  }
}
xemwebe commented 1 year ago

Actually I would prefer to just focus on the library's API in the Read.me instead of providing a comprehensive list of all potential usages. For example, to just print timestamp and adjclose, you could just replace the line let quotes = ... by something like

    let quotes: Vec<(u64, f64)> = response.quotes().unwrap().iter().map(|q| (q.timestamp, q.adjclose)).collect();

to achieve the desired result.