UofA522 / Project1

Rust Project 1 for 522 - Stock Market Monitor
GNU General Public License v3.0
0 stars 0 forks source link

Writing a method to fetch a stock #2

Open Alton1998 opened 1 month ago

Alton1998 commented 1 month ago

Handle bad stock symbol through Results or Options

Prabhroop-Singh2002 commented 1 month ago

For the main.rs file:

use yahoo_finance_api as yahoo; use std::time::{Duration, UNIX_EPOCH}; use tokio_test;

fn main() { let provider = yahoo::YahooConnector::new().unwrap(); let response = tokio_test::block_on(provider.get_quote_range("GOOGL", "1d", "1mo")).unwrap(); let quotes = response.quotes().unwrap(); println!("Google's quotes of the last month: {:?}", quotes);

let first_day_quote = &quotes[0]; // Access the first quote (first day's data)
let high = first_day_quote.high;
let low = first_day_quote.low;

println!("High for the first day: {}", high);
println!("Low for the first day: {}", low);

}

For the cargo.toml file:

[package] name = "fetch_stock" version = "0.1.0" edition = "2021"

[dependencies] yahoo_finance_api = "2.3.0" tokio-test = "0.4.4"