[GNC-dev] Robust error handling and respecting the Apha Vantage API limits in gnc-fq-helper.

Mike Alexander mta at umich.edu
Mon Feb 10 16:26:44 EST 2020


On 10 Feb 2020, at 6:27, Edward d'Auvergne wrote:

> I realise that F::Q is broken in some places.  As I said, I reported
> an issue.  However, as you have seen yourself, the F::Q developers are
> simply non-responsive.  I believe that asking all GnuCash users to
> manually patch their own Finance::Quote perl modules to get around
> this 2 year old issue is too much to ask of users.  My reasoning is
> that a little more logic on the GnuCash side to handle F::Q
> misbehaving is easier for all GnuCash users.  And, from the behaviour
> of the scripts below, I now wonder if GnuCash could benefit by
> switching from piping '(currency "USD" "EUR")' into gnc-fc-helper to
> instead piping in '(alphavantage "USDEUR")'?  The only disadvantage is
> that gold and silver quotes do not work via the fetch() interface with
> Alpha Vantage.

I think I understand now why we've been talking past each other.  There 
isn't any API in F::Q to fetch multiple currency quotes in one call.  
Instead it's a feature of AlphaVantage to treat exchange rates as if 
they were stock quotes and use the stock quote API to fetch them.  I 
wasn't aware that this existed.  I played with it for a few minutes and 
see a couple of problems with it.  Some currencies are not available 
using the stock quote API but are available using the currency API.  For 
example three in my list of currencies which don't work with the quote 
API are MNT, SBD, and VUV.  These all work fine with the currency API.

The other problem is that for very small exchange rates the stock quote 
interface loses precision.  For example, compare

./gnc-fq-dump alphavantage IDRUSD
Finance::Quote fields Gnucash uses:
     symbol: IDRUSD               <=== required
       date: 02/10/2020           <=== recommended
   currency: USD                  <=== required
       last: 0.0001               <=\
        nav:                      <=== one of these
      price:                      <=/
   timezone:                      <=== optional

and

./gnc-fq-dump currency IDR USD
1 IDR = 7.295e-05 USD

These problems would make the quote API for currencies less useful.

By the way, I didn't mean to suggest that we should encourage all users 
of GnuCash to patch F::Q.  I still remain hopeful that the maintainers 
will merge my pull request that fixes this bug.  In the meantime 
switching to the quote API might be a good idea even if it does have 
issues.  The code would have to be smart enough to work around the 
problems.  For example if the quote API fails for a given currency it 
could try the currency API.  If the returned value appears to have lost 
all precision then it could try the reverse quote and compute the 
reciprocal itself.

Another possibility would be to abandon AlphaVantage entirely for 
currency exchange rates.  For example https://currencylayer.com/ looks 
promising.  They allow up to 250 queries per month for free and it seems 
very fast.  Of course this would require changes to F::Q which gets us 
right back into those problems.

         Mike


More information about the gnucash-devel mailing list