diff --git a/apps/monitor/calc.py b/apps/monitor/calc.py index 54f1194..80a2124 100644 --- a/apps/monitor/calc.py +++ b/apps/monitor/calc.py @@ -25,10 +25,10 @@ class Calc: out["crypto"] = crypto with connection.cursor() as cursor: - sql = """SELECT SUM(amount_after_fee) as after_fee, SUM(amount) as amount FROM `transaction` WHERE amount >= 0 and crypto_currency=%s and owner_id=%s""" + sql = """SELECT SUM(amount_after_fee) as after_fee, SUM(amount) as amount FROM `transaction` WHERE amount_after_fee > 0 and crypto_currency=%s and owner_id=%s""" cursor.execute(sql, [crypto, userid]) bought = cursor.fetchone() - if bought[1]: + if bought[0]: out["bought"] = bought[1] total_investment += Decimal(bought[1]) amount_kept += Decimal(bought[0]) @@ -36,10 +36,10 @@ class Calc: out["bought"] = None with connection.cursor() as cursor: - sql = """SELECT SUM(amount_before_fee) as before_fee, SUM(amount) as amount FROM `transaction` WHERE amount < 0 and crypto_currency=%s and owner_id=%s""" + sql = """SELECT SUM(amount_before_fee) as before_fee, SUM(amount) as amount 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[1]: + if sold[0]: out["sold"] = sold[1] total_investment += Decimal(sold[1]) amount_kept += Decimal(sold[0])