Skip to main content

Fetch and format historical price data

Project description

pricehist

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

Installation

Install via pip or pipx:

pipx install pricehist

Sources

Output formats

Examples

Show usage information:

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

Fetch historical price data

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

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

Show usage information for the fetch command:

pricehist fetch -h
usage: pricehist fetch SOURCE PAIR [-h] [-vvv] [-t TYPE] [-s DATE | -sx DATE] [-e DATE | -ex DATE]
[-o beancount|csv|gnucash-sql|ledger] [--invert] [--quantize INT]
[--fmt-base SYM] [--fmt-quote SYM] [--fmt-time TIME] [--fmt-decimal CHAR] [--fmt-thousands CHAR]
[--fmt-symbol rightspace|right|leftspace|left] [--fmt-datesep CHAR] [--fmt-csvdelim CHAR]

positional arguments:
  SOURCE                   the source identifier
  PAIR                     pair, usually BASE/QUOTE, e.g. BTC/USD

optional arguments:
  -h, --help               show this help message and exit
  -vvv, --verbose          show all log messages
  -t TYPE, --type TYPE     price type, e.g. close
  -s DATE, --start DATE    start date, inclusive (default: source start)
  -sx DATE, --startx DATE  start date, exclusive
  -e DATE, --end DATE      end date, inclusive (default: today)
  -ex DATE, --endx DATE    end date, exclusive
  -o FMT, --output FMT     output format (default: csv)
  --invert                 invert the price, swapping base and quote
  --quantize INT           round to the given number of decimal places
  --fmt-base SYM           rename the base symbol in output
  --fmt-quote SYM          rename the quote symbol in output
  --fmt-time TIME          set a particular time of day in output (default: 00:00:00)
  --fmt-decimal CHAR       decimal point in output (default: '.')
  --fmt-thousands CHAR     thousands separator in output (default: '')
  --fmt-symbol LOCATION    commodity symbol placement in output (default: rightspace)
  --fmt-datesep CHAR       date separator in output (default: '-')
  --fmt-csvdelim CHAR      field delimiter for CSV output (default: ',')

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 which has a Commodity.update_prices method for fetching 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.
  • ledger_get_prices: Uses Yahoo Finance to generate a 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pricehist-0.1.6.tar.gz (35.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pricehist-0.1.6-py3-none-any.whl (40.8 kB view details)

Uploaded Python 3

File details

Details for the file pricehist-0.1.6.tar.gz.

File metadata

  • Download URL: pricehist-0.1.6.tar.gz
  • Upload date:
  • Size: 35.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.6 Linux/5.12.14-arch1-1

File hashes

Hashes for pricehist-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a6ebeb42269eca99014584a5a8250eef76a4fc8b3ae7bfb25be84fd8f749aabd
MD5 2066b49a4596130b9a499f108b81879f
BLAKE2b-256 54657b8b33198205adee2b1f9425cce5b9c0babf8af1b565e9365eee10ec0548

See more details on using hashes here.

File details

Details for the file pricehist-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: pricehist-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 40.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.6 Linux/5.12.14-arch1-1

File hashes

Hashes for pricehist-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4c83147484de265e90f0e164e162aacacd45c18e5614dd803ebf976e444d7f6f
MD5 e2a2847a28179093d69267bd9ef61658
BLAKE2b-256 a3898aff4186145e9dcb0b3e471f74ecd3b293c13658be0398f61a247e8c0abd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page