Hi Errol,
if I remember correctly it depends not on the commodities but if you
have actually any balances using the instruments.
For updating a file, this is what I use. I have a prices folder with a
file per instrument.
#!/usr/bin/env python3
from beanprice import price
from beancount import loader
from beancount.parser import printer
entries, errors, options = loader.load_file('main.beancount')
priceJobs = price.get_price_jobs_at_date(entries, inactive=True)
prices = []
for job in priceJobs:
try:
prices.append(price.fetch_price(job))
except Exception as e:
print("failed to fetch, ", job, e)
prices, ignoredEntries = price.filter_redundant_prices(prices, entries)
for newPrice in prices:
with open('prices/' + newPrice.currency.lower() + '.beancount',
'a') as priceFile:
priceFile.write(printer.format_entry(newPrice))
Regards,
Patrick
On 27.12.2024 07:28, Errol Lee wrote:
Hi Patrick,
Thank you for your guidance! I thought I did, but I must've done
something wrong earlier. I've reinstalled and can now successfully
retrieve prices using Yahoo.
For example:
❯ bean-price -e 'AUD:yahoo/VDHG.AX'
2024-12-27 price VDHG.AX 69.53 AUD
I’ve defined my commodities in a commodities.bean file. For instance,
VDHG is defined as follows:
2000-01-01 commodity VDHG
name:"Vanguard Diversified High Growth ETF"
asset-class:"Equity"
symbol:"VDHG"
price:"AUD:yahoo/VDHG.AX"
However, when I run the following command, it seems to execute
successfully, but I don’t see the prices updated in any of my files:
❯ bean-price commodities.bean
Ideally, I’d like the latest prices to be saved automatically in a
prices.bean file. Is there something I’m missing in my setup or an
additional step I need to take to ensure the prices are recorded in
the desired file?
Thanks again for your help!
Best regards,
Errol
On Tuesday, December 24, 2024 at 3:46:05 PM UTC+8 Patrick Ruckstuhl wrote:
Hi Errol,
Did you install beanprice separately?
https://github.com/beancount/beanprice
I'm using alphavantage on a daily basis.
You will need to set an environment variable ALPHAVANTAGE_API_KEY
with a free api key from them and use it like
USD:alphavantage/price:AAPL:USD
Regards,
Patrick
On December 24, 2024 2:48:02 AM GMT+01:00, Errol Lee
<[email protected]> wrote:
Hi everyone,
I’m new to Beancount (and honestly, I’m amazed by the amount
of functionality it offers—wish I had discovered it sooner!).
I’m trying to set up bean-price to fetch stock prices, but
I’ve run into some issues, particularly with Yahoo and
Alphavantage as sources.
Here’s what I’ve tried so far:
1.*Yahoo*:
It seems like Yahoo has blocked API access for fetching stock
prices. When I try fetching prices for AAPL, I get the
following error:
❯ bean-price -e 'USD:yahoo/AAPL'
ERROR : Error fetching AAPL: Status 401: {'code':
'Unauthorized', 'description': 'User is unable to access this
feature - https://bit.ly/yahoo-finance-api-feedback'}
ERROR : Could not fetch for job: DatedPrice(base='AAPL',
quote='USD', date=None, sources=[PriceSource(module=<module
'beancount.prices.sources.yahoo' from
'/opt/homebrew/lib/python3.11/site-packages/beancount/prices/sources/yahoo.py'>,
symbol='AAPL', invert=False)])
2.*Alphavantage*:
Despite being listed as a source in the GitHub documentation,
I can’t seem to get it working. Here’s the error I encounter:
❯ bean-price -e 'USD:alphavantage/AAPL'
Traceback (most recent call last):
File
"/opt/homebrew/lib/python3.11/site-packages/beancount/prices/price.py",
line 178, inimport_source
__import__(default_name)
ModuleNotFoundError: No module named
'beancount.prices.sources.alphavantage'
During handling of the above exception, another exception
occurred:
Traceback (most recent call last):
File
"/opt/homebrew/lib/python3.11/site-packages/beancount/prices/price.py",
line 182, inimport_source
__import__(module_name)
ModuleNotFoundError: No module named 'alphavantage'
Ultimately, I’d like to fetch prices for some Australian
stocks in my portfolio (e.g., ASX:VDHG, ASX:VGS, etc.).
Does anyone have advice on:
•Workarounds for Yahoo?
•How to enable or properly configure Alphavantage as a source?
•Any other sources I can use for Australian stocks?
Thanks in advance for your help! Any guidance would be much
appreciated.
--
You received this message because you are subscribed to the Google
Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/beancount/1e797d83-4d9c-4951-8609-a20781fb5164n%40googlegroups.com
<https://groups.google.com/d/msgid/beancount/1e797d83-4d9c-4951-8609-a20781fb5164n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/beancount/63288dc2-2e32-4d4f-86d2-302fc718fa1f%40tario.org.