Add more user feedback on rejected and dropped trades
This commit is contained in:
parent
a96c99b9e4
commit
b7c46ba1d3
|
@ -459,17 +459,20 @@ def execute_strategy(callback, strategy, func):
|
||||||
# Don't be silly
|
# Don't be silly
|
||||||
if callback.exchange != account.exchange:
|
if callback.exchange != account.exchange:
|
||||||
log.error("Market exchange differs from account exchange.")
|
log.error("Market exchange differs from account exchange.")
|
||||||
|
sendmsg(user, "Market exchange differs from account exchange.", title="Error")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get the pair we are trading
|
# Get the pair we are trading
|
||||||
symbol = get_pair(account, base, quote)
|
symbol = get_pair(account, base, quote)
|
||||||
if not symbol:
|
if not symbol:
|
||||||
|
sendmsg(user, f"Symbol not supported by account: {symbol}", title="Error")
|
||||||
log.error(f"Symbol not supported by account: {symbol}")
|
log.error(f"Symbol not supported by account: {symbol}")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Extract the information for the symbol
|
# Extract the information for the symbol
|
||||||
instrument = strategy.account.client.extract_instrument(instruments, symbol)
|
instrument = strategy.account.client.extract_instrument(instruments, symbol)
|
||||||
if not instrument:
|
if not instrument:
|
||||||
|
sendmsg(user, f"Symbol not found: {symbol}", title="Error")
|
||||||
log.error(f"Symbol not found: {symbol}")
|
log.error(f"Symbol not found: {symbol}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -478,6 +481,7 @@ def execute_strategy(callback, strategy, func):
|
||||||
trade_precision = instrument["tradeUnitsPrecision"]
|
trade_precision = instrument["tradeUnitsPrecision"]
|
||||||
display_precision = instrument["displayPrecision"]
|
display_precision = instrument["displayPrecision"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
sendmsg(user, f"Precision not found for {symbol}", title="Error")
|
||||||
log.error(f"Precision not found for {symbol}")
|
log.error(f"Precision not found for {symbol}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -508,6 +512,11 @@ def execute_strategy(callback, strategy, func):
|
||||||
side = check_exit["side"]
|
side = check_exit["side"]
|
||||||
response = account.client.close_position(side, symbol)
|
response = account.client.close_position(side, symbol)
|
||||||
log.debug(f"Close position response: {response}")
|
log.debug(f"Close position response: {response}")
|
||||||
|
sendmsg(
|
||||||
|
user,
|
||||||
|
f"Closing {side} position on exit signal: {symbol}",
|
||||||
|
title="Exit signal",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Set the trend
|
# Set the trend
|
||||||
|
@ -523,13 +532,28 @@ def execute_strategy(callback, strategy, func):
|
||||||
if strategy.trend_signals.exists():
|
if strategy.trend_signals.exists():
|
||||||
if strategy.trends is None:
|
if strategy.trends is None:
|
||||||
log.debug("Refusing to trade with no trend signals received")
|
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
|
return
|
||||||
if symbol not in strategy.trends:
|
if symbol not in strategy.trends:
|
||||||
log.debug("Refusing to trade asset without established trend")
|
log.debug("Refusing to trade asset without established trend")
|
||||||
|
sendmsg(
|
||||||
|
user,
|
||||||
|
f"Refusing to trade {symbol} without established trend",
|
||||||
|
title="Trend not ready",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if strategy.trends[symbol] != direction:
|
if strategy.trends[symbol] != direction:
|
||||||
log.debug("Refusing to trade against the trend")
|
log.debug("Refusing to trade against the trend")
|
||||||
|
sendmsg(
|
||||||
|
user,
|
||||||
|
f"Refusing to trade {symbol} against the trend",
|
||||||
|
title="Trend rejection",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
log.debug(f"Trend check passed for {symbol} - {direction}")
|
log.debug(f"Trend check passed for {symbol} - {direction}")
|
||||||
|
@ -590,6 +614,14 @@ def execute_strategy(callback, strategy, func):
|
||||||
if filtered["action"] == "rejected":
|
if filtered["action"] == "rejected":
|
||||||
new_trade.status = "rejected"
|
new_trade.status = "rejected"
|
||||||
new_trade.save()
|
new_trade.save()
|
||||||
|
sendmsg(
|
||||||
|
user,
|
||||||
|
(
|
||||||
|
f"{direction} on {symbol} rejected due to conflicting position: "
|
||||||
|
f"{filtered['positions']}"
|
||||||
|
),
|
||||||
|
title="Trade rejected",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
info = new_trade.post()
|
info = new_trade.post()
|
||||||
log.debug(f"Posted trade: {info}")
|
log.debug(f"Posted trade: {info}")
|
||||||
|
|
Loading…
Reference in New Issue