[GNC-dev] Thoughts on new Finance::Quote modules that require an API Key

Vincent Lucarelli vincent.lucarelli at gmail.com
Sun Jun 16 16:14:14 EDT 2019


Hi,

I think for the next release of Finance::Quote, Alphavantage.pm and IEXCloud will only support environment variables (named ALPHVANTAGE_API_KEY and IEXCLOUD_API_KEY).

We are going to work on extending the new operator to allow setting instance variables, including module specific data.  Something like:

my $q = Finance::Quote->new(
     TIMEOUT => 60,
     FAILOVER => 1,
     alphavantage => { API_KEY => 'thealphavkey', othervariable => 'value' },
     iexcloud => { API_KEY => 'theiexkey'},
  );

There will also be setter methods as you suggested.

We can keep you informed so that the September GnuCash release can take advantage.

Best,

Vince

> On Jun 15, 2019, at 10:59 PM, John Ralls <jralls at ceridwen.us> wrote:
> 
> David,
> 
> AQBanking maintains its own set of settings files in ~/.aqbanking. Finance::Quote at present doesn't keep any user state.
> 
> Regards,
> John Ralls
> 
> 
>> On Jun 15, 2019, at 5:52 PM, David Carlson <david.carlson.417 at gmail.com> wrote:
>> 
>> I believe the AQ Banking feature has already solved the issue of saving usernames and passwords for multiple financial institutions in a manner that is easily migrated to new GnuCash releases.  Is it possible to do the API Key thing in a manner that would seem very little different to the user?
>> 
>> 
>> 
>> On Sat, Jun 15, 2019 at 12:53 PM John Ralls <jralls at ceridwen.us> wrote:
>> 
>> 
>>> On Jun 15, 2019, at 9:17 AM, Vincent Lucarelli <vincent.lucarelli at gmail.com> wrote:
>>> 
>>> Hi,
>>> 
>>> We are working on the next release of Finance::Quote and will try to add https://iexcloud.io/ <https://iexcloud.io/> as a new module.
>>> 
>>> Like Alphavantage, users will need to register and get an API key.
>>> 
>>> Since GnuCash is a major user of Finance::Quote, I wanted to get opinions on how to handle API keys.  I have two initial ideas:
>>> 
>>> 
>>> 1. Each Finance::Quote module expects a module specific environment variable and GnuCash would need to update the Preferences > Online Quotes pane for each API key.
>>> 
>>> 2. We invent a more global environment variable that can hold multiple API keys. For example, something like
>>> 
>>> FQ_API_KEYS=ALPHAVANTAGE_API_KEY:XXXXXXXXXXXXXXXX;IEXCLOUD_API_KEY:sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>>> 
>>> 
>>> The problem with the first approach is that GnuCash preferences need to change with each addition.
>>> 
>>> The problems wit the second approach are usability and parsing (do we assume no service would ever include : or ; in the API key?).  The later could be solved with json formatting, but that is even worse for users.
>>> 
>>> 
>>> 
>>> Appreciate any suggestions.
>> 
>> Vince,
>> 
>> Excellent news, thanks for stepping up to help Erik out.
>> 
>> ';' in your FQ_API_KEYS will have to be quoted to keep the shell from interpreting it, and any quotes in the key would have to be escaped even with separate environment variables per service. Telling users to escape the delimiter character and quotes is easier than teaching them to format a JSON string. e.g FQ_API_KEYS="AlphaVantage:xxxxxxxxx\"xxxx\:xxxxxx...". The real problem with that is that it breaks backward compatibility with GnuCash, which sets ALPHAVANTAGE_API_KEY when the preference is set. That could be worked around by continuing to look for the older environment variable, or telling users to set the new environment variable themselves, which they'd need to do anyway to use a new service until we rewrote the preference item. Note that we're two weeks away from our next release, so that change would be in the September release at the earliest.
>> 
>> Environment variables are clumsy. Might you consider an alternative, perhaps a "set_key(service, key)" function on the Finance::Quote object? 
>> 
>> Regards,
>> John Ralls
>> 
>> 
>> _______________________________________________
>> gnucash-devel mailing list
>> gnucash-devel at gnucash.org
>> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
>> 
>> 
>> -- 
>> David Carlson
> 



More information about the gnucash-devel mailing list