Online OFX import of Investment Statements
Stephen R. Besch
sbesch at buffalo.edu
Thu Jun 4 14:46:30 EDT 2009
I have worked up a patch to fix the problem with GnuCash not being able
to import stock transactions using the aqbanking interface.
Problem:
1) aqbanking's implementation of the OFX parser is incomplete,
handling only bank account transactions. However, it downloads complete
OFX files from all accessible institutions.
2) GnuCash already imports OFX files using the
File...Import...OFX/QFX option using libofx. It makes no sense to patch
the OFX parser in aqbanking to also handle investment transactions. It
would be a duplication of effort and likely source of inconsistencies to
use two different OFX parsers.
Solution:
1) Patch aqbanking to simply save a copy of the OFX data returned
from the bank, skipping any attempt at parsing the file.
2) Patch GnuCash to accept the file and pass it to the file import
routines which are already written for the File...Import...OFX/QFX
functionality.
Details:
This requires modifications to 5 files, 2 in aqbanking and 3 in GnuCash:
aqbanking-trunk/src/plugins/backends/aqofxconnect/plugin/network.c
aqbanking-trunk/src/plugins/backends/aqofxconnect/plugin/provider.c
gnucash-trunk/src/import-export/aqbanking/gnc-ab-gettrans.c
gnucash-trunk/src/import-export/ofx/gnc-ofx-import.h
gnucash-trunk/src/import-export/ofx/gnc-ofx-import.c
Description:
gnc-ab-gettrans.c is called when the user clicks on
Actions->Online Actions->Get Transactions... It calls aqbanking and
expects aqbanking to return a list of transactions, which are then
processed by subsequent code. For investments, this list is always
empty. The patch inserts code to create an empty file. The default is
"/dev/shm/aqbanking/ofx.ofx" and it may be optionally defined in the
environment variable AQOFX__OFX. It then calls aqbanking as usual. On
return, it calls gnc-ofx-import_with_filename with the file name of the
file containing the OFX data. This file is deleted after it is
processed. The original code to process the returned transaction list is
removed.
The existing routine - "void gnc-ofx-import(void)" - is renamed to
"void gnc-ofx-import_with_filename(char * PreSetFileName)" and patched
to use PreSetFileName as the input file. If PreSetFileName is a NULL
pointer, the GUI is called to get a file name, duplicating the existing
behavior. "void gnc-ofx-import(void)" is then re-defined as a simple
one-line routine that calls "gnc-ofx-import_with_filename(NULL)"
On the aqbanking side, "network.c:AO_Provider_SendAndReceive" is
modified to look for the presence of "/dev/shm/aqbanking/ofx.ofx", or
the file named in AQOFX__OFX, if there is one. If it finds a file there,
it overwrites its contents with the OFX data and closes the file and
returns a value of +1 as a signal to higher level code. If it does not
find the file, it proceeds to act exactly as before. In addition,
"provider.c:AO_Provider_RequestStatements" is patched to recognize the
return value of "1" and skip normal parsing of the data. Normal return
values are 0, which results in the previous behavior, and -1, which
results in an error. This behavior is unaffected by the patch.
I've tested the patch against Gnucash svn-trunk, r18102, aqbanking
svn-trunk r1702 and gwenhywfar svn trunk r1549 on both Hardy/amd64 and
Jaunty/i386. Repository and svn-trunk versions of libofx4 work equally
well.
Stephen R. Besch, Ph.D.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: aqbanking.diff
Type: text/x-diff
Size: 2823 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20090604/883dbd16/attachment-0007.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gnc-ab-gettrans.c
Type: text/x-csrc
Size: 8303 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20090604/883dbd16/attachment-0008.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gnc-ofx-import.c
Type: text/x-csrc
Size: 26301 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20090604/883dbd16/attachment-0009.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gnc-ofx-import.h
Type: text/x-chdr
Size: 1922 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20090604/883dbd16/attachment-0010.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gnucash.diff
Type: text/x-diff
Size: 6887 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20090604/883dbd16/attachment-0011.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: network.c
Type: text/x-csrc
Size: 14649 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20090604/883dbd16/attachment-0012.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: provider.c
Type: text/x-csrc
Size: 25528 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20090604/883dbd16/attachment-0013.bin>
More information about the gnucash-devel
mailing list