| 1 | # beanprice: Price quotes fetcher for Beancount |
| 2 | |
| 3 | ## Description |
| 4 | |
| 5 | A script to fetch market data prices from various sources on the internet |
| 6 | and render them for plain text accounting price syntax (and Beancount). |
| 7 | |
| 8 | This used to be located within Beancount itself (at v2) under beancount.prices. |
| 9 | This repo will contain all future updates to that script and to those price |
| 10 | sources. |
| 11 | |
| 12 | ## Documentation |
| 13 | |
| 14 | Some documentation is still part of Beancount. More about how to use this can be |
| 15 | found on that [mailing-list](https://groups.google.com/forum/#!forum/beancount). |
| 16 | Otherwise read the source. |
| 17 | |
| 18 | ## Quick start |
| 19 | |
| 20 | To install beanprice, run: |
| 21 | |
| 22 | ```shell |
| 23 | pip install git+https://github.com/beancount/beanprice.git |
| 24 | ``` |
| 25 | |
| 26 | You can fetch the latest price of a stock by running: |
| 27 | |
| 28 | ```shell |
| 29 | bean-price -e 'USD:yahoo/AAPL' |
| 30 | ``` |
| 31 | |
| 32 | To fetch the latest prices from your beancount file, first ensure that commodities have price metadata, e.g. |
| 33 | |
| 34 | ``` |
| 35 | 2000-01-01 commodity AAPL |
| 36 | price: "USD:yahoo/AAPL" |
| 37 | ``` |
| 38 | |
| 39 | Then run: |
| 40 | |
| 41 | ```shell |
| 42 | bean-price ledger.beancount |
| 43 | ``` |
| 44 | |
| 45 | To update prices up to the present day, run: |
| 46 | |
| 47 | ```shell |
| 48 | bean-price --update ledger.beancount |
| 49 | ``` |
| 50 | |
| 51 | For more detailed guide for price fetching, read <https://beancount.github.io/docs/fetching_prices_in_beancount.html>. |
| 52 | |
| 53 | |
| 54 | ## Price source info |
| 55 | The following price sources are available: |
| 56 | |
| 57 | | Name | Module | Provides prices for | Base currency | Latest price? | Historical price? | |
| 58 | |-------------------------|---------------------------|-----------------------------------------------------------------------------------|----------------------------------------------------------------------------------|---------------|-------------------| |
| 59 | | Alphavantage | `beanprice.alphavantage` | [Stocks, FX, Crypto](http://alphavantage.co) | Many currencies | ✓ | ✕ | |
| 60 | | Coinbase | `beanprice.coinbase` | [Most common (crypto)currencies](https://api.coinbase.com/v2/exchange-rates) | [Many currencies](https://api.coinbase.com/v2/currencies) | ✓ | ✓ | |
| 61 | | Coincap | `beanprice.coincap` | [Most common (crypto)currencies](https://docs.coincap.io) | USD | ✓ | ✓ | |
| 62 | | Coinmarketcap | `beanprice.coinmarketcap` | [Most common (crypto)currencies](https://coinmarketcap.com/api/documentation/v1/) | Many Currencies | ✓ | ✕ | |
| 63 | | European Central Bank API| `beanprice.ecbrates` | [Many currencies](https://data.ecb.europa.eu/search-results?searchTerm=exchange%20rates) | [Many currencies](https://data.ecb.europa.eu/search-results?searchTerm=exchange%20rates) (Derived from EUR rates)| ✓ | ✓ | |
| 64 | | IEX | `beanprice.iex` | [Trading symbols](https://iextrading.com/trading/eligible-symbols/) | USD | ✓ | 🚧 (Not yet!) | |
| 65 | | OANDA | `beanprice.oanda` | [Many currencies](https://developer.oanda.com/exchange-rates-api/v1/currencies/) | [Many currencies](https://developer.oanda.com/exchange-rates-api/v1/currencies/) | ✓ | ✓ | |
| 66 | | Quandl | `beanprice.quandl` | [Various datasets](https://www.quandl.com/search) | [Various datasets](https://www.quandl.com/search) | ✓ | ✓ | |
| 67 | | Rates API | `beanprice.ratesapi` | [Many currencies](https://api.exchangerate.host/symbols) | [Many currencies](https://api.exchangerate.host/symbols) | ✓ | ✓ | |
| 68 | | Thrift Savings Plan | `beanprice.tsp` | TSP Funds | USD | ✓ | ✓ | |
| 69 | | Yahoo | `beanprice.yahoo` | Many currencies | Many currencies | ✓ | ✓ | |
| 70 | | EastMoneyFund(天天基金) | `beanprice.eastmoneyfund` | [Chinese Funds](http://fund.eastmoney.com/js/fundcode_search.js) | CNY | ✓ | ✓ | |
| 71 | |
| 72 | |
| 73 | More price sources can be found at [awesome-beancount.com](https://awesome-beancount.com/#price-sources) website. |
| 74 | |
| 75 | ## Testing |
| 76 | |
| 77 | Run tests: |
| 78 | |
| 79 | ``` |
| 80 | pytest beanprice |
| 81 | ``` |
| 82 | |
| 83 | Lint: |
| 84 | |
| 85 | ``` |
| 86 | pylint beanprice |
| 87 | ``` |
| 88 | |
| 89 | Type checker: |
| 90 | |
| 91 | ``` |
| 92 | mypy beanprice |
| 93 | ``` |
| 94 | |
| 95 | ## Copyright and License |
| 96 | |
| 97 | Copyright (C) 2007-2020 Martin Blais. All Rights Reserved. |
| 98 | |
| 99 | This code is distributed under the terms of the "GNU GPLv2 only". |
| 100 | See COPYING file for details. |