bean-price Alphavantage example

108 views
Skip to first unread message

Aaron Axvig

unread,
Sep 17, 2024, 8:53:31 AM9/17/24
to bean...@googlegroups.com
Could someone provide an example of fetching a price using
Alphavantage? It is non-obvious to me:

bean-price -e 'USD:alphavantage/AAPL' -vv

INFO : Using price cache at "/tmp/bean-price.cache" (with indefinite
expiration)
INFO : Processing at date: 2024-09-17
INFO : Fetching: AAPL (time: None)
ERROR : Error fetching AAPL: Invalid ticker. Use "price:SYMBOL:BASE"
or "fx:CCY:BASE" format.
ERROR : Could not fetch for job: DatedPrice(base='AAPL', quote='USD',
date=None, sources=[PriceSource(module=<module
'beanprice.sources.alphavantage' from
'/home/aaron/beancount/venv/lib/python3.11/site-
packages/beanprice/sources/alphavantage.py'>, symbol='AAPL',
invert=False)])

Patrick Ruckstuhl

unread,
Sep 17, 2024, 12:30:13 PM9/17/24
to bean...@googlegroups.com

Hi,


sure, first you have to provide the api key as an environment variable

e.g. something like

export ALPHAVANTAGE_API_KEY=demo

and then call it like

bean-price -e 'USD:alphavantage/price:AAPL:USD' -vv

Regards,
Patrick

Aaron Axvig

unread,
Sep 17, 2024, 9:39:18 PM9/17/24
to bean...@googlegroups.com
Very strange, it just sits and does nothing after starting the HTTPS connection.  So that makes me wonder I have some other network problem, because I was using the Yahoo source on a different machine and that started hanging in a similar way a couple weeks ago.  I thought that was just Yahoo cutting everyone off. :)

(venv):~/beancount/venv/bin$ ./bean-price -e 'USD:alphavantage/price:AAPL:USD' -vv --cache cache.db
INFO : Using price cache at "cache.db" (with indefinite expiration)
INFO : Processing at date: 2024-09-17
INFO : Fetching: price:AAPL:USD (time: None)
DEBUG : Starting new HTTPS connection (1): www.alphavantage.co:443

The API key is set:

(venv):~/beancount/venv/bin$ printenv | grep ALPHA
ALPHAVANTAGE_API_KEY=snipped

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/74cd9006-f2d9-495d-85a9-2ece648429fc%40tario.org.

Patrick Ruckstuhl

unread,
Sep 18, 2024, 2:17:09 AM9/18/24
to bean...@googlegroups.com

Aaron Axvig

unread,
Sep 18, 2024, 9:40:07 PM9/18/24
to bean...@googlegroups.com
The direct URL returns a nice JSON with price data in it, instantly.

I let the bean-price command run for a while and it finished after a couple minutes.  I'll stew on it.

Patrick Ruckstuhl

unread,
Sep 19, 2024, 1:53:13 AM9/19/24
to bean...@googlegroups.com

one thing that is in the bean-price alphavantage importer is to deal with rate limit of alphavantage, if there is an issue with the request, it sleeps for 60 seconds and then tries again. Maybe you hit that one.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages