From b7c46ba1d3d99fabe280f10b42604f50c2188ebb Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 20 Dec 2022 07:20:26 +0000 Subject: [PATCH] Add more user feedback on rejected and dropped trades --- core/lib/market.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/lib/market.py b/core/lib/market.py index 198ffd2..aba0147 100644 --- a/core/lib/market.py +++ b/core/lib/market.py @@ -459,17 +459,20 @@ def execute_strategy(callback, strategy, func): # Don't be silly if callback.exchange != account.exchange: log.error("Market exchange differs from account exchange.") + sendmsg(user, "Market exchange differs from account exchange.", title="Error") return # Get the pair we are trading symbol = get_pair(account, base, quote) if not symbol: + sendmsg(user, f"Symbol not supported by account: {symbol}", title="Error") log.error(f"Symbol not supported by account: {symbol}") return # Extract the information for the symbol instrument = strategy.account.client.extract_instrument(instruments, symbol) if not instrument: + sendmsg(user, f"Symbol not found: {symbol}", title="Error") log.error(f"Symbol not found: {symbol}") return @@ -478,6 +481,7 @@ def execute_strategy(callback, strategy, func): trade_precision = instrument["tradeUnitsPrecision"] display_precision = instrument["displayPrecision"] except KeyError: + sendmsg(user, f"Precision not found for {symbol}", title="Error") log.error(f"Precision not found for {symbol}") return @@ -508,6 +512,11 @@ def execute_strategy(callback, strategy, func): side = check_exit["side"] response = account.client.close_position(side, symbol) log.debug(f"Close position response: {response}") + sendmsg( + user, + f"Closing {side} position on exit signal: {symbol}", + title="Exit signal", + ) return # Set the trend @@ -523,13 +532,28 @@ def execute_strategy(callback, strategy, func): if strategy.trend_signals.exists(): if strategy.trends is None: log.debug("Refusing to trade with no trend signals received") + sendmsg( + user, + f"Refusing to trade {symbol} with no trend signals received", + title="Trend not ready", + ) return if symbol not in strategy.trends: log.debug("Refusing to trade asset without established trend") + sendmsg( + user, + f"Refusing to trade {symbol} without established trend", + title="Trend not ready", + ) return else: if strategy.trends[symbol] != direction: log.debug("Refusing to trade against the trend") + sendmsg( + user, + f"Refusing to trade {symbol} against the trend", + title="Trend rejection", + ) return else: log.debug(f"Trend check passed for {symbol} - {direction}") @@ -590,6 +614,14 @@ def execute_strategy(callback, strategy, func): if filtered["action"] == "rejected": new_trade.status = "rejected" new_trade.save() + sendmsg( + user, + ( + f"{direction} on {symbol} rejected due to conflicting position: " + f"{filtered['positions']}" + ), + title="Trade rejected", + ) else: info = new_trade.post() log.debug(f"Posted trade: {info}")