Transactions#

A class placed in transactions.py file. All transaction digging (pandas dataframing) is placed here. All methods that fetch data and calculates some metrics are mainly placed in this class.

get_transaction_basic_stats()#

Transactions.get_transaction_basic_stats(closed=None)#

Compiles a dataframe with all (see closed param) 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 closed is 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

It’s used for following charts:

  • transactions overview chart in Transactions

  • investment vs revenue column chart in Transactions

  • profit pie chart in closed Transactions

  • investment pie chart in open Transactions

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

get_pile_stats()#

static Transactions.get_pile_stats(df)#

Takes dataframe from get_transaction_basic_stats() (the given df param) method and converts it into a pile (see group_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 strucutre see above.

Return type:

list