A command-line tool for fetching and formatting historical price data, with support for multiple data sources and output formats.
Find a file
2021-07-01 13:56:39 +02:00
src/pricehist Normalize symbols (to upper case). Output symbols returned by coinmarketcap. 2021-06-17 13:42:06 +02:00
tests After running Black. 2021-04-20 20:41:58 +02:00
.flake8 Add Black, isort and flake8. 2021-04-20 20:41:58 +02:00
.gitignore Tidy for publishing. 2021-06-03 10:39:10 +02:00
LICENSE Rename and switch to poetry. 2021-02-28 15:21:56 +01:00
Makefile Add Black, isort and flake8. 2021-04-20 20:41:58 +02:00
poetry.lock Log requests as curls. 2021-05-27 16:31:05 +02:00
pyproject.toml Bump version. 2021-06-03 10:42:19 +02:00
README.md README update. 2021-07-01 13:56:39 +02:00

pricehist

A command-line tool for fetching and formatting historical price data, with support for multiple data sources and output formats.

Installation

Install via pipx:

pipx install pricehist

Sources

Output formats

Examples

Show usage information:

pricehist -h
usage: pricehist [-h] [--version] [--verbose] {sources,source,fetch} ...

Fetch historical price data

optional arguments:
  -h, --help              show this help message and exit
  --version               show version information
  --verbose               show all log messages

commands:
  {sources,source,fetch}
    sources               list sources
    source                show source details
    fetch                 fetch prices

Fetch prices after 2021-01-04, ending 2021-01-15, as CSV:

pricehist fetch ecb EUR/AUD -sx 2021-01-04 -e 2021-01-15 -o csv
date,base,quote,amount,source,type
2021-01-05,EUR,AUD,1.5927,ecb,reference
2021-01-06,EUR,AUD,1.5824,ecb,reference
2021-01-07,EUR,AUD,1.5836,ecb,reference
2021-01-08,EUR,AUD,1.5758,ecb,reference
2021-01-11,EUR,AUD,1.5783,ecb,reference
2021-01-12,EUR,AUD,1.5742,ecb,reference
2021-01-13,EUR,AUD,1.5734,ecb,reference
2021-01-14,EUR,AUD,1.5642,ecb,reference
2021-01-15,EUR,AUD,1.568,ecb,reference

In Ledger format:

pricehist fetch ecb EUR/AUD -s 2021-01-01 -o ledger | head
P 2021-01-04 00:00:00 EUR 1.5928 AUD
P 2021-01-05 00:00:00 EUR 1.5927 AUD
P 2021-01-06 00:00:00 EUR 1.5824 AUD
P 2021-01-07 00:00:00 EUR 1.5836 AUD
P 2021-01-08 00:00:00 EUR 1.5758 AUD
P 2021-01-11 00:00:00 EUR 1.5783 AUD
P 2021-01-12 00:00:00 EUR 1.5742 AUD
P 2021-01-13 00:00:00 EUR 1.5734 AUD
P 2021-01-14 00:00:00 EUR 1.5642 AUD
P 2021-01-15 00:00:00 EUR 1.568 AUD

Generate SQL for a GnuCash database and apply it immediately:

pricehist fetch ecb EUR/AUD -s 2021-01-01 -o gnucash-sql | sqlite3 Accounts.gnucash
pricehist fetch ecb EUR/AUD -s 2021-01-01 -o gnucash-sql | mysql -u username -p -D databasename
pricehist fetch ecb EUR/AUD -s 2021-01-01 -o gnucash-sql | psql -U username -d databasename -v ON_ERROR_STOP=1

Design choices

To keep things simple, at least for now, pricehist provides only univariate time series of daily historical prices. It doesn't provide other types of market, financial or economic data, real-time prices, or other temporal resolutions. Multiple or multivariate series require multiple invocations.

Alternatives

Beancount's bean-price tool fetches prices and addresses other workflow concerns in a Beancount-specific manner, generally requiring a Beancount file as input.

The Piecash library is a pythonic interface to GnuCash files stored in SQL. It has a Commodity.update_prices method that can fetch historical prices.

The GnuCash wiki documents wrapper scripts for the Finance::QuoteHist Perl module.

Other projects with related goals include:

  • hledger-stockquotes: A CLI addon for hledger that reads a journal file and pulls the historical prices for commodities from AlphaVantage.
  • ledger_get_prices: Uses Yahoo finance to intelligently generate a ledger price database based on your current ledger commodities and time period.
  • LedgerStockUpdate: Locates any stocks you have in your ledger-cli file, then generates a price database of those stocks.
  • market-prices: Downloads market values of commodities from a few different sources.