For anyone watching, I think I've got it. I tried the AI route, CoPilot w/
gpt 4o failed miserably, completely making up functions.
But it wasn't terrible to hack out. Note: python is not my native language.
# "price" is too generic
from beanprice import price as beanprice
...
def extract(self, filepath, existing):
# Initialize cache (string path) and a dict of
commodity:sources_list for easy reference later
sometuples = beanprice.find_currencies_declared(existing)
commodity_sources = { sometuple[0]:sometuple[2] for sometuple in
sometuples }
# I made price_cache path an importer option for flexibility
if self.price_cache:
beanprice.setup_cache(self.price_cache, False)
... Later pulling a price:
# Get that "sources_list" for, e.g. "BTC"
srcs = commodity_sources[asset]
# Make the thing we need to pass to fetch_price, using date of
a given transaction
dated_price = beanprice.DatedPrice(self.base_currency, None,
date, srcs)
price = beanprice.fetch_price(dated_price)
cost = CostSpec(price.amount.number, None,
price.amount.currency, None, None, None)
# ... add cost to Posting
In context:
https://github.com/pwalkr/beancount-utils/commit/ec87207eb02b2f32d7e4b88937063b1af40e7d0d
Paul
On Sunday, May 4, 2025 at 1:23:20 PM UTC-4 Paul Walker wrote:
> Is there an easy way to leverage beanprice with its cache and
> commodity-meta awareness in a beangulp import workflow? I want to fetch
> prices for crypto airdrops and staking rewards on import so I can attach
> cost/lots; Kraken doesn't offer this in its ledger api response. I was
> thinking to persist find_currencies_declared
> <https://github.com/beancount/beanprice/blob/7a6efa7e0b0c9567df27c98e3fd4e8fc3e1c7117/beanprice/price.py#L201>
>
> and maybe process "DatedPrice" jobs inline, but wondered if it's been done
> already.
>
> Thanks,
> Paul
>
--
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/b4c58a84-a560-4895-a3d4-b658dad158adn%40googlegroups.com.