From 49e02ce5499051e030e5704de2fa81bb3a5c7d88 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 25 Jan 2022 17:54:42 +0000 Subject: [PATCH] Move totals code to transactions --- handler/agora.py | 7 +++++++ handler/app.py | 1 + handler/commands.py | 51 +++++++++++++-------------------------------- 3 files changed, 23 insertions(+), 36 deletions(-) diff --git a/handler/agora.py b/handler/agora.py index f4376f6..9dd61d2 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -621,3 +621,10 @@ class Agora(object): payload = {"tradeId": contact_id, "password": settings.Agora.Pass} rtrn = self.agora._api_call(api_method=f"contact_release/{contact_id}", http_method="POST", query_values=payload) return rtrn + + def withdraw_funds(self): + """ + Withdraw excess funds to our XMR/BTC wallets. + """ + # wallet_xmr = + pass diff --git a/handler/app.py b/handler/app.py index e3673d5..1759796 100755 --- a/handler/app.py +++ b/handler/app.py @@ -76,6 +76,7 @@ if __name__ == "__main__": # Pass Agora and IRC to Transactions and Transactions to IRC tx.set_agora(agora) tx.set_irc(irc) + tx.set_revolut(revolut) irc.set_tx(tx) agora.set_tx(tx) diff --git a/handler/commands.py b/handler/commands.py index e82053c..2ccc27b 100644 --- a/handler/commands.py +++ b/handler/commands.py @@ -193,42 +193,11 @@ class IRCCommands(object): @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): - total_usd_revolut = revolut.get_total_usd() - if total_usd_revolut is False: - msg("Error getting Revolut balance.") - return - agora_wallet_xmr = agora.agora.wallet_balance_xmr() - if not agora_wallet_xmr["success"]: - msg("Error getting Agora XMR balance.") - return - agora_wallet_btc = agora.agora.wallet_balance() - if not agora_wallet_btc["success"]: - msg("Error getting Agora BTC balance.") - return - 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 = agora.cg.get_price(ids="monero", vs_currencies=["USD"]) - - # Get the BTC -> USD exchange rate - btc_usd = 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 - - # Convert the total USD price to GBP and SEK - rates = agora.get_rates_all() - price_sek = rates["SEK"] * total_usd - price_usd = total_usd - price_gbp = rates["GBP"] * total_usd - msg(f"SEK: {price_sek} | USD: {price_usd} | GBP: {price_gbp}") + totals_all = tx.get_total() + totals = totals_all[0] + wallets = totals_all[1] + msg(f"Totals: SEK: {totals[0]} | USD: {totals[1]} | GBP: {totals[2]}") + msg(f"Wallets: XMR USD: {wallets[0]} | BTC USD: {wallets[1]}") class ping(object): name = "ping" @@ -430,3 +399,13 @@ class IRCCommands(object): price_usd = xmr_prices["bitcoin"]["usd"] price_gbp = xmr_prices["bitcoin"]["gbp"] msg(f"SEK: {price_sek} | USD: {price_usd} | GBP: {price_gbp}") + + class withdraw(object): + name = "withdraw" + authed = True + helptext = "Take profit." + + @staticmethod + def run(cmd, spl, length, authed, msg, agora, revolut, tx): + rtrn = agora.withdraw_funds() + msg(dumps(rtrn))