hledger-stockquotes: Generate HLedger Price Directives From Daily Stock Quotes.

[ bsd3, console, finance, library, program ] [ Propose Tags ]

hledger-stockquotes is an addon for hledger that reads your journal file, pulls the historical stock prices for commodities, and writes out a new journal file containing the respective price directives.

The AlphaVantage API is used to fetch the stock quotes and you will need a free API key to use this program.

You can install hledger-stockquotes with Stack: stack install --resolver nightly hledger-stockquotes. Then run hledger-stockquotes --help to see the usage instructions & all available options.


[Skip to Readme]
Versions [faq] 0.1.0.0, 0.1.1.0
Change log CHANGELOG.md
Dependencies aeson (==1.*), base (>=4.7 && <5), bytestring (==0.*), cmdargs (>=0.6 && <1), containers (==0.*), hledger-lib (<2), hledger-stockquotes, req (==3.*), safe (>=0.3.5 && <1), scientific (==0.*), split (==0.*), text (<2), time (<2), unordered-containers (<0.3) [details]
License BSD-3-Clause
Copyright 2020 Pavan Rikhi
Author Pavan Rikhi
Maintainer pavan.rikhi@gmail.com
Category Finance, Console
Home page https://github.com/prikhi/hledger-stockquotes#readme
Bug tracker https://github.com/prikhi/hledger-stockquotes/issues
Source repo head: git clone https://github.com/prikhi/hledger-stockquotes
Uploaded by lysergia at 2021-01-23T19:44:07Z
Distributions NixOS:0.1.0.0
Executables hledger-stockquotes
Downloads 192 total (35 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2021-01-23 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for hledger-stockquotes-0.1.1.0

[back to package description]

hledger-stockquotes

hledger-stockquotes Build Status

hledger-stockquotes is a CLI addon for hledger that reads a journal file and pulls the historical prices for commodities from AlphaVantage. To use this application, you'll need a free AlphaVantage API key.

Usage

hledger-stockquotes parses your journal file, determines what commodities are defined, and queries AlphaVantage for prices on the date range present in the journal file.

By default, the program will use the HLedger default file location of ~/.hledger.journal. A LEDGER_FILE environmental variable can be used to override the location. The -f flag can be used to override both the default and LEDGER_FILE locations.

At the bare minimum, you need to set an ALPHAVANTAGE_KEY environmental variable or use the -a switch to specify your AlphaVantage key:

hledger-stockquotes -a MY_API_KEY -f accounting.journal

This will print out price directive to a prices.journal file.

Custom Output Files

The output file can be set with the -o flag:

hledger-stockquotes -a MY_API_KEY -o prices/2021.journal

NOTE: the contents of the output file will be overwritten if the file already exists!

Excluding Commodities

By default, we query AlphaVantage for all non-USD commodities included in your journal file. We do not currently support AlphaVantage's FOREX or Crypto API routes, so if you have those commodities, stockquotes will print an error when fetching them. You can exclude commodities by passing them as arguments to hledger-stockquotes:

hledger-stockquotes -a MY_API_KEY AUTO TA_VFFVX

NOTE: hledger defines an AUTO commodity if you use the default commodity directive(D).

API Limits

AlphaVantage has an API request limit of 5 requests per minute. hledger-stockquotes enforces this limit on a per-command basis. A single run will fetch 5 price histories, wait 60 seconds, fetch 5 more, etc. Running multiple hledger-stockquotes commands in sequence will not enforce this limit over multiple runs and may result in API errors. You can ignore the request limiting with the -n flag. To test a command without hitting the API, pass the --dry-run flag. This will simply print out the commodities and date ranges that would be queried instead of making requests to AlphaVantage.

Additional Documentation

The --help flag provides more thorough documentation on all available flags:

hledger-stockquotes --help

Build / Install

This project has not yet been packaged for any OSes or Linux distributions, so you'll have to clone this repository & compile/install the code yourself:

git clone https://github.com/prikhi/hledger-stockquotes.git
cd hledger-stockquotes
stack install

This will put the hledger-stockquotes exe into your ~/.local/bin/ directory. Ensure that the directory is included in your PATH environmental variable. Then you can run the application:

hledger-stockquotes --help

Since the executable has the hledger- prefix, you can also use it with the hledger command:

hledger stockquotes -- --help

Development/Manual Builds

You can build the project with stack: stack build

For development, you can enable fast builds with file-watching, documentation-building, & test-running: stack test --haddock --fast --file-watch

To build & open the documentation, run stack haddock --open hledger-stockquotes

To install the executable to ~/.local/bin, run stack install.

LICENSE

BSD-3