piecash.core.commodity module — Python interface to GnuCash documents 0.14.1 documentation

# piecash.core.commodity module

class `piecash.core.commodity.` `Price`(commodity, currency, date, value, type='unknown', source='user:price')

  Bases: `piecash._declbase.DeclarativeBaseGuid`

  A single Price for a commodity.

  `commodity`

    `Commodity` – commodity to which the Price relates

  `currency`

    `Commodity` – currency in which the Price is expressed

  `date`

    `datetime.date` – date object representing the day at which the price is relevant

  `source`

    str – source of the price

  `type`

    str – last, ask, bid, unknown, nav

  `value`

    `decimal.Decimal` – the price itself

class `piecash.core.commodity.` `Commodity`(namespace, mnemonic, fullname, fraction=100, cusip='', quote_flag=0, quote_source=None, quote_tz=None, book=None)

  Bases: `piecash._declbase.DeclarativeBaseGuid`

  A GnuCash Commodity.

  `cusip`

    str – cusip code

  `fraction`

    int – minimal unit of the commodity (e.g. 100 for 1/100)

  `namespace`

    str – CURRENCY for currencies, otherwise any string to group multiple commodities together

  `mnemonic`

    str – the ISO symbol for a currency or the stock symbol for stocks (used for online quotes)

  `quote_flag`

    int – 1 if piecash/GnuCash quotes will retrieve online quotes for the commodity

  `quote_source`

    str – the quote source for GnuCash (piecash always use yahoo for stock and quandl for currencies

  `quote_tz`

    str – the timezone to assign on the online quotes

  `base_currency`

    `Commodity` – The base_currency for a commodity:

    - if the commodity is a currency, returns the “default currency” of the book (ie the one of the root_account)
    - if the commodity is not a currency, returns the currency encoded in the quoted_currency slot
  `accounts`

    list of `piecash.core.account.Account` – list of accounts which have the commodity as commodity

  `transactions`

    list of `piecash.core.transaction.Transaction` – list of transactions which have the commodity as currency

  `prices`

    iterator of `Price` – iterator on prices related to the commodity (it is a sqlalchemy query underneath)

  `update_prices`(start_date=None)

    Retrieve online prices for the commodity:

    - for currencies, it will get from quandl the exchange rates between the currency and its base_currency
    - for stocks, it will get from yahoo the daily closing prices expressed in its base_currency

    Parameters: | start_date (`datetime.date`) – prices will be updated as of the start_date. If None, start_date is today 7 days. (-) –

    Note

    if prices are already available in the GnuCash file, the function will only retrieve prices as of the max(start_date, last quoted price date)

    Todo

    add some frequency to retrieve prices only every X (week, month, …)