Programming Question regarding prices table

John Ralls jralls at
Sun Oct 30 17:20:33 EDT 2016

> On Oct 30, 2016, at 11:12 AM, David T. via gnucash-devel <gnucash-devel at> wrote:
> Hi,
> As I mentioned yesterday, I am trying my hand at scripting a program that can generate monthly entries for the price db for all holdings in a GnuCash data file. Thus far, I am having a fine time cracking the crusty shell of perl, and have gotten a script that will retrieve the right prices and print them to the console. I believe am close to finishing the script, but I need some help with a couple of points related directly to the data structure of the prices table in the database.
> First, and probably more prosaically, I am challenged again by the nature of the prices stored in GnuCash. They are stored as separate number and denominator, while Finance::QuoteHist returns prices as a decimal number. I want to know how best to convert these decimals correctly into GnuCash’s format. Should I use the commodity fraction to multiply the price, and store fraction in value_denom? Or is there some other way I should make this conversion? 
> Next, and much more problematically, is the fact that every price record includes a currency_guid. I am unsure how exactly I would identify this guid consistently, since the record in commodities doesn’t store this information. Neither does Finance::QuoteHist return the currency for the price returned, which precludes a query into commodities based on the QuoteHist currency. It’s not even possible to use query the account table, since the account is denominated in the commodity, not the underlying currency. Can anyone shed light on how I would determine the value for currency_guid for a given commodity?


It doesn't really matter how you convert the float to a rational as long as it's the same number. An easy way would be to shift the decimal two places, truncate, and use 100 for the denominator. The price isn't the number of shares or whatever in the security, it's how much one share was worth in some currency (see next paragraph) at the time of the quote.

The currency guid is for the currency that the quote is in. If Quote-Hist doesn't include a field for it then your script will have to fill it in somehow. If all of your securities are in one currency then you can just hardcode it, otherwise you'll have to make something like a mapping table between security and commodity.

John Ralls

More information about the gnucash-devel mailing list