Crates.io | hledger-get-market-prices |
lib.rs | hledger-get-market-prices |
version | 1.1.0 |
source | src |
created_at | 2022-01-09 15:40:30.048475 |
updated_at | 2022-01-30 19:51:17.477938 |
description | Gets historical stock prices from Alpha Vantage API and outputs them in hledger market price format |
homepage | |
repository | https://github.com/EliasHolzmann/hledger-get-market-prices |
max_upload_size | |
id | 510894 |
size | 53,551 |
You can use this project to get historical stock and fonds prices from the Alpha Vantage API and convert them to the hledger market price format. This is useful to keep track of the current value of your portfolio.
$ cargo install hledger-get-market-prices
Let's say you are interested in how the fonds with ISIN IE00BJ0KDQ92 traded on XETRA. In hledger, you call the commodity of this fonds MSCIWRLD
. The Euro is used at XETRA to trade MSCIWRLD
, and hledger knows this currency as the commodity €
.
First, you need an Alpha Vantage API key. You can receive a key for free here.
hledger-get-market-prices
expects this key in the environment variable HLEDGER_GET_MARKET_PRICES_API_KEY
, so either add this to your environment for all applications (for example inside ~/.bashrc
if you are using Bash) or always call hledger-get-market-prices
with the key prepended (HLEDGER_GET_MARKET_PRICES_API_KEY=<key> hledger get-market-prices ...
).
Next, you need to find out the symbol used for the fonds. In theory, you can search via hledger get-market-prices search-stock-symbol
, but the search API of Alpha Vantage is a bit tricky. You can try to search by the ISIN:
$ hledger get-market-prices search-stock-symbol IE00BJ0KDQ92
Currently, this does not return any results. Searching for the name of the fonds ("Xtrackers MSCI World UCITS ETF 1C") doesn't work either. But you can search for the ticker symbol XETRA uses. As you can see here, XETRA uses the ticker symbol XDWD. Searching for XDWD
leads to multiple results:
$ hledger get-market-prices search-stock-symbol XDWD
Region | Symbol – Name
Frankfurt | XDWD.FRK – Xtrackers (IE) Public Limited Company - Xtrackers MSCI World UCITS ETF
United Kingdom | XDWD.LON – Xtrackers (IE) Plc - Xtrackers MSCI World UCITS ETF 1C
XETRA | XDWD.DEX – Xtrackers (IE) Plc - Xtrackers MSCI World UCITS ETF 1C
You are interested on results for XETRA, so XDWD.DEX
is the correct symbol.
Now, you can use the symbol to ask for historic data:
hledger get-market-prices history XDWD.DEX MSCIWRLD €
; Generated by hledger-get-market-prices V1.0.0
P 2022-01-07 MSCIWRLD 84.838 €
P 2022-01-06 MSCIWRLD 85.4 €
P 2022-01-05 MSCIWRLD 86.752 €
P 2022-01-04 MSCIWRLD 86.752 €
P 2022-01-03 MSCIWRLD 86.594 €
P 2021-12-30 MSCIWRLD 86.706 €
...
hledger-get-market-prices
? Open price, close price, average price or something different?Currently, hledger-get-market-prices
uses close prices because that's what I am interested in. If you want additional functionality, a pull request is welcome.