Transactions module#
Module transactions/transactions.py houses three classes that
work on the live transaction ledger:
Performance– computes the Highcharts series for the Assets section of Transactions.Transactions– pandas dataframing of the ledger, parent-chain tracing, root-investment pile computation.Graph– per-transaction parent / child PNG diagram, persisted by thegenerate_graphs()task.
Performance#
Its get_data() method returns the Highcharts
series shown in the Assets section of Transactions – the
profit (or market-value) curve of each asset over the period it
was held.
Construct
Performance(type, user=None, currency=None, profit=False, use_cache=True):
type– one of"share","index","coin","etf".user– restrict to a single user. If omitted,get_data()recomputes (and warms cache) for every user with matching holdings.currency– restrict to one currency. If omitted, every currency the user trades in is processed.profit–Truereturns the profit curve;False(default) returns the market-value curve.use_cache– whenFalse, cache is bypassed and recomputed.
- class richy.transactions.transactions.Performance(type, user=None, currency=None, profit=False, use_cache=True)[source]#
Bases:
objectCalculates performance stats for transactions.
- Performance.get_data()[source]#
Fetches data from database/cache for shares/indexes/coins/etfs and calculates it’s performance (market value or profit) over time.
- Returns:
List of tuples (user, Data for Highcharts).
- Return type:
Output structure from get_data():
[
{
"name": "BTC",
"data": [
[1504656000000, None], # Timestamp, price
[1504742400000, None],
[1504828800000, None],
[1504915200000, None],
...
],
},
{
"name": "ETC",
"data": [
[1545955200000, 422.4],
[1546041600000, 415.2],
[1546128000000, 424.8],
[1546214400000, 404.0],
[1546300800000, 418.4],
],
},
...
]
Transactions#
- class richy.transactions.transactions.Transactions(user)[source]#
Bases:
objectHandles transactions data digging.
- Transactions.get_transaction_basic_stats(closed=None)[source]#
Compiles a dataframe with all (see
closedparam) transactions and it’s basic stats.DF looks like this:
exchange amount price fee symbol currency is_deposit is_closing is_closed date closed_on parents balance_in_time type is_leaf root_parent root_investment pk 1 Kraken 200.0 0.25 1.0 XRP USD True False False 2018-12-01 None NaN -51.0 coin False 1 51.0 3 Binance 100.0 0.25 0.0 XRP USD False False False 2019-12-02 None 2.0 -25.0 coin False 1 51.0 5 Kraken 100.0 0.25 0.0 ETC USD False False False 2019-12-02 None 4.0 -25.0 coin True 1 51.0 2 Kraken -100.0 0.25 0.0 XRP USD False False False 2019-12-02 None 1.0 25.0 coin False 1 51.0 4 Kraken -100.0 0.25 0.0 XRP USD False False False 2019-12-02 None 1.0 25.0 coin False 1 51.0 8 Binance 100.0 0.25 0.0 XRP USD False False True 2019-12-05 None 7.0 -25.0 coin False 6 50.0 6 Binance 50.0 1.00 0.0 BTC USD True False False 2019-12-05 None NaN -50.0 coin False 6 50.0 7 Binance -25.0 1.00 0.0 BTC USD False False True 2019-12-05 None 6.0 25.0 coin False 6 50.0 9 Binance -25.0 1.00 0.0 BTC USD False False True 2019-12-06 None 6.0 25.0 coin False 6 50.0 10 Binance 50.0 0.50 0.0 ETH USD False False False 2019-12-06 None 9.0 -25.0 coin False 6 50.0 11 Binance -25.0 0.50 0.0 ETH USD False False False 2019-12-07 None 10.0 12.5 coin False 6 50.0 12 Binance 50.0 0.25 0.0 TRX USD False False False 2019-12-07 None 11.0 -12.5 coin True 6 50.0 13 Binance -200.0 0.25 0.0 XRP USD False True True 2019-12-12 None 8.0 50.0 coin True 6 50.0 13 Binance -200.0 0.25 0.0 XRP USD False True True 2019-12-12 None 3.0 50.0 coin True 1 51.0
If
closedis false then following columns are added:current_price
market_value
market_value_perc
DF looks like this:
exchange amount price fee symbol currency is_deposit is_closing is_closed date closed_on parents balance_in_time type is_leaf root_parent root_investment current_price market_value market_value_perc pk 1 Kraken 200.0 0.25 1.0 XRP USD True False False 2018-12-01 None NaN -51.0 coin False 1 51.0 0 0.0 0.0 3 Binance 100.0 0.25 0.0 XRP USD False False False 2019-12-02 None 2.0 -25.0 coin False 1 51.0 0 0.0 0.0 2 Kraken -100.0 0.25 0.0 XRP USD False False False 2019-12-02 None 1.0 25.0 coin False 1 51.0 0 -0.0 0.0 4 Kraken -100.0 0.25 0.0 XRP USD False False False 2019-12-02 None 1.0 25.0 coin False 1 51.0 0 -0.0 0.0 8 Binance 100.0 0.25 0.0 XRP USD False False True 2019-12-05 None 7.0 -25.0 coin False 6 50.0 0 0.0 0.0 13 Binance -200.0 0.25 0.0 XRP USD False True True 2019-12-12 None 8.0 50.0 coin True 6 50.0 0 -0.0 0.0 13 Binance -200.0 0.25 0.0 XRP USD False True True 2019-12-12 None 3.0 50.0 coin True 1 51.0 0 -0.0 0.0 5 Kraken 100.0 0.25 0.0 ETC USD False False False 2019-12-02 None 4.0 -25.0 coin True 1 51.0 0 0.0 0.0 6 Binance 50.0 1.00 0.0 BTC USD True False False 2019-12-05 None NaN -50.0 coin False 6 50.0 0 0.0 0.0 7 Binance -25.0 1.00 0.0 BTC USD False False True 2019-12-05 None 6.0 25.0 coin False 6 50.0 0 -0.0 0.0 9 Binance -25.0 1.00 0.0 BTC USD False False True 2019-12-06 None 6.0 25.0 coin False 6 50.0 0 -0.0 0.0 10 Binance 50.0 0.50 0.0 ETH USD False False False 2019-12-06 None 9.0 -25.0 coin False 6 50.0 0 0.0 0.0 11 Binance -25.0 0.50 0.0 ETH USD False False False 2019-12-07 None 10.0 12.5 coin False 6 50.0 0 -0.0 0.0 12 Binance 50.0 0.25 0.0 TRX USD False False False 2019-12-07 None 11.0 -12.5 coin True 6 50.0 0 0.0 0.0
Direct consumers:
Open Transactions list page: transactions overview chart (
TransactionOverviewChart).Open / Closed Transactions list pages: investment vs revenue column chart and profit/investment pie chart (
TransactionsBasicColumnChart/TransactionBasicPieChart).Transaction detail page: investment vs revenue column chart (
TransactionDetailColumnChart); item-price chart date range (FetchItemPricesAjaxView).Per-asset overview pages (shares/coins/etfs/indexes): possession-percentage list, via
BaseUserItemCreateView.get_open_items_possession_stats.Coin list page: staking ratio pie (
OpenStakingsRatioPieChart).
Indirect consumers (via internal pipeline):
Performance.get_data– asset-allocation and profit charts in the Assets section.Graph.generate– per-transaction parent/child PNG on the transaction detail page.
- Parameters:
closed (bool) – If False already closed transaction are not included. If None all transaction are included.
- Returns:
Dataframe with grouped transaction stats or empty dataframe in case of no transactions.
- Return type:
DataFrame
- static Transactions.get_pile_stats(df)[source]#
Takes dataframe from
get_transaction_basic_stats()(the givendfparam) method and converts it into a pile (seegroup_deposit_groups()) with stats. The stats are basic stats for charts and overviews.Pile is a list of pairs. Each pair has 2 items:
root transactions list (key)
- stats - objects with following keys
open_symbols
investments
incomes
fees
Pile looks like this:
[ ( [6], { 'open_symbols': [{ 'symbol': 'QCOM', 'amount': 14.0, 'market_price': 1271.3400000000001 }], 'investments': [{6: 780.2199999999999}], # key is transaction PK 'incomes': [], 'fees': 7.95 } ) ]
It’s used for following charts:
transactions overview chart in Transactions
- Parameters:
df (pandas.DataFrame)
- Returns:
Pile - for structure see above.
- Return type:
Graph#
- class richy.transactions.transactions.Graph(transaction)[source]#
Bases:
objectGenerates graphviz graph for the given transaction.