piecash.core.commodity module¶
-
class
piecash.core.commodity.
Price
(commodity, currency, date, value, type=u'unknown', source=u'user:price')[source]¶ Bases:
piecash._declbase.DeclarativeBaseGuid
A single Price for a commodity.
-
date
¶ datetime.datetime
– datetime object representing the time 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=u'', quote_flag=0, quote_source=None, quote_tz=None, book=None)[source]¶ 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)[source]¶ 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, ...)
-