Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YH Finance (FINANCEAPI) API Key to Quotes infrastructure. #2021

Closed
wants to merge 0 commits into from

Conversation

jralls
Copy link
Member

@jralls jralls commented Sep 19, 2024

And add financeapi to known sources.
This to accommodate a new source in F::Q 1.63 that @bpschuck intends to release soon. There's some string revisions so we need to get this merged this weekend.

Copy link
Member

@gjanssens gjanssens left a comment

Choose a reason for hiding this comment

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

Looks good to me.

The use of boost::process::environment is a nice touch. Would it make sense to replace our use of getenv with calls to boost::process::environment as well for consistency ? One way to do that could be to make new_env a member variable of GncFQQuoteSource and populate it at construction time already. That would eliminate the need to store the two api keys themselves as member variables.

@jralls
Copy link
Member Author

jralls commented Sep 20, 2024

I used bp::environment because that's what bp::child wants for an environment argument. You're right, having retrieved the whole environment with bp::environment I should be using that to retrieve the api key from it instead of calling getenv.

Related to that, the current implementation prefers the preference value to the environment variable's value if both are set. Is that appropriate or should it be the other way around?

The idea to make new_env a member variable instead of keeping individual API keys as member variables is worth discussing. Having separate member variables for api keys isn't going to scale: There are already 8 (5 stock, 4 currency, but alphavantage is duplicated and yh finance will be). @bpschuck has in the past said that he'd prefer not to use environment variables for the keys--there's a way to set them in F::Q::new--and there are two of the 8 (CurrencyRates/Fixer.pm and CurrencyRates/OpenExchange.pm) that require an api key and lack an environment environment variable to set it. It would be more in line with F::Q's future direction to be passing a JSON dict of api keys to gnc-fq-wrapper.

Apropos that we also need to have a preference for the default currency source, and given Alpha Vantage's throttling and daily quote limits it should be something else.

There's not time for that this weekend. I'll merge this and do another PR.

@bpschuck
Copy link
Contributor

bpschuck commented Sep 20, 2024 via email

@jralls
Copy link
Member Author

jralls commented Sep 20, 2024

@gjanssens, of course using the bp::environment in get_api_key required creating it in the GncFQQuoteSource constructor, at which point I might as well make it a member and lose the api_key members, so I did. The result is cleaner still and @bpschuck's (thanks, Bruce!) clarification means that it's a good way forward.

@gjanssens
Copy link
Member

@jralls regarding the question of precedence, I don't have a strong opinion. I can only imagine one use case where it would be useful if the environment value takes precedence over the preference value: perhaps someone may want to run gnucash-cli to retrieve quotes with a different-than default API key. In that case it would be convenient if it could just be set via an environment variable. I think that's rather uncommon though. And if that need really exists I'd probably rather implement it as an extra command line option to pass API key overrides.

For now my suggestion would be the current precedence rules are fine until someone presents a good case to do it differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants