Can't find commodity using gnc_commodity_table_lookup()

Derek Atkins warlord at MIT.EDU
Tue Nov 11 08:43:42 EST 2008


Hi,

Justin Mazzola Paluska <jmp at MIT.EDU> writes:

> Hi,
>
> I’m trying to write a small program to add (historical) prices to my
> gnucash file.  I’m basing my approach off of some code I found on the
> gnucash-users list
> (http://article.gmane.org/gmane.comp.gnome.apps.gnucash.user/25065/match=historical+prices+bond).
> Essentially, my code opens up the book, tries to find a commodity
> (hard coded to “GOOG” for testing) and then creates a new price for
> that commodity.  I’ve attached my code to this message, as well as an
> example.gnucash file that I’ve been using.
>
> Unfortunately, I’m getting stuck — even though I’ve defined a GOOG
> security in my gnucash file, I can’t seem to retrieve it from my file
> using “gnc_commodity_table_lookup()”: I always get NULL for my
> commodity, even though I can zless the example.gnucash file and can
> see my commodity, as well as edit it in gnucash.
>
> To wit, here’s a transcript of a session with my code:
[snip]
>     if (gnc_commodity_table_has_namespace(table, "NYSE")) {
> 	printf("Has NYSE namespace\n");
>     }
>
>     commodity = gnc_commodity_table_lookup(table,
> 					   GNC_COMMODITY_NS_NYSE,
> 					   "GOOG");
>     if (!commodity) {
> 	printf("commodity is NULL\n");
> 	return 1;
>     }

Well, for one thing I would either use "NYCE" or GNC_COMMODITY_NS_NYSE
in both places.  Yes, technically they should be the same, but you might
as well test that theory.

I didn't look into the data file to verify that you configured GOOG
under NYCE.

-derek
-- 
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord at MIT.EDU                        PGP key available


More information about the gnucash-devel mailing list