beancount.prices.sources

Implementation of various price extractors.

This package is looked up by the driver script to figure out which extractor to use.

beancount.prices.sources.iex

Fetch prices from the IEX 1.0 public API.

This is a really fantastic exchange API with a lot of relevant information.

Timezone information: There is currency no support for historical prices. The output datetime is provided as a UNIX timestamp.

exception beancount.prices.sources.iex.IEXError

An error from the IEX API.

class beancount.prices.sources.iex.Source

IEX API price extractor.

get_historical_price(ticker, time)

See contract in beancount.prices.source.Source.

get_latest_price(ticker)

See contract in beancount.prices.source.Source.

beancount.prices.sources.iex.fetch_quote(ticker)

Fetch

beancount.prices.sources.oanda

A source fetching currency prices from OANDA.

Valid tickers are in the form “XXX_YYY”, such as “EUR_USD”.

Here is the API documentation: https://developer.oanda.com/rest-live/rates/

For example: https://api-fxtrade.oanda.com/v1/candles?instrument=EUR_USD&granularity=D&start=2016-03-27T00%3A00%3A00Z&end=2016-04-04T00%3A00%3A00Z&candleFormat=midpoint

Timezone information: Input and output datetimes are specified via UTC timestamps.

class beancount.prices.sources.oanda.Source

OANDA price source extractor.

get_historical_price(ticker, time)

See contract in beancount.prices.source.Source.

get_latest_price(ticker)

See contract in beancount.prices.source.Source.

beancount.prices.sources.quandl

Fetch prices from Quandl’s simple URL-based API.

Quandl is a useful source of alternative data and it offers a simple REST API that serves CSV and JSON and XML formats. There’s also a Python client library, but we specifically avoid using that here, in order to keep Beancount dependency-free.

Many of the datasets are freely available, which is why this is included here. You can get information about the available databases and associated lists of symbols you can use here: https://www.quandl.com/search

If you have a paid account and would like to be able to access the premium databases from the Quandl site, you can set QUANDL_API_KEY environment variable.

Use the “<DATABASE_CODE>:<DATASET_CODE>” format to refer to Quandl symbols. Note that their symbols are usually identified by “<DATABASE_CODE>/<DATASET_CODE>”.

(For now, this supports only the Time-Series API. There is also a Tables API, which could easily get integrated. We would just have to encode the ‘datatable_code’ and ‘format’ and perhaps other fields in the ticker name.)

Timezone information: Input and output datetimes are limited to dates, and I believe the dates are presumed to live in the timezone of each particular data source. (It’s unclear, not documented.)

exception beancount.prices.sources.quandl.QuandlError

An error from the Quandl API.

class beancount.prices.sources.quandl.Source

Quandl API price extractor.

get_historical_price(ticker, time)

See contract in beancount.prices.source.Source.

get_latest_price(ticker)

See contract in beancount.prices.source.Source.

beancount.prices.sources.quandl.fetch_time_series(ticker, time=None)

Fetch

beancount.prices.sources.quandl.parse_ticker(ticker)

Convert ticker to Quandl codes.

beancount.prices.sources.yahoo

Fetch prices from Yahoo Finance’s CSV API.

As of lated 2017, the older Yahoo finance API deprecated. In particular, the ichart endpoint is gone, and the download endpoint requires a cookie (which could be gotten - here’s some documentation for that http://blog.bradlucas.com/posts/2017-06-02-new-yahoo-finance-quote-download-url/).

We’re using both the v7 and v8 APIs here, both of which are, as far as I can tell, undocumented:

https://query1.finance.yahoo.com/v7/finance/quote https://query1.finance.yahoo.com/v8/finance/chart/SYMBOL

Timezone information: Input and output datetimes are specified via UNIX timestamps, but the timezone of the particular market is included in the output.

class beancount.prices.sources.yahoo.Source

Yahoo Finance CSV API price extractor.

get_historical_price(ticker, time)

See contract in beancount.prices.source.Source.

get_latest_price(ticker)

See contract in beancount.prices.source.Source.

exception beancount.prices.sources.yahoo.YahooError

An error from the Yahoo API.

beancount.prices.sources.yahoo.parse_currency(result)

Infer the currency from the result.

Return type

str

beancount.prices.sources.yahoo.parse_response(response)

Process as response from Yahoo.

Raises

YahooError – If there is an error in the response.

Return type

Dict