I may be wrong, but IIRC, there’s no way to do this through the API. @@ is not very well supported. The parser has it but the Posting class doesn’t.
For what you’re wanting, shouldn’t you be wanting to avoid using @@?
fwiw I agree with Zoltan - with the exception of money market funds where `@ 1.00 USD` makes sense, it never makes sense to record the unit price in a transaction, as that is a derivative property of how much is actually paid. Similar to eg Quicken where the default is 'automatically calculate price.' Writing the unit price feels like a clear anti-pattern to me... unless I really wanted to track the rounding errors the bank is earning off me? I have scripts that normalize and rewrite transactions and I hack the output to manually export `@@ total_price USD` everywhere.
The main reason I record the unit price in commodities held at cost is to match how my brokers store/expose it. Makes it easy to cross-check with statements when needed or for lot matching when selling. A secondary but equally important reason is to catch errors during import. It’s all too easy to miss a new type of fee or such that the importer hasn’t seen, if the total price is “absorbed in”.
With price conversions though (as opposed to commodities held at cost), as the OP says, it’s generally more important to have both sides of the transaction reflect what the banks see, the unit price is less important, and @@ is preferred.
For what you’re wanting, shouldn’t you be wanting to avoid using @@?
What is the alternative way to solve what I’m looking for?
My bad, I misread your statement as a desire to not have many digits in the conversion. You’re right, I’d want to do what you do in principle. As you ran into though, @@ has no API support (and this comment says even the input parser could be improved). Given that, these are some approaches I see:
Given:
Hope that helps.
The main reason I record the unit price in commodities held at cost is to match how my brokers store/expose it. Makes it easy to cross-check with statements when needed or for lot matching when selling. A secondary but equally important reason is to catch errors during import. It’s all too easy to miss a new type of fee or such that the importer hasn’t seen, if the total price is “absorbed in”.
I would consider implementing this differently. The price exposed on the statement is not the price - or, perhaps not always, depending on the broker. It is an approximation of the price, sometimes not even significant to the the point that it prints. Vanguard, for instance, on some of my accounts (I think my 529), reports prices at 4 decimal points, but rounds it to 3 with a trailing 0, while I can get the 'more correct' price online. I've also seen different rounding prices in CSV vs OFX exports from the same statements, and I've seen different conventions where trailing 0's are dropped only when correct vs rounding - leading to strict Decimal tolerance issues. But even if all those were solved for, it's not actually the "price.'' When they calculate gains etc, they use whatever they use in the backend - probably to more significant digits than what is exposed.
Most brokers store either 4 (common) or 6 (becoming common?) decimal points -- in the US at least -- and expose anywhere between 2 and the full number of decimals varyingly on the web, in their pdf statements, on ofx, and on csv. So while it’s true in principle that we users may or may not be able to import the full precision as stored, in practice I’ve found using the price as exposed by the brokerage works very well because a) they are consistent and tend to match on both ends, and b) the rounding errors that come from the store/expose delta is too low to matter. Of course, YMMV. That’s for prices. Quantities are a different story.
I only do automatic lot specification so I'm not sure on the best approach to suggest, but I would presume your concerns are also easier to address by specifying date or label of a lot rather than a price, and let the more accurate price calculations run through.
It doesn’t work when one has multiple transactions on the same day, and one doesn’t want to use labels (automation complexity, portability).
BTW, given the 4/6 storage, price calculations using @@ typically end up with many more decimal points, and are arguably less accurate in that they don’t match how your brokerage stores it. This might matter more from a purity standpoint though, and not in practice.
--
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 visit https://groups.google.com/d/msgid/beancount/04770ab4-f822-4be3-addd-28bd6d4e1ec4n%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "Beancount" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beancount/D6xpn0guLzs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beancount+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/beancount/CAK21%2BhOpc0asmhrpNWLqxqnYcFWeRu3ckd61PUXX_U0-3gNX1w%40mail.gmail.com.
I only do automatic lot specification so I'm not sure on the best approach to suggest, but I would presume your concerns are also easier to address by specifying date or label of a lot rather than a price, and let the more accurate price calculations run through.
When I submit a buy execution to my broker it gets filled like this:2020-03-12 * "SMLF" #20200228-tlh-rzv
Assets:US:Interactive-Brokers 1000 SMLF {31.4550 USD, 2020-03-12} @ 31.455 USD
Assets:US:Interactive-Brokers 400 SMLF {30.5350 USD, 2020-03-12} @ 30.535 USD
Assets:US:Interactive-Brokers 400 SMLF {30.5930 USD, 2020-03-12} @ 30.593 USD
Assets:US:Interactive-Brokers 1600 SMLF {30.5900 USD, 2020-03-12} @ 30.59 USD
Assets:US:Interactive-Brokers 600 SMLF {30.5950 USD, 2020-03-12} @ 30.595 USD
Assets:US:Interactive-Brokers 1600 SMLF {30.6200 USD, 2020-03-12} @ 30.62 USD
Assets:US:Interactive-Brokers 400 SMLF {30.6250 USD, 2020-03-12} @ 30.625 USD
Assets:US:Interactive-Brokers 100 SMLF {30.4800 USD, 2020-03-12} @ 30.48 USD
Assets:US:Interactive-Brokers 100 SMLF {30.4700 USD, 2020-03-12} @ 30.47 USD
Assets:US:Interactive-Brokers 200 SMLF {30.3250 USD, 2020-03-12} @ 30.325 USD
Assets:US:Interactive-Brokers 100 SMLF {30.4650 USD, 2020-03-12} @ 30.465 USD
Assets:US:Interactive-Brokers 400 SMLF {30.4650 USD, 2020-03-12} @ 30.465 USD
Assets:US:Interactive-Brokers 200 SMLF {30.3250 USD, 2020-03-12} @ 30.325 USD
Assets:US:Interactive-Brokers 700 SMLF {30.4750 USD, 2020-03-12} @ 30.475 USD
Assets:US:Interactive-Brokers 100 SMLF {30.5350 USD, 2020-03-12} @ 30.535 USD
Assets:US:Interactive-Brokers 300 SMLF {30.5550 USD, 2020-03-12} @ 30.555 USD
Assets:US:Interactive-Brokers 200 SMLF {30.3250 USD, 2020-03-12} @ 30.325 USD
Assets:US:Interactive-Brokers 200 SMLF {30.5515 USD, 2020-03-12} @ 30.5515 USDThose are all on the same date, so using a date doesn't help discriminate lots. I'm not sure what arbitrary label you could pick that is going to be meaningful or useful when I go to sell lots and need to correlate things with my broker -- they show the per-unit price of the shares in the lot. I suppose you could give a text-string label of "31.4550 USD" but...that just feels like I'm doing something wrong if I'm resorting to that.
On Tuesday, February 10, 2026 at 3:29:35 AM UTC+10:30 scott...@gmail.com wrote:I only do automatic lot specification so I'm not sure on the best approach to suggest, but I would presume your concerns are also easier to address by specifying date or label of a lot rather than a price, and let the more accurate price calculations run through.Neither of these really seem like plausible alternatives. When I submit a buy execution to my broker it gets filled like this:2020-03-12 * "SMLF" #20200228-tlh-rzv
Assets:US:Interactive-Brokers 1000 SMLF {31.4550 USD, 2020-03-12} @ 31.455 USD
Assets:US:Interactive-Brokers 400 SMLF {30.5350 USD, 2020-03-12} @ 30.535 USD
Ah yes, I’d completely forgotten about this, which my transactions are full of as well. Yet another reason @@ doesn’t work.
FWIW, I've never had my broker display different per-unit pricing in different reports. It is conceivable Vanguard does but (at least until their big push for better IT in the early 2000s) they historically had the worst IT infrastructure among major brokers by a fair margin so I'd expect it to be limited to them.
I wish I could say this were true. Take Fidelity whose IT infra hasn’t had the complaints that Vanguard has had. Until recently, they provided ofx, csv, and web display (ofx is gone now). Ofx had 5 digits, while csv/web has always had two.
On a different note, how do you get 4 decimal points with Interactive Brokers? Looking at my journal, I seem to get two through their flexquery downloads.