From 75999112799f7f479191e94d75b89f6c1f376827 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 24 Feb 2022 22:26:16 +0000 Subject: [PATCH] Fix how min and max are used in transactions --- handler/transactions.py | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/handler/transactions.py b/handler/transactions.py index 1ab50b6..451bdce 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -72,6 +72,8 @@ class Transactions(object): event = data["event"] ts = data["timestamp"] + if "data" not in data: + return inside = data["data"] txid = inside["id"] @@ -152,10 +154,8 @@ class Transactions(object): "description": description, "valid": 0, # All checks passed and we can release escrow? } - self.log.info("Transaction processed: {formatted}", formatted=dumps(to_store, indent=2)) self.irc.sendmsg(f"AUTO Incoming transaction: {amount}{currency} ({reference}) - {state} - {description}") - # Partial reference implementation # Account for silly people not removing the default string # Split the reference into parts @@ -230,14 +230,14 @@ class Transactions(object): if looked_up_without_reference: return # If the amount does not match exactly, get the min and max values for our given acceptable margins for trades - min_amount, max_amount = self.money.get_acceptable_margins(currency, amount) + min_amount, max_amount = self.money.get_acceptable_margins(currency, stored_trade["amount"]) self.log.info( "Amount does not match exactly, trying with margins: min: {min_amount} / max: {max_amount}", min_amount=min_amount, max_amount=max_amount, ) self.irc.sendmsg(f"Amount does not match exactly, trying with margins: min: {min_amount} / max: {max_amount}") - if not min_amount < stored_trade["amount"] < max_amount: + if not min_amount < amount < max_amount: self.log.info( "Amount mismatch - not in margins: {amount} (min: {min_amount} / max: {max_amount}", amount=stored_trade["amount"], @@ -562,33 +562,6 @@ class Transactions(object): self.write_to_es("get_remaining", cast_es) 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) - if trades: - cast_es = { - "profit_trades_usd": profit, - } - else: - cast_es = { - "profit_usd": profit, - } - - self.write_to_es("get_profit", cast_es) - return profit - def get_open_trades_usd(self): """ Get total value of open trades in USD.