I'm glad you're looking at this since it does need some work. However I think there are a couple of things you're not aware of. I, too, have quite a ffew currencies in my file (around 30) and by coincidence I was running a price fetch in the background when I first saw your message. It completed successfully after fetching all currency quotes as usual.

You're right that GnuCash fetches one currency per call, but this is the only API for currencies that F::Q provides. It fetches all the other quotes for a given source in one call to F::Q. The F::Q currency quote code has a test for the rate limiting message that AlphaVantage returns when currency quote fetches come too fast. However at some time in the past AlphaVantage changed this message. I updated F::Q to look for the new message and sent a pull request upstream. This pul request has never been applied which means that the current F::Q does not recognize when AlphaVantage is trying to tell it to slow down. My copy of F::Q has this change which is probably why it works for me and not for you.

The patch is simple, just change it to look for a "Note" field in the returned data instead of an "Information" field.

Try this and see if it helps.

Your change to make GnuCash handle F::Q failures better seems like a good idea. Putting the delay on GnuCash's side of the API might also be a good idea, but really shouldn't be necessary. It also would be a problem for someone who has actually paid for an AlphaVantage subscription and hence can get currency quotes faster. Some day I hope that F::Q will find a currency quote source that works better and faster at which time you wouldn't want the delay in GnuCash.

        Mike

diff --git a/lib/Finance/Quote.pm b/lib/Finance/Quote.pm
index b66bca9..6703935 100644
--- lib/Finance/Quote.pm
+++ lib/Finance/Quote.pm
@@ -274,9 +274,9 @@ sub currency {
     if ( !$json_data || $json_data->{'Error Message'} ) {
       return undef;
     }
-# print "Failed: " . $json_data->{'Information'} . "\n" if (($try_cnt < 5) && ($json_data->{'Information'}));
-    sleep (20) if (($try_cnt < 5) && ($json_data->{'Information'}));
-  } while (($try_cnt < 5) && ($json_data->{'Information'}));
+# print "Failed: " . $json_data->{'Note'} . "\n" if (($try_cnt < 5) && ($json_data->{'Note'}));
+    sleep (20) if (($try_cnt < 5) && ($json_data->{'Note'}));
+  } while (($try_cnt < 5) && ($json_data->{'Note'}));

my $exchange_rate = $json_data->{'Realtime Currency Exchange Rate'}->{'5. Exchange Rate'};

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

Reply via email to