FW: alphavantage quotes fix

Chris Good goodchris96 at gmail.com
Sun Apr 1 20:09:39 EDT 2018


Hi Steven,

 

You can but you should ask the gnucash-user email list first as many other people are interested, may have more available time and may have answers I don’t have.

 

Regards, Chris Good

 

From: Steven Anter <anter.s at gmail.com> 
Sent: Monday, 2 April 2018 9:26 AM
To: Chris Good <goodchris96 at gmail.com>; gnucash-user at gnucash.org
Subject: Re: FW: alphavantage quotes fix

 

Hi Chris,

 

Applied your patches and AlphaVantage worked. For now at least.  If I have future issues, may I contact you?  

 


 <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon> 

Virus-free.  <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link> www.avast.com 

 

On Sat, Mar 31, 2018 at 9:49 PM, Chris Good <goodchris96 at gmail.com <mailto:goodchris96 at gmail.com> > wrote:

Hi Steven,

 

Please see my mail below but get the Quote.pm + AlphaVantage.pm from Mike Alexander’s git hub instead of mine as he has also put the 1 second delay between each request for a currency and you will need that. 

 

Get from Quote.pm from

https://raw.githubusercontent.com/mtalexander/finance-quote/6ee43ea08b504617142139fda41ae45be865fa38/lib/Finance/Quote.pm

 

Get AlphaVantage.pm from

https://github.com/mtalexander/finance-quote/blob/6ee43ea08b504617142139fda41ae45be865fa38/lib/Finance/Quote/AlphaVantage.pm

 

Regards,

 

Chris Good

 

From: Chris Good <goodchris96 at gmail.com <mailto:goodchris96 at gmail.com> > 
Sent: Sunday, 18 March 2018 6:54 PM
To: finance-quote-devel at lists.sourceforge.net <mailto:finance-quote-devel at lists.sourceforge.net> 
Cc: lordpaul123 at gmail.com <mailto:lordpaul123 at gmail.com> 
Subject: RE: alphavantage quotes fix 

 

Message: 1 
Date: Sat, 3 Mar 2018 07:49:34 -0600 
From: Paul Bates <lordpaul123 at gmail.com <mailto:lordpaul123 at gmail.com> > 
To: finance-quote-devel at lists.sourceforge.net <mailto:finance-quote-devel at lists.sourceforge.net>  
Subject: [Finance-quote-devel] alphavantage quotes fix 
Message-ID: 
<CAL7gLaFOitANVhwRVTMoPY5oDNZwGJBdzKfwZTusDdb4GaJ7Qw at mail.gmail.com <mailto:CAL7gLaFOitANVhwRVTMoPY5oDNZwGJBdzKfwZTusDdb4GaJ7Qw at mail.gmail.com> > 
Content-Type: text/plain; charset="utf-8" 

I have been using the alphavantage module with gnucash to get quotes for 
stocks.  The list is well over 40, so it has become nonfunctional in the 
last couple of months.  I am not a perl programmer, so the fix took several 
hours and more cups of coffee.  I hope a perl programmer can add error 
checks and possibly while loops to catch the occasional double message. 
Currently It seems to miss one or two stocks on the list. 

In alphavantage.pm <http://alphavantage.pm>    I inserted the following code in the sub alphavantage : 

        my $code = $reply->code; 
        my $desc = HTTP::Status::status_message($code); 
        my $body = $reply->content; 
        if ($code != 200) { 
            $info{ $stock, 'success' } = 0; 
            $info{ $stock, 'errormsg' } = $desc; 
            next; 
        } 

        my $json_data; 
        eval {$json_data = JSON::decode_json $body}; 

################################################# 
### Insert 
################################################# 
        # attempt to handle the Information message 
        if ( $json_data->{'Information'} ) { 
           sleep (20); 
           $reply = $ua->request( GET $url); 
           $code = $reply->code; 
           $desc = HTTP::Status::status_message($code); 
           $body = $reply->content; 
           eval {$json_data = JSON::decode_json $body}; 
        } 
################################################### 

        if ($@) { 
            $info{ $stock, 'success' } = 0; 
            $info{ $stock, 'errormsg' } = $@; 
        } 

I am sure there are better ways to handle this, but I am not used to the 
developers lists and hate to leave alphavantage being blamed for a problem 
that is not theirs. 

Paul Bates 

Hi Paul,

 

I have modified AlphaVantage.pm as you requested.

If it fails with an Information message, it will try again 4 times, with a 20 second delay between each try.

It tests OK for me but I don’t usually use AlphaVantage and it has never failed with an Information message for me, so can you please get my code from

https://github.com/goodvibes2/finance-quote/blob/FqIss83AlphaVantage/lib/Finance/Quote/AlphaVantage.pm

and test it?

 

After you test it, I will create a Pull Request to get this change incorporated in Finance::Quote.

 

Just for completeness, can you tell us what is in the Information messages you are getting?

 

Regards, Chris Good

 



More information about the gnucash-user mailing list