From b88f49b6ae1e3a7463ea4f6623c7fa1ebfc61c38 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 15 Feb 2022 23:20:42 +0000 Subject: [PATCH] Add commands to check only profit --- handler/commands.py | 20 ++++++++++++++++++++ handler/transactions.py | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/handler/commands.py b/handler/commands.py index bd852f1..c9ac313 100644 --- a/handler/commands.py +++ b/handler/commands.py @@ -465,3 +465,23 @@ class IRCCommands(object): def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify): total = tx.get_total_with_trades() msg(f"${total}") + + class profit(object): + name = "profit" + authed = True + helptext = "Get total profit." + + @staticmethod + def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify): + total = tx.get_profit() + msg(f"Profit: {total}USD") + + class tprofit(object): + name = "tprofit" + authed = True + helptext = "Get total profit with open trades." + + @staticmethod + def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify): + total = tx.get_profit(True) + msg(f"Profit: {total}USD") diff --git a/handler/transactions.py b/handler/transactions.py index 74e4354..5e3698c 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -485,6 +485,23 @@ class Transactions(object): return remaining + # TODO: move to money + def get_profit(self, trades=False): + """ + Check how much total profit we have made. + :return: profit in USD + :rtype: float + """ + total_usd = self.get_total_usd() + if not total_usd: + return False + if trades: + trades_usd = self.get_open_trades_usd() + total_usd += trades_usd + + profit = total_usd - float(settings.Money.BaseUSD) + return profit + def get_open_trades_usd(self): """ Get total value of open trades in USD.