From 6feb0e3ab5c1e3ddf4f5be4c753ff00a84b52cb5 Mon Sep 17 00:00:00 2001 From: Timotheus Pokorra Date: Wed, 24 Mar 2021 21:27:09 +0100 Subject: [PATCH] deal with transfers of once crypto currency between wallets fixes #24 --- apps/monitor/calc.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/monitor/calc.py b/apps/monitor/calc.py index 0778f1e..b96952a 100644 --- a/apps/monitor/calc.py +++ b/apps/monitor/calc.py @@ -85,6 +85,15 @@ class Calc: else: out["sold"] = None + # moving coins to other wallet with fees. + with connection.cursor() as cursor: + sql = """SELECT SUM(amount_after_fee) as after_fee FROM `transaction` WHERE amount_before_fee = 0 and crypto_currency=%s and owner_id=%s""" + cursor.execute(sql, [crypto, userid]) + sold = cursor.fetchone() + if sold[0]: + # total_investment -= Decimal(sold[1]) + amount_kept += Decimal(sold[0]) + rateEUR = ExchangeRate.objects.filter(crypto_currency=crypto, fiat_currency='EUR').order_by('-datetime_valid').first() rateUSD = ExchangeRate.objects.filter(crypto_currency=crypto, fiat_currency='USD').order_by('-datetime_valid').first()