From c17e311f7ebf5dae6eb0a271124d55b65c7030f4 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 24 Feb 2022 22:28:00 +0000 Subject: [PATCH] Move get_profit to money --- handler/money.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/handler/money.py b/handler/money.py index 5727a66..ce14ed1 100644 --- a/handler/money.py +++ b/handler/money.py @@ -78,3 +78,30 @@ class Money(object): else: rates = self.get_rates_all() return float(amount) / rates[currency] + + # 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.tx.get_total_usd() + if not total_usd: + return False + if trades: + trades_usd = self.tx.get_open_trades_usd() + total_usd += trades_usd + + profit = total_usd - float(settings.Money.BaseUSD) + if trades: + cast_es = { + "profit_trades_usd": profit, + } + else: + cast_es = { + "profit_usd": profit, + } + + self.tx.write_to_es("get_profit", cast_es) + return profit