OFX Investment Import -- Was Re: [Aqbanking-devel] Direct Investment import to GNUCash

Hubert Bahr hab at hbahr.org
Wed Dec 13 04:32:09 EST 2006

Christian Stimming wrote:
> As you have already noticed, there are two ways of importing OFX data
> into GnuCash:
> #1 Import data from an OFX file
> #2 Use "OFX DirectConnect" for direct data retrieval from a bank server
> that happens to send its data in the OFX format
> For #1, questions about particular data fields that don't show up in
> GnuCash have to be solved in libofx and GnuCash and this is probably the
> easier problem. First you would have to check for code in libofx (or add
> it) that reads this particular data from the OFX file (or stream). Then
> you would have to add interface functions to libofx that make this data
> accessible to the users of libofx. Eventually you have to add the
> retrieval functions into gnucash's ofx import code in
> src/import-export/ofx/gnc-ofx-import.c although this might also require
> additions to the "generic importer" code in src/import-export/*.c.
As suggested I am starting with OFX Import.  Investigation of libofx
shows that it supports sufficient fields to provide the necessary data,
based on the examination of its ofxdump utility.  The code of this
utility provides examples of the library data elements that need to
used.  A dump of test file from my investment broker helps me identify
which fields they provide and the information contained in them.
> Note that the QIF importer does not share any program parts with any of
> the other importer features in GnuCash. It is very well possible that
> because of this, it supports a whole lot of other data that the others
> don't support.
Initially I believed that QIF importer might provide a guide, however it
doesn't seem similar at all to ofximport even the method of targeting
the entry into a transaction.
> Discussion about the necessary libofx extensions should happen solely on
> the libofx-devel mailing list. Discussion about the necessary GnuCash
> extensions are warmly welcome on gnucash-devel. The connection between
> both can be discussed on both, of course.
> On the other hand, for #2 you not only have to extend libofx and
> GnuCash, but additionally you have to extend aqbanking. The issue is
> that aqbanking tries to be a *general* online banking library, hence all
> data types are intended to present some sort of common denominator of
> all protocols that are being supported. For aqbanking, OFX DirectConnect
> is only one out of several possible data retrieval interfaces. You would
> have to find an interface that represents your additional data in a way
> that is still abstract enough for the general interface in aqbanking. I
> can imagine this to be the hardest part of this extension.
> http://bugzilla.gnome.org/show_bug.cgi?id=347741 describes the RFE
> you're asking for
> I'd suggest you should work on #1. First you should check whether libofx
> provides the data through some interface, and if it doesn't, you would
> have to add code to libofx. Then you should work on gnucash's
> src/import-export/ofx/gnc-ofx-import.c (please make sure to use SVN
> trunk for such additions), add the code and keep some documentation
> somewhere about the necessary additions (so that we know what the
> DirectConnect importer will need as well). You should probably start a
> wiki page http://wiki.gnucash.org for keeping those notes, and/or start
> an extra Bugzilla RFE
> http://bugzilla.gnome.org/enter_bug.cgi?product=GnuCash which is useful
> if you want to upload test files (file upload in the wiki is currenly
> not available).
> Regards
> Christian
I have established bug 385366 as a collection point for file transfers,
and uploaded two files the first id 78266 is an ofx file to be used as
the initial test case.  The second id# 78267 is the output of ofxdump.
It will be used for the initial discussions.  I have joined the wiki but
I am not quite sure on how to tie the page in to the rest.  I plan on
posting findings and hints that I have found useful as I progress.

It looks to me that the transactions from the broker have one end tied
to the brokerage account and the other to either external accounts such
as (income, distribution, or deposit) or internal accounts to various
commodities.  However, some transactions have the same id that implies
that they could be combined such as having the income account and a
commodity account as the terminal points for a dividend reinvestment.

I am not sure how to handle the sale and purchase of commodities where
the key value in the commodity account is number of shares but the
balancing split is in currency.  The transaction from the broker gives #
of units, the Unit Price and the Total money amount, however due to
round off they don't always balance.  As such I would be tempted to
enter the Total money amount, and the # of units and calculate the

Where would I find the appropriate functions for passing these values to
the engine.  Some of them seem to be described in
src/engine/Transaction.h but the list seems incomplete.

To me the majority of the changes look like they belong in
ofx_proc_transaction_cb of


More information about the gnucash-devel mailing list