From 0675b015e5eecbca9fe70784b5cb0797e15467f7 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 31 Jan 2022 11:32:47 +0000 Subject: [PATCH] Implement remaining command --- handler/commands.py | 10 ++++++++++ handler/transactions.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/handler/commands.py b/handler/commands.py index 4db8df0..1838680 100644 --- a/handler/commands.py +++ b/handler/commands.py @@ -450,3 +450,13 @@ class IRCCommands(object): currency = spl[1] rtrn = revolut.shuffle(currency) msg(dumps(rtrn)) + + class remaining(object): + name = "r" + authed = True + helptext = "Show how much is left before we are able to withdraw funds." + + @staticmethod + def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify): + remaining = tx.get_remaining() + msg(f"Remaining: {remaining}USD") diff --git a/handler/transactions.py b/handler/transactions.py index 5d76566..7c51c3a 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -392,6 +392,35 @@ class Transactions(object): return False return ref_data["id"] + def get_total_usd(self): + total_usd_revolut = self.revolut.get_total_usd() + if total_usd_revolut is False: + return False + agora_wallet_xmr = self.agora.agora.wallet_balance_xmr() + if not agora_wallet_xmr["success"]: + return False + agora_wallet_btc = self.agora.agora.wallet_balance() + if not agora_wallet_btc["success"]: + return False + total_xmr_agora = agora_wallet_xmr["response"]["data"]["total"]["balance"] + total_btc_agora = agora_wallet_btc["response"]["data"]["total"]["balance"] + # Get the XMR -> USD exchange rate + xmr_usd = self.agora.cg.get_price(ids="monero", vs_currencies=["USD"]) + + # Get the BTC -> USD exchange rate + btc_usd = self.agora.cg.get_price(ids="bitcoin", vs_currencies=["USD"]) + + # Convert the Agora XMR total to USD + total_usd_agora_xmr = float(total_xmr_agora) * xmr_usd["monero"]["usd"] + + # Convert the Agora BTC total to USD + total_usd_agora_btc = float(total_btc_agora) * btc_usd["bitcoin"]["usd"] + + # Add it all up + total_usd_agora = total_usd_agora_xmr + total_usd_agora_btc + total_usd = total_usd_agora + total_usd_revolut + return total_usd + def get_total(self): total_usd_revolut = self.revolut.get_total_usd() if total_usd_revolut is False: @@ -431,3 +460,13 @@ class Transactions(object): (total_usd_agora_xmr, total_usd_agora_btc), # Total USD balance in only Agora (total_xmr_agora, total_btc_agora), ) # Total XMR and BTC balance in Agora + + def get_remaining(self): + total_usd = self.get_total_usd() + if not total_usd: + return False + + withdraw_threshold = float(settings.Money.BaseUSD) + float(settings.Money.WithdrawLimit) + remaining = withdraw_threshold - total_usd + + return remaining