Skip to content

Conversation

SaurabhJamadagni
Copy link
Contributor

PR in reference to issue

PR changes include:

  • Implementation of the StocksSource trait for alpha vantage source
  • Types of data to be retrieved but not limited to:
    • Stock quote
    • Historical time series on ticker
    • company fundamentals such as balance sheet, earnings, IPO Calendar

Todo before final PR:

  • Revert example function to original.
  • Extend to above kinds of data
  • Write necessary tests.

This PR is currently in a draft stage. PR description to be updated with progressing changes.

@carlobortolan please let me know your feedback on the flow. I'll extend the functionality with your feedback in mind. Thanks!

@SaurabhJamadagni
Copy link
Contributor Author

Hey @carlobortolan, I configured my commits to be signed and also ensured I passed the -S flag while committing. I am not sure why my commits aren't signed here. I'll fix that for the future commits, I apologise.

@carlobortolan
Copy link
Owner

carlobortolan commented Jul 18, 2025

@SaurabhJamadagni Thanks! I'll take a look at the changes over the weekend;

one idea regarding the signed commits: have you uploaded your keys to github? https://github.com/settings/keys

@carlobortolan carlobortolan marked this pull request as draft July 18, 2025 00:33
@carlobortolan carlobortolan changed the title feat(data): fetch stocks data from Alpha Vantage [DRAFT] feat(data): fetch stocks data from Alpha Vantage Jul 18, 2025
@carlobortolan carlobortolan added enhancement New feature or request dependencies Pull requests that update a dependency file rust Pull requests that update rust code labels Jul 18, 2025
Copy link
Owner

@carlobortolan carlobortolan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SaurabhJamadagni: Very nice - thanks for the good work so far! I've added some small comments.

I also wanted to ask your opinion regarding the naming of some things:

  • traits::StocksSource -> traits::QuoteProvider (stock_source is already the name of the module)
  • GlobalQuote -> Quote (GlobalQuote might be too specific to Alpha Vantage?)

example_data_module().await;
}

async fn example_data_module() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe put this in a separate file inside the examples/ directory

self.base_url, symbol, self.api_key
);

let response = reqwest::get(&url).await.unwrap();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're using .unwrap(); if the network call fails (e.g., DNS error, timeout), the program will panic. Something like this should fix this:

let response = reqwest::get(&url).await.map_err(|e| {
    Error::new(std::io::ErrorKind::Other, format!("Request failed: {}", e))
})?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for sure! I was just really wanting to see some output so took a bit of a lousy approach to exception handling. I'll factor that in.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re using reqwest::get() directly, which creates a new HTTP client on every request.
I'd suggest instantiating it once and then reusing it:

pub struct AlphaVantageSource {
    client: reqwest::Client,
    base_url: String,
    api_key: String,
}

impl AlphaVantageSource {
    pub fn new(user_key: &str) -> Self {
        AlphaVantageSource {
            client: reqwest::Client::new(),
            base_url: "https://www.alphavantage.co/query".to_string(),
            api_key: user_key.to_string(),
        }
    }
}

...

let response = self.client.get(&url).send().await.map_err(...)?

@SaurabhJamadagni
Copy link
Contributor Author

traits::StocksSource -> traits::QuoteProvider (stock_source is already the name of the module)

For this, I was assuming anything related to a stock ticker would fall under this trait. So fundamentals data as well. Or were you thinking fundamentals data would be a different trait?

GlobalQuote -> Quote (GlobalQuote might be too specific to Alpha Vantage?)

Agree on this. I'll change that right away.

Thanks for all your feedback @carlobortolan :)

@carlobortolan
Copy link
Owner

traits::StocksSource -> traits::QuoteProvider (stock_source is already the name of the module)

For this, I was assuming anything related to a stock ticker would fall under this trait. So fundamentals data as well. Or were you thinking fundamentals data would be a different trait?

@SaurabhJamadagni ah, got it; I was thinking that QuoteProvider could focus only on quote-level data (price, volume, etc.), and then we could later add a separate trait like FundamentalsProvider for earnings, IPO calendar, etc. to keep them separated (but still within the same module). Let me know what you think / if you have alternative ideas on how to structure this!

@SaurabhJamadagni
Copy link
Contributor Author

keep them separated (but still within the same module). Let me know what you think / if you have alternative ideas on how to structure this!

Oh I see what you mean too. I didn't think about having multiple traits going in the same module. But that sounds good, I agree with you. Thanks @carlobortolan! On it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request rust Pull requests that update rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants