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:
Paul