avhz / RustQuant

Rust library for quantitative finance.
https://avhz.github.io
Apache License 2.0
1.07k stars 124 forks source link

Unable to Call YahooConnector Methods Due to Result Type Handling after upgrade yahoo_finance_api v2.1.0 to v2.2.0 #232

Closed joaquinbejar closed 3 months ago

joaquinbejar commented 3 months ago

I am encountering an issue where methods from YahooConnector in the yahoo_finance_api crate cannot be called due to the provider variable being of type Result<YahooConnector, YahooError>. The following errors are observed:

error[E0599]: no method named `get_quote_history` found for enum `Result` in the current scope
   --> src/data/yahoo.rs:187:54
    |
187 |         let response = tokio_test::block_on(provider.get_quote_history(
    |                                             ---------^^^^^^^^^^^^^^^^^ method not found in `Result<YahooConnector, YahooError>`
    |
note: the method `get_quote_history` exists on the type `YahooConnector`
   --> /Users/joaquin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/yahoo_finance_api-2.2.0/src/async_impl.rs:14:5
    |
14  | /     pub async fn get_quote_history(
15  | |         &self,
16  | |         ticker: &str,
17  | |         start: OffsetDateTime,
18  | |         end: OffsetDateTime,
19  | |     ) -> Result<YResponse, YahooError> {
    | |______________________________________^
help: use the `?` operator to extract the `YahooConnector` value, propagating a `Result::Err` value to the caller
    |
187 |         let response = tokio_test::block_on(provider?.get_quote_history(
    |                                                     +

error[E0599]: no method named `search_options` found for enum `Result` in the current scope
   --> src/data/yahoo.rs:228:54
    |
228 |         let response = tokio_test::block_on(provider.search_options(self.ticker.as_ref().ok_or(
    |                                             ---------^^^^^^^^^^^^^^ method not found in `Result<YahooConnector, YahooError>`
    |
note: the method `search_options` exists on the type `YahooConnector`
   --> /Users/joaquin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/yahoo_finance_api-2.2.0/src/async_impl.rs:92:5
    |
92  |     pub async fn search_options(&self, name: &str) -> Result<YOptionResults, YahooError> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: use the `?` operator to extract the `YahooConnector` value, propagating a `Result::Err` value to the caller
    |
228 |         let response = tokio_test::block_on(provider?.search_options(self.ticker.as_ref().ok_or(
    |                                                     +

error[E0599]: no method named `get_latest_quotes` found for enum `Result` in the current scope
   --> src/data/yahoo.rs:293:22
    |
293 |             provider.get_latest_quotes(
    |             ---------^^^^^^^^^^^^^^^^^ method not found in `Result<YahooConnector, YahooError>`
    |
note: the method `get_latest_quotes` exists on the type `YahooConnector`
   --> /Users/joaquin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/yahoo_finance_api-2.2.0/src/async_impl.rs:5:5
    |
5   | /     pub async fn get_latest_quotes(
6   | |         &self,
7   | |         ticker: &str,
8   | |         interval: &str,
9   | |     ) -> Result<YResponse, YahooError> {
    | |______________________________________^
help: use the `?` operator to extract the `YahooConnector` value, propagating a `Result::Err` value to the caller
    |
293 |             provider?.get_latest_quotes(
    |                     +
joaquinbejar commented 3 months ago

we can fix the version in the dependency yahoo_finance_api = "=2.1.0" or call the method handling the Result:

let response = tokio_test::block_on(provider.get_quote_history(
let response = tokio_test::block_on(provider?.search_options(self.ticker.as_ref().ok_or(
avhz commented 3 months ago

This should be fixed in my latest commit.