Vincent,

You're looking in the wrong places.

The list of F::Q sources displayed in the Security Editor dialog is partially 
hard-coded in libgnucash/engine/gnc-commodity.c beginning at line 171. Every 
entry in those two lists represents an F::Q method. At startup GC calls F::Q's 
`$quoter->sources()` and compares the returned list against the hard-coded 
lists, enabling the matching entries. Any F::Q methods not in either hard-coded 
list is added to a new dynamic list that's displayed as the "unknown" 
list--unknown because at present GnuCash has no way of knowing whether it's a 
single or a multi-source method--in F::Q terminology whether it has fallbacks. 
Maintaining that list is a pain in the rear and its existence creates a 
coupling between GC and F::Q versions. The same applies to modules and API keys 
and to which module provides which methods. The perl interface is in 
libgnucash/quotes/finance-quotes-wrapper.in that's turned into 
bin/finance-quotes-wrapper.pl at configuration. Any additions or changes there 
should be limited to converting a JSON stream on stdin to function arguments, 
calling the F::Q function, and converting the return data into a JSON stream on 
stdout and errors on stderr. The wrapper is driven by gnucash/price-quotes.cpp 
that's responsible for presenting an API to the rest of the program. API callsl 
set arguments and marshal them into the JSON stream sent to 
finance-quoter-wapper's stdin, invoking the appropriate finance-quote-wrapper 
function, parsing the returned JSON string into whatever C++ struct the API 
promises to the rest of GnuCash, and parsing and interpreting the stderr JSON. 
finance-quote-wrapper functions should be kept as thin as possible because it's 
perl running in a separate process and must interact purely through the JSON 
streams. The pair of finance-quote-wrapper and price-quotes.cpp should abstract 
away as much implementation detail as possible so that coupling between F::Q 
and the rest of GnuCash is minimal.

I think that the user interface, both for the source selection in the GUI and 
for retrieving specified quotes from the command line, should continue to focus 
on methods and treat the methods behind them as much as an implementation 
detail as possible. To accomplish that GnuCash needs to know when a method is 
implemented by a module that needs an API key and which key that is. If GC 
doesn't already have that key stored it needs to prompt for it using a dialog 
box with a "remember" checkbox in the GUI; there are several ways one could go 
with a terminal command of which erroring out (`method foo requires a bar API 
key and you haven't provided one`).

I'd also like to get rid of the hard-coded method lists. That requires being 
able to query which methods are single-source and which have fallbacks. For the 
latter it would be nice to have a tooltip listing what single-source methods in 
what order will be tried to obtain the quote. It would also be nice to flag on 
the list which sources need which API keys. GC also needs to scan the 
configured securities for sources to identify any sources that aren't provided 
by the installed F::Q and present that as an error to the user.

Currency sources are interesting in a different way. Last I looked F::Q had 
four available sources for looking up currencies defaulting on alphavantage. 
Using anything other than the F::Q default will require substantially changing 
the way GC requests currency rates. There are probably users who would like to 
configure sources per pair of currencies, e.g ECB for EUR<->USD and 
Alphavantage for USD<->INR. Others might be content with a preference setting 
for the currency method. Most may not care at all as long as they can get the 
rates that they want without much fiddling.

That's a mid-size project. I don't think it will be possible to have it ready 
for GnuCash 5.0, whose release is only 10 weeks from now with feature freeze in 
only two weeks. It might be possible to get it into 5.1 at the end of June but 
I think 5.2 at the end of September is a more realistic goal.

See https://wiki.gnucash.org/wiki/CodingStandard and 
https://wiki.gnucash.org/wiki/C++ for style guidance.

Regards,
John Ralls


> On Jan 21, 2023, at 8:43 AM, Vincent Lucarelli <vincent.lucare...@gmail.com> 
> wrote:
> 
> Hi,
> 
> We have an experimental function in Finance::Quote called get_features() that 
> returns a perl hash that provides information on 
> quote_modules - list of sources for stock quotes + a list of any required 
> parameters (such as an API key) the module requires
> quote_methods - a single module or list of modules to try in a specific order
> currency_modules - list of sources for currency information if FQ is required 
> to convert quotes from one currency to another
> 
> The current version of FQ just uses AlphaVantage for currency conversion and 
> users must specify an AlphaVantage API through either an environment variable 
> or through GnuCash Settings.
> 
> With this experimental FQ function, GnuCash could 
> Solicit API keys in Settings to centralize where users setup FQ
> Expose currecy_modules to users so they could use alternatives to AlphaVantage
> Reduce issues on platforms like macOS where setting GnuCash environment 
> variables is not straight-forward nor survivors GnuCash upgrades
> 
> It looks like there are three touch points for FQ in GnuCash
> GUI: Tools > Security Editor > Add
> I’m not clear on what the “Unknown” list is, but the Single is for “modules” 
> and Multiple is for “methods”
> One approach to simplify this is to just have a list of “methods” and in the 
> list indicate which modules the method uses
> GUI: gnucash > Settings… > Online Quotes
> This currently only asks for an AlphaVantage API Key
> The additional information from get_features() would allow expanding these 
> preferences to include any API key + control over currency conversion
> finance-quote-wrapper
> The API key info + currency preferences from the GUI will need to be routed 
> through here (I think?)
> Is this also used to populate the lists in Security Editor
> 
> Potential Changes to GunCash (listed in the order I think I would try to 
> implement)
> Expand Settings… > Online Quotes to solicit all FQ parameters & route info to 
> finance-quote-wrapper
> Use information from get_features to better populate Security Editor > Add 
> and potential simplify GUI
> Expand Settings… > Online Quotes to expose currency features to users
> 
> Looking for missing touch points, feedback on potential changes, and pointers 
> to GnuCash-FQ interactions that are more complicated than I presented here.
> 
> Best,
> 
> Vince
> _______________________________________________
> gnucash-devel mailing list
> gnucash-devel@gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel

_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to