Beancount cost and price

I'm confused.

1.

I buy BTC. I use {} instead of @ because I want to track "capital gains". Then I buy ETH with BTC.

I expect this to work:

2025-01-01 open Assets:Test

2025-01-02 * "buy btc"
    Assets:Test       1 BTC {123456 USD, "foo"}
    Assets:Test -123456 USD

2025-01-03 * "buy eth"
    Assets:Test      80 ETH {0.005 BTC}
    Assets:Test    -0.4 BTC {"foo"}

Error: "No position matches ..."

Ok, so I change the last transaction:

2025-01-03 * "buy eth"
    Assets:Test      80 ETH {0.005 BTC}
    Assets:Test    -0.4 BTC {"foo"}
    Assets:Test     0.4 BTC @ 123456 USD  ; new posting
    Assets:Test    -0.4 BTC               ; new posting

This seems to be working. Is this the correct approach?

2.

I noticed that when I add price to the posting -0.4 BTC {"foo"}, for example 49176234 USD, it seems to have no effect. No error.

2025-01-03 * "buy eth"
    Assets:Test      80 ETH {0.005 BTC}
    Assets:Test    -0.4 BTC {"foo"} @ 49176234 USD
    Assets:Test     0.4 BTC @ 123456 USD
    Assets:Test    -0.4 BTC

I can enter any price, 999999 USD. Is this a bug? What is happening?

2025-01-03 * "buy eth"
    Assets:Test      80 ETH {0.005 BTC}
    Assets:Test    -0.4 BTC {"foo"} @ 999999 USD
    Assets:Test     0.4 BTC @ 123456 USD
    Assets:Test    -0.4 BTC
1 Like
  1. from the docs:

Finally, if a posting has both a cost and a price, we simply ignore the price. This optional price is used later on to generate an entry in the in-memory prices database, but it is not used in balancing at all.

For 1. are you sure that you really want to use BTC as the cost currency for your ETH? I think that is the issue, if you change the cost tag for ETH to use USD, the first way will work.

For 2. there are some plugins which start to enforce some of the checks (e.g. sellgains), see beancount.plugins - Beancount Documentation