Programming Question regarding prices table

David T. sunfish62 at yahoo.com
Sun Oct 30 14:12:37 EDT 2016


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?

TIA,
David


More information about the gnucash-devel mailing list