Finance-Quote 1.47 Unable to retrieve Currency quotes

Richard Morris sgtzeno5 at gmail.com
Thu Feb 22 10:01:07 EST 2018


Cunning stuff Adriano!

Here's someone else finding that implementing a delay doesn't seem to work:
https://www.alpha-vantage.community/post/how-to-reduce-api-call-frequency-tried-up-to-sleep80-between-curls-but-still-hitting-9655828

I suspect it's throttled on the basis of 'x requests allowed from the same
IP address within y minutes', or some such (where x and y are now very low
values!).

However the block only seems to last a short while. So one way around it
might be to fiddle with Quote.pm and test the Perl::LWP response, If it's,
say "200" and the response content contains their 'contact support'
message, then sleep() for say 2 minutes.

But then what are we doing here? Trying to game their system? Doesn't seem
the right way forward...

Best

Richard
(Perl fan)


On 22 February 2018 at 14:39, Adriano Baldi <adriano.baldi at gmail.com> wrote:

> Hello Richard
>
> You can't introduce a delay in Gnucash but you can modify the
> Finance::Quote module that Gnucash use.
> For the currency is Quote.pm (for me is in  /usr/local/share/perl/5.22.1/Finance/
> ) and I try tho chance it :
>
>
> ........
>
> # =======================================================================
> # currency (public object method)
> #
> # currency allows the conversion of one currency to another.
> #
> # Usage: $quoter->currency("USD","AUD");
> #  $quoter->currency("15.95 USD","AUD");
> #
> # undef is returned upon error.
>
> sub currency {
>   my $this = shift if (ref($_[0]));
>   $this ||= _dummy();
>
>   my ($from, $to) = @_;
>   return undef unless ($from and $to);
>
>   $from =~ s/^\s*(\d*\.?\d*)\s*//;
>   my $amount = $1 || 1;
>
>   # Don't know if these have to be in upper case, but it's
>   # better to be safe than sorry.
>   $to = uc($to);
>   $from = uc($from);
>
>   return $amount if ($from eq $to); # Trivial case.
>
>   my $ua = $this->user_agent;
>
>   my $ALPHAVANTAGE_API_KEY = $ENV{'ALPHAVANTAGE_API_KEY'};
>   return undef unless ( defined $ALPHAVANTAGE_API_KEY );
> #------------------------------------ change start ----------------------
>
>
>
>
> *my $key_n=0;  sleep 1;   # This introduce a 1s delay  $key_n =
> int(rand(10));  # Select randomly one of the following API key (change the
> keys with your keys)*
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *  if($key_n == 0)  {$ALPHAVANTAGE_API_KEY="xxxxxx_KEY_00_xxxxxx"};
> if($key_n == 1)  {$ALPHAVANTAGE_API_KEY="xxxxxx_KEY_01_xxxxxx"};
> if($key_n == 2)  {$ALPHAVANTAGE_API_KEY="xxxxxx_KEY_02_xxxxxx"};
> if($key_n == 3)  {$ALPHAVANTAGE_API_KEY="xxxxxx_KEY_03_xxxxxx"};
> if($key_n == 4)  {$ALPHAVANTAGE_API_KEY="xxxxxx_KEY_04_xxxxxx"};
> if($key_n == 5)  {$ALPHAVANTAGE_API_KEY="xxxxxx_KEY_05_xxxxxx"};
> if($key_n == 6)  {$ALPHAVANTAGE_API_KEY="xxxxxx_KEY_06_xxxxxx"};
> if($key_n == 7)  {$ALPHAVANTAGE_API_KEY="xxxxxx_KEY_07_xxxxxx"};
> if($key_n == 8)  {$ALPHAVANTAGE_API_KEY="xxxxxx_KEY_08_xxxxxx"};
> if($key_n == 9)  {$ALPHAVANTAGE_API_KEY="xxxxxx_KEY_09_xxxxxx"};
> if($key_n == 10) {$ALPHAVANTAGE_API_KEY="xxxxxx_KEY_10_xxxxxx"};*  my
> $reply = $ua->request(GET "${ALPHAVANTAGE_CURRENCY_URL}"
>     . "&from_currency=" . ${from}
>     . "&to_currency=" . ${to}
>     . "&apikey=" . ${ALPHAVANTAGE_API_KEY} );
>
>
> *# This print the request, and you can see the key used*
>
>
>
>
>
>
>
>
> *  print "${ALPHAVANTAGE_CURRENCY_URL}"    . "&from_currency=" .
> ${from}    . "&to_currency=" . ${to}    . "&apikey=" .
> ${ALPHAVANTAGE_API_KEY}."\n";  print
> $reply;#------------------------------------ change end
> ----------------------*
> if you run  *gnc-fq-dump currency usd eur  *you are able to test it
> outside Gnucash.
> This apply a request every 0,1s  but the delay inside the module (*sleep
> 1; *) decide the real frequency and you can change it.
>
> root at ASUS-N56VZ:/usr/local/share/perl/5.22.1/Finance# *watch -n 0
> gnc-fq-dump currency usd eur*
> https://www.alphavantage.co/query?function=CURRENCY_
> EXCHANGE_RATE&from_currency=USD&to_currency=EUR&apikey=xxxxxxxxxxxxxxxxxxx
> HTTP::Response=HASH(0x42eb5a0)1 usd = 0.812089 eur
>
> The problem it's than after two polling, same time the download fail.
>
> Best regard
>
>            Adriano
>
>
>
> 2018-02-22 9:47 GMT+01:00 Richard Morris <sgtzeno5 at gmail.com>:
>
>> Sorry I couldn't reply to this before Adriano - I've been finding using
>> this list a bit too difficult for me! (A confusion between my @gmail and
>> @googlemail email domain identities)
>>
>> I think you are probably on to something in trying to throttle your
>> requests. But may I ask - how are you adding the delay? Where is the
>> setting in GNUCash for that?
>>
>> I have about 35 stocks to check, of which about 7 or 8 are in USD etc. I
>> run "gnucash --add-price-quotes" on the hour as a cron job. I wouldn't have
>> thought that was too demanding on Alphavantage. But then - how many of us
>> are making requests to them via GNUCash?
>>
>> Best
>>
>> Richard
>>
>> On 20 February 2018 at 11:47, Adriano Baldi <adriano.baldi at gmail.com>
>> wrote:
>>
>>> Hello Richard
>>>
>>> After doing countless tests I think that the problem is related to the
>>> management of the demands of Alphavantage.
>>> But I can not figure out where we are wrong.
>>> These are the declared performances:
>>>
>>> *>> What is the expected server-side performance (e.g., throughput time)
>>> for the API service?*
>>>
>>> *>> Based on the latest instrumentation, the throughput time for our API
>>> endpoint is under 500 milliseconds per request at 25% to 75% percentile. *
>>>
>>> *>> While we are proud to provide free API service with no
>>> daily/weekly/monthly call limits, we recommend that API call frequency does
>>> not extend far beyond ~1 call per second *
>>>
>>> *>> so that we can continue to deliver the optimal server-side
>>> performance.*
>>>
>>> So I tried to put a delay between one request and another of 1 or more
>>> seconds, with no result.
>>> In addition I tried to ensure that for each request was used a different
>>> key, randomly chosen among 10 keys, even here without result.
>>>
>>> I need new idea to test.
>>>
>>> Best regards
>>>
>>> Adriano
>>>
>>>
>>> 2018-02-20 9:28 GMT+01:00 Richard Morris <sgtzeno5 at googlemail.com>:
>>>
>>>> I have this problem too (starting yesterday). I was going to do a post
>>>> - then, late in the day, the problem went away! But now it's back again.
>>>>
>>>> I wonder if this is a connectivity issue with whatever GNUCash uses for
>>>> currency sources? (This is hard-wired I think, and I'm not sure what that
>>>> is).
>>>>
>>>> I'm on Ubuntu too: GnuCash 2.6.17 + Ubuntu 17.10 + Finance::Quote 1.47
>>>>
>>>>
>>>> On Tue, Feb 20, 2018 at 6:09 AM, Adriano Baldi <adriano.baldi at gmail.com
>>>> > wrote:
>>>>
>>>>> Hello
>>>>>
>>>>> I apologize for my poor English.
>>>>>
>>>>> I use GnuCash since 2011 and usually I am able to solve this kind of
>>>>> problem by myself if necessary modifing the perl files of
>>>>> Finance::Quote.
>>>>> But now I'm going crazy with this problem.
>>>>>
>>>>> I've got this error since february 14 on two different PC with Ubuntu
>>>>> 14.04
>>>>> and 16.04 with GnuCash 2.6.12 and Finance::Quote 1.47.
>>>>>
>>>>> Unable to retrieve quotes for these items:
>>>>>   CURRENCY:XAU
>>>>>   CURRENCY:XPT
>>>>>   CURRENCY:XAG
>>>>>   CURRENCY:NZD
>>>>>   CURRENCY:CAD
>>>>>   CURRENCY:AUD
>>>>>   CURRENCY:CHF
>>>>>   CURRENCY:CNY
>>>>>   CURRENCY:RUB
>>>>>   CURRENCY:DKK
>>>>>   CURRENCY:NOK
>>>>>   CURRENCY:GBP
>>>>>   CURRENCY:USD
>>>>>   CURRENCY:JPY
>>>>> Continue using only the good quotes?
>>>>>
>>>>> If I try from the consolle Finance::Quote work fine
>>>>>
>>>>> $ gnc-fq-dump currency USD EUR
>>>>> 1 USD = 0.805969 EUR
>>>>>
>>>>> $ gnc-fq-dump currency XAU EUR
>>>>> 1 XAU = 1085.3924262 EUR
>>>>>
>>>>> $ gnc-fq-check
>>>>> ("1.47" "adig" "aex" "aiahk" "alphavantage" "amfiindia" "asegr" "asia"
>>>>> "asx" "australia" "bamosz" "bet" "bmonesbittburns" "bourso" "brasil"
>>>>> "bse"
>>>>> "bsero" "canada" "canadamutual" "citywire" "cominvest" "cse" "deka"
>>>>> "dutch"
>>>>> "dwsfunds" "europe" "fetch_live_currencies" "fidelity"
>>>>> "fidelity_direct"
>>>>> "fidelityfixed" "financecanada" "finanzpartner" "finland" "fool"
>>>>> "france"
>>>>> "ftfunds" "ftportfolios" "ftportfolios_direct" "fundlibrary"
>>>>> "goldmoney"
>>>>> "greece" "hex" "hu" "hufund" "hungary" "hustock" "indiamutual"
>>>>> "known_currencies" "lerevenu" "maninv" "morningstar" "morningstarjp"
>>>>> "mstaruk" "nasdaq" "nyse" "nz" "nzx" "platinum" "romania" "seb_funds"
>>>>> "sixfunds" "sixshares" "stockhousecanada_fund" "tdefunds"
>>>>> "tdwaterhouse"
>>>>> "tiaacref" "tnetuk" "troweprice" "troweprice_direct" "trustnet" "tsp"
>>>>> "tsx"
>>>>> "uk_unit_trusts" "ukfunds" "unionfunds" "usa" "usfedbonds" "vanguard"
>>>>> "vwd"
>>>>> "yahoo" "yahoo_asia" "yahoo_australia" "yahoo_brasil" "yahoo_europe"
>>>>> "yahoo_json" "yahoo_nz" "yahoo_yql" "za" "za_unittrusts")
>>>>>
>>>>> I don't know if this problem afflict only me (I hope so) or if others
>>>>> have
>>>>> the same problem.
>>>>> The problem afflicts only the currency with continuity, on some stocks
>>>>> I
>>>>> can have the problem occasionally, but generally a second download work
>>>>> fine.
>>>>> I retreive more of 40 stocks from 6 excange with no problem using
>>>>> Alphavantage.
>>>>> Does anyone have an idea from what can be determined?
>>>>> Does anyone have a suggestion to give me to solve this problem?
>>>>> Thanks in advance to anyone who can help me.
>>>>>
>>>>> Best regards
>>>>>
>>>>>                 Adriano
>>>>> _______________________________________________
>>>>> gnucash-user mailing list
>>>>> gnucash-user at gnucash.org
>>>>> To update your subscription preferences or to unsubscribe:
>>>>> https://lists.gnucash.org/mailman/listinfo/gnucash-user
>>>>> If you are using Nabble or Gmane, please see
>>>>> https://wiki.gnucash.org/wiki/Mailing_Lists for more information.
>>>>> -----
>>>>> Please remember to CC this list on all your replies.
>>>>> You can do this by using Reply-To-List or Reply-All.
>>>>>
>>>>
>>>>
>>>
>>>
>>
>


More information about the gnucash-user mailing list