### Install pricehist with pipx Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Install the pricehist command-line tool using pipx for isolated environments. ```bash pipx install pricehist ``` -------------------------------- ### Bean-price Output Example Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md This is an example of the output format when fetching a single price using bean-price. ```text 2021-08-18 price BTC:USD 44725.12 USD ``` -------------------------------- ### Show Source Information Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Use the `source` command to display details about a specific data provider. This includes its ID, name, description, URL, data start date, and available data types. ```bash pricehist source alphavantage ``` ```text ID : alphavantage Name : Alpha Vantage Description : Provider of market data for stocks, forex and cryptocurrencies URL : https://www.alphavantage.co/ Start : 1995-01-01 Types : close, open, high, low, adjclose, mid Notes : Alpha Vantage has data on... ``` -------------------------------- ### Bean-price Historical Price Output Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Example output showing a series of historical prices fetched and updated using bean-price with a Beancount file. ```text 2021-08-14 price BTC 47098.2633 USD 2021-08-15 price BTC 47018.9017 USD 2021-08-16 price BTC 45927.405 USD 2021-08-17 price BTC 44686.3333 USD 2021-08-18 price BTC 44725.12 USD ``` -------------------------------- ### Generate BTC/USD price chart with gnuplot Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Fetches Bitcoin (BTC) to US Dollar (USD) prices from CoinDesk, processes the CSV output to extract date and price, and pipes it to gnuplot to generate a line chart. Requires gnuplot to be installed. ```bash pricehist fetch coindesk BTC/USD -s 2021-01-01 | \ sed 1d | \ cut -d, -f1,4 | \ gnuplot -p -e \ "set datafile separator ",";" set xdata time; set timefmt "%Y-%m-%d"; set format x "%b\n%Y"; plot "/dev/stdin" using 1:2 with lines title "BTC/USD" ``` -------------------------------- ### Configure Price Source in Beancount Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Define a price source in a Beancount file to fetch historical price data. Ensure the 'pricehist' package is installed and accessible. ```beancount ; input.beancount 2021-08-14 commodity BTC price: "USD:pricehist.beanprice.coindesk/BTC:USD:close" ``` -------------------------------- ### Fetch Price Series using pricehist Library Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Demonstrates how to use the pricehist library in Python to fetch a series of prices. Requires importing Series and a specific source class like ECB. ```python from pricehist.series import Series from pricehist.sources.ecb import ECB series = ECB().fetch(Series("EUR", "AUD", "reference", "2021-01-04", "2021-01-08")) print(series.prices) ``` -------------------------------- ### List Symbols for a Source Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md To see all available trading pairs or individual symbols for a source, use the `--symbols` flag. This is useful for understanding what data can be fetched. ```bash pricehist source ecb --symbols ``` ```text EUR/AUD Euro against Australian Dollar EUR/BGN Euro against Bulgarian Lev EUR/BRL Euro against Brazilian Real EUR/CAD Euro against Canadian Dollar EUR/CHF Euro against Swiss Franc ... ``` -------------------------------- ### Fetch and Output Prices in Ledger Format Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Fetches price data for a specified pair and date range, outputting it in the Ledger format. Ensure the output format is supported by your financial software. ```bash pricehist fetch ecb EUR/AUD -s 2021-01-04 -e 2021-01-08 -o ledger ``` ```text P 2021-01-04 00:00:00 EUR 1.5928 AUD P 2021-01-05 00:00:00 EUR 1.5927 AUD P 2021-01-06 00:00:00 EUR 1.5824 AUD P 2021-01-07 00:00:00 EUR 1.5836 AUD P 2021-01-08 00:00:00 EUR 1.5758 AUD ``` -------------------------------- ### Show Pricehist Usage Information Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Append -h to any pricehist command to display detailed usage instructions and available options. ```bash pricehist fetch -h ``` ```bash usage: pricehist fetch SOURCE PAIR [-h] [-vvv] [-t TYPE] [-s DATE | -sx DATE] [-e DATE | -ex DATE] [-o beancount|csv|json|jsonl|gnucash-sql|ledger] [--invert] [--quantize INT] [--fmt-base SYM] [--fmt-quote SYM] [--fmt-time TIME] [--fmt-decimal CHAR] [--fmt-thousands CHAR] [--fmt-symbol rightspace|right|leftspace|left] [--fmt-datesep CHAR] [--fmt-csvdelim CHAR] [--fmt-jsonnums] positional arguments: SOURCE the source identifier PAIR pair, usually BASE/QUOTE, e.g. BTC/USD optional arguments: -h, --help show this help message and exit -vvv, --verbose show all log messages -t TYPE, --type TYPE price type, e.g. close -s DATE, --start DATE start date, inclusive (default: source start) -sx DATE, --startx DATE start date, exclusive -e DATE, --end DATE end date, inclusive (default: today) -ex DATE, --endx DATE end date, exclusive -o FMT, --output FMT output format (default: csv) --invert invert the price, swapping base and quote --quantize INT round to the given number of decimal places --fmt-base SYM rename the base symbol in output --fmt-quote SYM rename the quote symbol in output --fmt-time TIME set a particular time of day in output (default: 00:00:00) --fmt-decimal CHAR decimal point in output (default: '.') --fmt-thousands CHAR thousands separator in output (default: '') --fmt-symbol LOCATION commodity symbol placement in output (default: rightspace) --fmt-datesep CHAR date separator in output (default: '-') --fmt-csvdelim CHAR field delimiter for CSV output (default: ',') --fmt-jsonnums numbers not strings for JSON output (default: False) ``` -------------------------------- ### Fetch Price with pricehist CLI Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Command-line interface to fetch a specific price type for a given pair from a source. 'coindesk' is the source ID, 'BTC/USD' is the pair, and 'close' is the price type. ```bash pricehist fetch coindesk BTC/USD --type close ``` -------------------------------- ### Reproduce Source Request with Curl and Parse JSON Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md This command demonstrates how to extract the `curl` command from verbose output, execute it, and then parse the resulting JSON using `jq`. This allows for direct inspection of the data returned by the source. ```bash pricehist fetch coindesk BTC/USD -s 2021-01-01 -e 2021-01-05 -vvv 2>&1 \ | grep '^DEBUG curl' | sed 's/^DEBUG //' | bash | jq . ``` ```json { "bpi": { "2021-01-01": 29391.775, "2021-01-02": 32198.48, "2021-01-03": 33033.62, "2021-01-04": 32017.565, "2021-01-05": 34035.0067 }, "disclaimer": "This data was produced from the CoinDesk Bitcoin Price Index. BPI value data returned as USD.", "time": { "updated": "Jan 6, 2021 00:03:00 UTC", "updatedISO": "2021-01-06T00:03:00+00:00" } } ``` -------------------------------- ### Update Prices with bean-price and Beancount File Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Fetch and update a series of prices by providing a Beancount file as input to bean-price. Options include updating rates, handling inactive entries, and clearing cache. ```bash bean-price input.beancount --update --update-rate daily --inactive --clear-cache ``` -------------------------------- ### Inspect Source Interactions with Verbose Output Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Add the `--verbose` or `-vvv` option to `fetch` commands to see detailed debugging information, including the exact `curl` commands executed to retrieve data. This is helpful for troubleshooting. ```bash pricehist fetch coindesk BTC/USD -s 2021-01-01 -e 2021-01-05 -vvv ``` ```text DEBUG Began pricehist run at 2021-08-12 14:38:26.630357. DEBUG Starting new HTTPS connection (1): api.coindesk.com:443 DEBUG https://api.coindesk.com:443 "GET /v1/bpi/historical/close.json?currency=USD&start=2021-01-01&end=2021-01-05 HTTP/1.1" 200 319 DEBUG curl -X GET -H 'Accept: */*' -H 'Accept-Encoding: gzip, deflate' -H 'Connection: keep-alive' -H 'User-Agent: python-requests/2.25.1' --compressed 'https://api.coindesk.com/v1/bpi/historical/close.json?currency=USD&start=2021-01-01&end=2021-01-05' DEBUG Available data covers the interval [2021-01-01--2021-01-05], as requested. date,base,quote,amount,source,type 2021-01-01,BTC,USD,29391.775,coindesk,close 2021-01-02,BTC,USD,32198.48,coindesk,close 2021-01-03,BTC,USD,33033.62,coindesk,close 2021-01-04,BTC,USD,32017.565,coindesk,close 2021-01-05,BTC,USD,34035.0067,coindesk,close DEBUG Ended pricehist run at 2021-08-12 14:38:26.709428. ``` -------------------------------- ### Fetch Latest Price with bean-price Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Use this command to fetch the latest price for a given currency pair directly from the command line using bean-price. ```bash bean-price -e "USD:pricehist.beanprice.coindesk/BTC:USD" ``` -------------------------------- ### Load Prices into GnuCash via SQL Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Generates SQL statements to load price data into a GnuCash database. This requires the GnuCash database to already contain the necessary commodity mnemonics. Back up your database before applying changes. ```bash pricehist fetch ecb EUR/AUD -s 2021-01-01 -o gnucash-sql | sqlite3 Accounts.gnucash ``` ```bash pricehist fetch ecb EUR/AUD -s 2021-01-01 -o gnucash-sql | mysql -u username -p -D databasename ``` ```bash pricehist fetch ecb EUR/AUD -s 2021-01-01 -o gnucash-sql | psql -U username -d databasename -v ON_ERROR_STOP=1 ``` -------------------------------- ### Customize Price Output Format Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Customizes the output format for fetched prices, including time, date separators, currency symbols, and symbol placement. This allows for tailored data presentation. ```bash pricehist fetch ecb EUR/AUD -s 2021-01-04 -e 2021-01-08 -o ledger \ --fmt-time '' --fmt-datesep / --fmt-base € --fmt-quote $ --fmt-symbol left ``` ```text P 2021/01/04 € $1.5928 P 2021/01/05 € $1.5927 P 2021/01/06 € $1.5824 P 2021/01/07 € $1.5836 P 2021/01/08 € $1.5758 ``` -------------------------------- ### Search for Symbols Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md You can search for specific symbols within a source using the `--search` option followed by your query. This helps in finding relevant financial instruments. ```bash pricehist source alphavantage --search Tesla ``` ```text TL0.DEX Tesla, Equity, XETRA, EUR TL0.FRK Tesla, Equity, Frankfurt, EUR TSLA34.SAO Tesla, Equity, Brazil/Sao Paolo, BRL TSLA Tesla Inc, Equity, United States, USD TXLZF Tesla Exploration Ltd, Equity, United States, USD ``` -------------------------------- ### Fetch ECB EUR/AUD prices Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Fetches historical exchange rates for EUR/AUD from the European Central Bank (ECB) for a specified date range. The default output format is CSV. ```bash pricehist fetch ecb EUR/AUD -s 2021-01-04 -e 2021-01-08 ``` ```csv date,base,quote,amount,source,type 2021-01-04,EUR,AUD,1.5928,ecb,reference 2021-01-05,EUR,AUD,1.5927,ecb,reference 2021-01-06,EUR,AUD,1.5824,ecb,reference 2021-01-07,EUR,AUD,1.5836,ecb,reference 2021-01-08,EUR,AUD,1.5758,ecb,reference ``` -------------------------------- ### Update Prices Incrementally Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Updates an existing CSV price file by fetching only new prices since the last entry. This avoids refetching historical data and appends new entries after removing any header. ```bash last=$(tail -1 prices-eur-usd.csv | cut -d, -f1) pricehist fetch ecb EUR/USD -sx $last -o csv | sed 1d >> prices-eur-usd.csv ``` -------------------------------- ### Price Object Representation Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md The 'prices' attribute of a Series object returns a list of Price objects, each containing a date and an amount. ```python [Price(date='2021-01-04', amount=Decimal('1.5928')), Price(date='2021-01-05', amount=Decimal('1.5927')), Price(date='2021-01-06', amount=Decimal('1.5824')), Price(date='2021-01-07', amount=Decimal('1.5836')), Price(date='2021-01-08', amount=Decimal('1.5758'))] ``` -------------------------------- ### Encode Special Characters for bean-price Tickers Source: https://gitlab.com/chrisberkhout/pricehist/-/blob/master/README.md Special characters in pricehist ticker symbols need to be encoded for bean-price. Use a two-digit hexadecimal code prefixed with an underscore for non-alphanumeric characters (except =, -, ., (, )). ```text USD:pricehist.beanprice.yahoo/_5eDJI::high ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.