how to set Gnucash commodities (exchange rates) from Python?

Felix Schwarz felix.schwarz at oss.schwarz.eu
Sat Jan 3 04:24:49 EST 2015


I'm trying to import some transactions into my gnucash db using Python. Adding
the transactions itself is no problem but some of them refer to accounts with
different currencies and I don't know how to set the exchange rate using the
Python API.

For example I have a EUR and a USD account and I transfer some USD to EUR. If
I don't care about commities gnucash will create an "imbalance" account.

After reading some examples it seems as if gnucash has a "global" (per gnucash
file) internal price database which contains triples
  (commodity_1, commodity_2, date) -> rate

Is just adding a new triple to the price database is enough for a
multi-currency transaction? Or do I have to set the correct commodity also in
the splits/transaction?


Assuming my understanding of gnucash's commodities is not flawed there are two
aspects of commodities which worry me a bit:
In general gnucash seems to assume that there is one "true" exchange rate for
any given point in time.
1. What is the time resolution for prices? I might have different
   transactions on the same day with different rates.
2. Similarly currency exchange rates are not the same everywhere even at the
   exact same point in time. For example PayPal has (significantly worse)
   rates than my bank. Is it possible somehow to set a specific rate
   for a transaction?
   The only workaround I could think of for this would be to create a new
   commodity (e.g. "PayPal USD") but that seems quite messy.

Felix


More information about the gnucash-user mailing list