deal with transfers of once crypto currency between wallets

fixes #24
This commit is contained in:
2021-03-24 21:27:09 +01:00
parent 91c264e9cd
commit 6feb0e3ab5
+9
View File
@@ -85,6 +85,15 @@ class Calc:
else: else:
out["sold"] = None 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() 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() rateUSD = ExchangeRate.objects.filter(crypto_currency=crypto, fiat_currency='USD').order_by('-datetime_valid').first()