Price quotes fetcher for Beancount
Project description
beanprice: Price quotes fetcher for Beancount
Description
A script to fetch market data prices from various sources on the internet and render them for plain text accounting price syntax (and Beancount).
This used to be located within Beancount itself (at v2) under beancount.prices. This repo will contain all future updates to that script and to those price sources.
Documentation
Some documentation is still part of Beancount. More about how to use this can be found on that mailing-list. Otherwise read the source.
Quick start
To install beanprice, run:
pip install git+https://github.com/beancount/beanprice.git
You can fetch the latest price of a stock by running:
bean-price -e 'USD:yahoo/AAPL'
To fetch the latest prices from your beancount file, first ensure that commodities have price metadata, e.g.
2000-01-01 commodity AAPL
price: "USD:yahoo/AAPL"
Then run:
bean-price ledger.beancount
To update prices up to the present day, run:
bean-price --update ledger.beancount
For more detailed guide for price fetching, read https://beancount.github.io/docs/fetching_prices_in_beancount.html.
Price source info
The following price sources are available:
| Name | Module | Provides prices for | Base currency | Latest price? | Historical price? |
|---|---|---|---|---|---|
| Alphavantage | beanprice.alphavantage |
Stocks, FX, Crypto | Many currencies | ✓ | ✕ |
| Coinbase | beanprice.coinbase |
Most common (crypto)currencies | Many currencies | ✓ | ✓ |
| Coincap | beanprice.coincap |
Most common (crypto)currencies | USD | ✓ | ✓ |
| Coinmarketcap | beanprice.coinmarketcap |
Most common (crypto)currencies | Many Currencies | ✓ | ✕ |
| European Central Bank API | beanprice.ecbrates |
Many currencies | Many currencies (Derived from EUR rates) | ✓ | ✓ |
| IEX | beanprice.iex |
Trading symbols | USD | ✓ | 🚧 (Not yet!) |
| OANDA | beanprice.oanda |
Many currencies | Many currencies | ✓ | ✓ |
| Quandl | beanprice.quandl |
Various datasets | Various datasets | ✓ | ✓ |
| Rates API | beanprice.ratesapi |
Many currencies | Many currencies | ✓ | ✓ |
| Thrift Savings Plan | beanprice.tsp |
TSP Funds | USD | ✓ | ✓ |
| Yahoo | beanprice.yahoo |
Many currencies | Many currencies | ✓ | ✓ |
| EastMoneyFund(天天基金) | beanprice.eastmoneyfund |
Chinese Funds | CNY | ✓ | ✓ |
More price sources can be found at awesome-beancount.com website.
Creating a custom price source
To create a price source, create a package (i.e. my_package) with a module (i.e. my_module) that contains the Source class which inherits from the beanprice.Source class:
from beanprice import source
class Source(source.Source):
def get_latest_price(self, ticker) -> source.SourcePrice | None:
pass
def get_historical_price(self, ticker, time):
pass
Implement the logic for fetching the prices. At a minimum, the get_latest_price() is required.
Then use your price source in the commodities
1900-01-01 commodity XYZ
price: "AUD:my_package.my_module/XYZ"
AUD just being an example of a currency specification.
Testing
Run tests:
pytest beanprice
Lint:
pylint beanprice
Type checker:
mypy beanprice
Copyright and License
Copyright (C) 2007-2020 Martin Blais. All Rights Reserved.
This code is distributed under the terms of the "GNU GPLv2 only". See COPYING file for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file beanprice-2.1.0.tar.gz.
File metadata
- Download URL: beanprice-2.1.0.tar.gz
- Upload date:
- Size: 55.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d90d26641f7baed8443cdfdb5545c38f8d01f97604ed4ad4173b023598982b13
|
|
| MD5 |
33448d5bd7b8b9323ecca739330b97e9
|
|
| BLAKE2b-256 |
06b5414ad3d4b5a7db87e8ee7aca5bcf7d88828622a39c03c46375b44a7de018
|
File details
Details for the file beanprice-2.1.0-py3-none-any.whl.
File metadata
- Download URL: beanprice-2.1.0-py3-none-any.whl
- Upload date:
- Size: 70.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d99ee65e216086994394624f2be89e8733d261a611686e54de268ce9e6d7f68
|
|
| MD5 |
7caa4fb86a721c80499fbe95dab523a1
|
|
| BLAKE2b-256 |
0a21636de4fcfb73e4452801f06a8868be0633797c0cf7b4119cac3ae94682a0
|