custom price fetcher: is it possible to specify a commodity ticker explicitly?

64 views
Skip to first unread message

rff...@gmail.com

unread,
Aug 17, 2019, 9:45:33 AM8/17/19
to Beancount
Hi everyone, 

sorry if this is a dumb question but I've been unable to find an answer.
I wrote a small price fetcher for the milan stock exchange, which works by scraping the website 
and works well enough.

But, to find a price I need to use the ISIN rather than the ticket price, 
which means I have to specify the price like 

EUR:borsa_italiana/IE00BDBRDM35:AGGH 

this in turn results in the generation of a price tag that looks like

2019-08-16 price IE00BDBRDM35:AGGH                   5.271 EUR

but I'd rather not have the ISIN in my commodity name.

AFAICT, the find_prices machinery does not have any ability to specify
separate symbol names for output and lookups, a PriceSource cannot set it or 
return it. 
I don't see this done for the quandl source either, resulting in WiKI:FOO names.

I guess I could hack something with dynamic module loaders but it seems to me
this should be possible, and useful in general, maybe having a "?name=FOO" 
extra bit in the price (which feels URI-ish anyway) 

If there's a non-hackish way to do this?

Thanks in advance for any help, and thanks for beancount, it's very cool!

PS
Maybe this already works for prices defined as metadata for commodities?
I could not check as I could never get bean-price to run on my ledger file, due to the same error 

Justus Pendleton

unread,
Aug 18, 2019, 8:18:30 PM8/18/19
to Beancount
On Saturday, August 17, 2019 at 8:45:33 PM UTC+7, rff...@gmail.com wrote:
Maybe this already works for prices defined as metadata for commodities?

Yes, it works for prices defined as metadata for commodities.
The thing you are linking to says it has been resolved a long time ago: https://bitbucket.org/blais/beancount/issues/395/using-bean-price-all-causes-an-error

gabriele renzi

unread,
Aug 19, 2019, 4:22:10 AM8/19/19
to bean...@googlegroups.com
On Mon, Aug 19, 2019 at 2:18 AM Justus Pendleton <just...@gmail.com> wrote:

The thing you are linking to says it has been resolved a long time ago: https://bitbucket.org/blais/beancount/issues/395/using-bean-price-all-causes-an-error

yes but it still happens for me, having install beancount for the first time last week.
2.2.1 is, as far as I can tell, the latest released tag. 

$ bean-price -V
Beancount 2.2.1

$ bean-price -a mini.beancount
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/beancount/prices/find_prices.py", line 147, in import_source
    __import__(default_name)
ModuleNotFoundError: No module named 'beancount.prices.sources.True'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/bean-price", line 4, in <module>
    from beancount.prices.price import main; main()
  File "/usr/local/lib/python3.7/site-packages/beancount/prices/price.py", line 354, in main
    args, jobs, entries, dcontext = process_args()
  File "/usr/local/lib/python3.7/site-packages/beancount/prices/price.py", line 347, in process_args
    entries, args.date, args.inactive, args.undeclared))
  File "/usr/local/lib/python3.7/site-packages/beancount/prices/find_prices.py", line 366, in get_price_jobs_at_date
    default_source = import_source(undeclared_source)
  File "/usr/local/lib/python3.7/site-packages/beancount/prices/find_prices.py", line 151, in import_source
    __import__(module_name)
TypeError: __import__() argument 1 must be str, not bool

$ cat mini.beancount
2019-01-01 open Assets:Shares:APPL
2019-01-01 commodity APPL
  name: "Apple"
  price: "USD:quandl/WIKI:AAPL" 

Justus Pendleton

unread,
Aug 21, 2019, 10:54:43 AM8/21/19
to Beancount


On Monday, August 19, 2019 at 3:22:10 PM UTC+7, gabriele renzi wrote:
On Mon, Aug 19, 2019 at 2:18 AM Justus Pendleton <just...@gmail.com> wrote:

The thing you are linking to says it has been resolved a long time ago: https://bitbucket.org/blais/beancount/issues/395/using-bean-price-all-causes-an-error

yes but it still happens for me, having install beancount for the first time last week.
2.2.1 is, as far as I can tell, the latest released tag.

In this case it appears that "fixed a long time ago" doesn't mean it has actually made its way into a release.

2.2.1 was tagged in January, I think, and you're right it seems to show that same error. I confirmed that it works fine with tip from bitbucket.

Martin Blais

unread,
Aug 21, 2019, 11:34:45 PM8/21/19
to Beancount

--
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 beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/efe8175e-108d-4806-a7cd-f54d3994f4f7%40googlegroups.com.

gabriele renzi

unread,
Aug 22, 2019, 6:57:25 AM8/22/19
to bean...@googlegroups.com
nice, thank you!

Martin Blais

unread,
Aug 23, 2019, 12:10:35 AM8/23/19
to Beancount
Sorry forgot to fetch & merge some approved PRs.
Did that just now, released 2.2.3.


On Thu, Aug 22, 2019 at 6:57 AM gabriele renzi <rff...@gmail.com> wrote:
nice, thank you!

--
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 beancount+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages