Confused about transaction/split
Niranjan Rao
nhrdls at gmail.com
Sun May 24 15:23:09 EDT 2026
Greetings,
I am trying to add a shares purchase transaction. I've account for given
stock/commodity and a cash account from which money will be transferred
As I understand one part of the split should come from cash which will
be currency or dollar value. Other split will be number of shares
purchased for that money.
I am trying to use API (through my Java library) to create a transaction
and not able to get it right. I am especially getting confused about the
value and amount parts. I am not sure which field will represent the
quantity or number of shares purchased.
Here is the general flow I am calling from Java
Create transaction - xaccMallocTransaction
Set currency as my commodity of stock - xaccTransSetCurrency
Create split xaccTransSetCurrency
Set appropriate account and parent xaccSplitSetAccount, xaccSplitSetParent
I now have three data fields available - total amount in dollar
(moneySpent), number of shares purchased (quantity) and price (price) at
which they were purchased. I tried various combinations of
xaccSplitSetAmount, xaccSplitSetValue, xaccSplitSetSharePriceAndAmount
But not matter what I do, I always get imbalance record or price gets
calculated wrong. In general split entry is wrong. Mirroring split from
cash account looks correct. At least that account shows the entry the
way it should be.
Can you please help me with the right method calls and parameters I need
to pass get the transaction right. I've intentionally used slightly
different variable names in the email so as to avoid the confusion with
the actual parameter names used in header files.
Regards,
Niranjan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20260524/8c8c2bdd/attachment.htm>
More information about the gnucash-devel
mailing list