<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">Thank you John. I made bit more
      progress, ended up uncompressing/expanding my sample file and then
      adding values like 1 or 2 and then comparing the results with
      previous entries.</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">It started working properly after I
      changed the transaction currency from commodity to actual
      currency. I am still struggling with another entry I want to add,
      but your email and my research will hopefully put me on right
      track.</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Regards,</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Niranjan</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">On 5/24/26 20:22, John Ralls wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:4B758886-9E55-4862-9E43-006E1A2146E4@ceridwen.us">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      Niranjan,
      <div><br>
      </div>
      <div>The transaction carries the date, description, and the
        CURRENCY that the transaction will be balanced in. In theory
        that doesn’t have to be either the currency in which the stock
        is priced nor the currency of the account from which you
        transfer the payment, but the more currencies that are involved
        the harder it is for GnuCash’s balancing code to get it right,
        so everything works best if there’s only one currency.</div>
      <div><br>
      </div>
      <div>Before you create the transaction you must already have
        created the stock’s commodity and an account of type STOCK or
        MUTUAL FUND denominated in that commodity. That account should
        be parented with an account of either type ASSET or type BANK
        denominated in the currency in which the stock trades. In
        GnuCash debits are positive numbers and credits are negative
        numbers. You’ll create a split in that account with the number
        of shares as the amount and the value as the extended value
        (i.e. amount * price) in the transaction currency. You’ll create
        a second split in the cash account with the amount set to the
        negative equivalent in the cash account’s currency and value as
        the negative extended value in the transaction currency.</div>
      <div><br>
      </div>
      <div>So the simplest example is all currencies are, say, INR. </div>
      <div>Transaction.Date = 2026-05-31, Transaction.Description = “Buy
        XYZ 100 @ 25.00 INR/share”, Transaction.Currency = INR</div>
      <div>Split1.Account = /Assets/Investment/Broker/Stocks/XYZ,
        Split1.Amount = 100, Split1.Value = 2500.00</div>
      <div>Split2.Account = /Assets/nvestment/Broker/Cash, Split2.Amount
        = -2500.00, Split2.Value = -2500.00.</div>
      <div><br>
      </div>
      <div>A more complicated example where the stock and cash account
        are still in INR but the transaction currency is USD. Today’s
        exchange rate is .010 USD = 1 INR so it will look like</div>
      <div><br>
      </div>
      <div>
        <div>
          <div>Transaction.Date = 2026-05-31, Transaction.Description =
            “Buy XYZ 100 @ 25.00 INR/share”, Transaction.Currency = USD</div>
          <div>Split1.Account = /Assets/Investment/Broker/Stocks/XYZ,
            Split1.Amount = 100, Split1.Value = 25.00</div>
          <div>Split2.Account = /Assets/nvestment/Broker/Cash,
            Split2.Amount = -2500.00, Split2.Value = -25.00.</div>
          <div><br>
          </div>
          <div>Regards,</div>
          <div>John Ralls</div>
          <div><br>
          </div>
          <blockquote type="cite">
            <div>On May 24, 2026, at 12:23, Niranjan Rao
              <a class="moz-txt-link-rfc2396E" href="mailto:nhrdls@gmail.com"><nhrdls@gmail.com></a> wrote:</div>
            <br class="Apple-interchange-newline">
            <div>
              <meta http-equiv="content-type"
                content="text/html; charset=UTF-8">
              <div>
                <p>Greetings,</p>
                <p>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</p>
                <p>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. </p>
                <p>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.</p>
                <p>Here is the general flow I am calling from Java </p>
                <p><br>
                </p>
                <p>Create transaction - <span
style="background-color:#ffffff;padding:0px 0px 0px 2px;"><span
style="background-color: rgb(255, 255, 255); font-family: Monospace; font-size: 10pt; white-space: pre;"><span
                    style=""></span><span
style="background-color: rgb(212, 212, 212); font-style: italic;">xaccMallocTransaction</span></span></span></p>
                <p>Set currency as my commodity of stock - <span
style="background-color:#ffffff;padding:0px 0px 0px 2px;"><span
style="background-color: rgb(255, 255, 255); font-family: Monospace; font-size: 10pt; white-space: pre;"><span
                    style=""></span><span
style="background-color: rgb(212, 212, 212); font-style: italic;">xaccTransSetCurrency</span></span></span></p>
                <p>Create split <span
style="background-color:#ffffff;padding:0px 0px 0px 2px;"><span
style="background-color: rgb(255, 255, 255); font-family: Monospace; font-size: 10pt; white-space: pre;"><span
                    style=""></span><span
style="background-color: rgb(212, 212, 212); font-style: italic;">xaccTransSetCurrency</span></span></span></p>
                <p><br>
                </p>
                <p>Set appropriate account and parent <span
style="background-color:#ffffff;padding:0px 0px 0px 2px;"><span
style="background-color: rgb(255, 255, 255); font-family: Monospace; font-size: 10pt; white-space: pre;"><span
                    style=""></span><span
style="background-color: rgb(212, 212, 212); font-style: italic;">xaccSplitSetAccount, </span></span></span><span
style="background-color:#ffffff;padding:0px 0px 0px 2px;"><span
style="background-color: rgb(255, 255, 255); font-family: Monospace; font-size: 10pt; white-space: pre;"><span
                    style=""></span><span
style="background-color: rgb(212, 212, 212); font-style: italic;">xaccSplitSetParent</span></span></span></p>
                <p><br>
                </p>
                <p>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 <span
style="background-color:#ffffff;padding:0px 0px 0px 2px;"><span
style="background-color: rgb(255, 255, 255); font-family: Monospace; font-size: 10pt; white-space: pre;"><span
                    style=""></span><span
style="background-color: rgb(212, 212, 212); font-style: italic;">xaccSplitSetAmount, </span></span></span><span
style="background-color:#ffffff;padding:0px 0px 0px 2px;"><span
style="background-color: rgb(255, 255, 255); font-family: Monospace; font-size: 10pt; white-space: pre;"><span
                    style=""></span><span
style="background-color: rgb(212, 212, 212); font-style: italic;">xaccSplitSetValue, </span></span></span><span
style="background-color:#ffffff;padding:0px 0px 0px 2px;"><span
style="background-color: rgb(255, 255, 255); font-family: Monospace; font-size: 10pt; white-space: pre;"><span
                    style=""></span><span
style="background-color: rgb(212, 212, 212); font-style: italic;">xaccSplitSetSharePriceAndAmount</span></span></span></p>
                <p><br>
                </p>
                <p>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.</p>
                <p>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.</p>
                <p><br>
                </p>
                <p>Regards,</p>
                <p>Niranjan</p>
                <p><br>
                </p>
              </div>
              _______________________________________________<br>
              gnucash-devel mailing list<br>
              <a class="moz-txt-link-abbreviated" href="mailto:gnucash-devel@gnucash.org">gnucash-devel@gnucash.org</a><br>
              <a class="moz-txt-link-freetext" href="https://lists.gnucash.org/mailman/listinfo/gnucash-devel">https://lists.gnucash.org/mailman/listinfo/gnucash-devel</a><br>
            </div>
          </blockquote>
        </div>
      </div>
    </blockquote>
  </body>
</html>