Skip to content

the-solipsist/hledger-scripts

Repository files navigation

hledger-scripts

A collection of Bash scripts for fetching authoritative market prices (Stocks, Mutual Funds, Gold, NPS, Crypto, Currency) and formatting them for hledger.

These scripts prioritize official, authoritative sources for maximum accuracy and reliability:

  • Indian Stocks: Parsed directly from the official BSE Bhavcopy (daily trade report CSVs).
  • Mutual Funds: Fetched from the Association of Mutual Funds in India (AMFI) master NAV file.
  • NPS (National Pension System): Sourced from the Protean (NSDL) CRA daily NAV archives.
  • Gold Rates: Extracted from IBJA (India Bullion and Jewellers Association), the benchmark rate-setting organization for bullion in India.

Separately, this repo also incldes:

  • Bank Import Helpers: cleaning scripts for Kotak Mahindra and YES Bank CSV statements.

Scripts

1. Indian Stocks (ledger_get-indian-stock-prices_bse.sh)

Downloads the daily BSE Bhavcopy CSV, extracts closing prices for stocks defined in your ledger, and formats them.

2. Mutual Funds (ledger_get-indian-mf-prices.sh)

Downloads the daily NAV file from AMFI and extracts prices for your funds.

3. Gold Rates (ledger_get-indian-gold-prices.sh)

Fetches 24K (999) and 22K (916) Gold rates from IBJA. Prices are normalized to per-gram for consistency.

4. NPS NAVs (ledger_get-indian-nps-prices.sh)

Downloads and parses the daily NAV ZIP file from the NSDL/Protean CRA website.

5. Currency Rates (ledger_get-currency-prices.sh)

Fetches exchange rates for all currencies found in your ledger.

  • Multiple sources: Supports Frankfurter, CurrencyBeacon, and AlphaVantage.
  • Usage: ./ledger_get-currency-prices.sh [currencybeacon|frankfurter] (Defaults to CurrencyBeacon).

6. Cryptocurrency (ledger_get-crypto-prices.sh)

Fetches latest crypto prices in your base currency (INR/USD).

  • Multiple sources: Supports CoinMarketCap and CoinGecko.

Installation

  1. Clone the repository: git clone git@github.com:the-solipsist/hledger-scripts.git

  2. Dependencies: Ensure these standard tools are installed: curl, jq, hledger, python3 (for HTML entity decoding), awk.

  3. Configuration: Scripts that require API keys (CurrencyBeacon, CoinMarketCap) look for .key files in the same directory:

    • key_currencybeacon-api.key: key="YOUR_KEY"
    • key_coinmarketcap-api.key: key="YOUR_KEY"

License

All code is licensed under the MIT License - see the LICENSE file for details.