From 0b9cd93369a3187cd254f2ad58151b882d8047ef Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 9 Feb 2022 18:45:43 +0000 Subject: [PATCH] Implement accounting for open trade value as part of total remaining --- handler/commands.py | 10 ++++++++++ handler/transactions.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/handler/commands.py b/handler/commands.py index e88656c..a30d7bd 100644 --- a/handler/commands.py +++ b/handler/commands.py @@ -441,3 +441,13 @@ class IRCCommands(object): def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify): remaining = tx.get_remaining() msg(f"Remaining: {remaining}USD") + + class total_remaining(object): + name = "tr" + authed = True + helptext = "Show how much is left before we are able to withdraw funds (including open trades)." + + @staticmethod + def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify): + remaining = tx.get_total_remaining() + msg(f"Total remaining: {remaining}USD") diff --git a/handler/transactions.py b/handler/transactions.py index eac6d44..9355a4f 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -458,3 +458,37 @@ class Transactions(object): remaining = withdraw_threshold - total_usd return remaining + + def get_open_trades_usd(self): + dash = self.agora.wrap_dashboard() + if dash is False: + return False + + rates = self.agora.get_rates_all() + cumul_usd = 0 + for contact_id, contact in dash.items(): + amount = contact["data"]["amount"] + currency = contact["data"]["currency"] + if not contact["data"]["is_selling"]: + continue + if currency == "USD": + cumul_usd += amount + else: + rate = rates[currency] + amount_usd = float(amount) / rate + print("AMOUTN USD", amount_usd) + cumul_usd += amount_usd + + return cumul_usd + + def get_total_remaining(self): + total_usd = self.get_total_usd() + total_trades_usd = self.get_open_trades_usd() + if not total_usd: + return False + total_usd += total_trades_usd + + withdraw_threshold = float(settings.Money.BaseUSD) + float(settings.Money.WithdrawLimit) + remaining = withdraw_threshold - total_usd + + return remaining