beancount.prices.sources.iex.IEXError: Invalid response (403): Forbidden

51 views
Skip to first unread message

matthew...@gmail.com

unread,
Jun 17, 2019, 1:20:00 PM6/17/19
to Beancount
I think something is wrong with the IEX asset pricing source.

Something like this:
2018-09-15 commodity UBER
  price
: "USD:iex/UBER"

Results in something like this:
Traceback (most recent call last):
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/shelve.py", line 111, in __getitem__
    value
= self.cache[key]
KeyError: '5f40c1783265eb0919e27627aed4d146'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/site-packages/beancount/prices/price.py", line 84, in fetch_cached_price
    timestamp_created
, result_naive = _CACHE[key]
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/shelve.py", line 113, in __getitem__
    f
= BytesIO(self.dict[key.encode(self.keyencoding)])
KeyError: b'5f40c1783265eb0919e27627aed4d146'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 
File "/nix/store/h5bpd5swkwcgxhz05aaj430qja3v04js-python3.7-beancount-2.2.1/bin/.bean-price-wrapped", line 5, in <module>
   
from beancount.prices.price import main; main()
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/site-packages/beancount/prices/price.py", line 369, in main
    price_entries
= sorted(price_entries, key=lambda e: e.currency)
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/concurrent/futures/_base.py", line 586, in result_iterator
   
yield fs.pop().result()
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/concurrent/futures/_base.py", line 432, in result
   
return self.__get_result()
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
   
raise self._exception
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result
= self.fn(*self.args, **self.kwargs)
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/site-packages/beancount/prices/price.py", line 159, in fetch_price
    srcprice
= fetch_cached_price(source, psource.symbol, dprice.date)
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/site-packages/beancount/prices/price.py", line 100, in fetch_cached_price
   
if time is None else
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/site-packages/beancount/prices/sources/iex.py", line 49, in get_latest_price
   
return fetch_quote(ticker)
 
File "/nix/store/bmq1vsmckm7vrfg4z0yyqb9jpddv6p6p-python3-3.7.3-env/lib/python3.7/site-packages/beancount/prices/sources/iex.py", line 30, in fetch_quote
    response
.text))
beancount
.prices.sources.iex.IEXError: Invalid response (403): Forbidden

What's the go-to price sources these days? I'm guessing that Yahoo and Google sources don't work anymore. What should I migrate to?

Patrick Ruckstuhl

unread,
Jun 17, 2019, 2:10:03 PM6/17/19
to bean...@googlegroups.com
Hi,

On 17.06.2019 19:20, matthew...@gmail.com wrote:
>
> What's the go-to price sources these days? I'm guessing that Yahoo and
> Google sources don't work anymore. What should I migrate to?


I'm using https://www.alphavantage.co/ they have a free offering and has
also data from different countries.


Regards,

Patrick


matthew...@gmail.com

unread,
Jun 18, 2019, 7:56:12 PM6/18/19
to Beancount
I don't see that in `beancount.prices.sources`. I only see `iex`, `oanda`, `quandl`, and `yahoo`. I'm on 2.2.1.


On Monday, June 17, 2019 at 2:10:03 PM UTC-4, Patrick Ruckstuhl wrote:
Hi,

Zhuoyun Wei

unread,
Jun 19, 2019, 11:51:12 AM6/19/19
to matthew...@gmail.com, Beancount
It seems that IEX stopped prividing non-IEX data:


https://iextrading.com/developer/docs/

https://iextrading.com/developer/#sunset-schedule

--
Zhuoyun Wei
> --
> 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 post to this group, send email to bean...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/beancount/33b31600-3304-405b-8eb1-9f983890caac%40googlegroups.com <https://groups.google.com/d/msgid/beancount/33b31600-3304-405b-8eb1-9f983890caac%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Patrick Ruckstuhl

unread,
Jun 19, 2019, 2:26:48 PM6/19/19
to bean...@googlegroups.com

Hi,

sorry, I was not clear on this. I created my own plugin, it depends on an environment variable ALPHAVANTAGE_API_KEY and only supports latest price


from beancount.prices import source
import datetime
from dateutil import tz
from dateutil.parser import parse
from beancount.core.number import D
import requests
from os import environ
from time import sleep

class Source(source.Source):
    def get_latest_price(self, ticker):
        params = {
            'function': 'GLOBAL_QUOTE',
            'symbol': ticker,
            'apikey': environ['ALPHAVANTAGE_API_KEY'],
        }

        resp = requests.get(url='https://www.alphavantage.co/query', params=params)
        data = resp.json()
        if 'Note' in data:
            sleep(60)
            resp = requests.get(url='https://www.alphavantage.co/query', params=params)
            data = resp.json()

        priceData = data['Global Quote']

        price = D(priceData['05. price'])
        date = parse(priceData['07. latest trading day'])

        us_timezone = tz.gettz("Europe/Zurich")
        time = date.astimezone(us_timezone)
        return source.SourcePrice(price, time, 'USD')

    def get_historical_price(self, ticker, time):
        return None

--
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 post to this group, send email to bean...@googlegroups.com.

Justus Pendleton

unread,
Jun 19, 2019, 10:07:46 PM6/19/19
to Beancount
On Tuesday, June 18, 2019 at 12:20:00 AM UTC+7, matthe...@gmail.com wrote:
What's the go-to price sources these days? I'm guessing that Yahoo and Google sources don't work anymore. What should I migrate to?

Yahoo works fine.
Reply all
Reply to author
Forward
0 new messages