I have a Perl script that uses Finance::Quote to fetch quotes for a few stocks and mutual funds I’m interested in and store them in a SQLite database. I run this in a cron job, and it had been working fine for nearly 5 years. On November 1 it suddenly stopped working. It turned out that the module defaulted to using Yahoo for its quotes, and they’d decided to no longer allow the module to access its data.
This led to a flurry of discussions online and quite a few updates to the module. After a week or two it settled down and I read that they’d switched to using a service called AlphAdvantage. Unfortunately my script still wasn’t working, nor were the example scripts in the module documentation.
Finally tonight I decided to see if I could get it working. I downloaded and built the latest version of Finance::Quote (1.47) from source. It has a test called alphavantage.t, and its tests passed! I compared its code to mine and finally got it working again. Here’s what I did:
Went to the Alphavantage web site and got a free API key.
I stored the key in an environment variabled named ALPHAVANTAGE_API_KEY:
export ALPHAVANTAGE_API_KEY=##########If you’re doing this yourself, you’ll need to replace “##########” with your actual API key, and add that export to wherever you set your other environment variables (possibly ~/.bashrc).
My previous code looked like this:
1 2 3 4 5 6 7 8 | |
I had to change lines 4 and 6:
1 2 3 4 5 6 7 8 | |
That’s it! It took a bit of digging to find it, but the actual change was pretty simple. Hopefully the module developers will eventually get around to updating their documentation.