Update telegram notifications to properly detect shorts

This commit is contained in:
Matthias 2022-03-04 19:42:29 +01:00
parent 9576fab621
commit 8943d42509
4 changed files with 9 additions and 7 deletions

View File

@ -197,7 +197,7 @@ class Order(_DECL_BASE):
self.order_filled_date = datetime.now(timezone.utc)
self.order_update_date = datetime.now(timezone.utc)
def to_json(self) -> Dict[str, Any]:
def to_json(self, entry_side: str) -> Dict[str, Any]:
return {
'pair': self.ft_pair,
'order_id': self.order_id,
@ -219,6 +219,7 @@ class Order(_DECL_BASE):
tzinfo=timezone.utc).timestamp() * 1000) if self.order_filled_date else None,
'order_type': self.order_type,
'price': self.price,
'ft_is_entry': self.ft_order_side == entry_side,
'remaining': self.remaining,
}
@ -458,7 +459,7 @@ class LocalTrade():
def to_json(self) -> Dict[str, Any]:
filled_orders = self.select_filled_orders()
orders = [order.to_json() for order in filled_orders]
orders = [order.to_json(self.enter_side) for order in filled_orders]
return {
'trade_id': self.id,

View File

@ -171,7 +171,7 @@ class RPC:
# calculate profit and send message to user
if trade.is_open:
try:
closing_side = "buy" if trade.is_short else "sell"
closing_side = trade.exit_side
current_rate = self._freqtrade.exchange.get_rate(
trade.pair, refresh=False, side=closing_side)
except (ExchangeError, PricingError):

View File

@ -398,7 +398,7 @@ class Telegram(RPCHandler):
first_avg = filled_orders[0]["safe_price"]
for x, order in enumerate(filled_orders):
if order['ft_order_side'] != 'buy':
if not order['ft_is_entry']:
continue
cur_entry_datetime = arrow.get(order["order_filled_date"])
cur_entry_amount = order["amount"]
@ -465,7 +465,7 @@ class Telegram(RPCHandler):
messages = []
for r in results:
r['open_date_hum'] = arrow.get(r['open_date']).humanize()
r['num_entries'] = len([o for o in r['orders'] if o['ft_order_side'] == 'buy'])
r['num_entries'] = len([o for o in r['orders'] if o['ft_is_entry']])
r['sell_reason'] = r.get('sell_reason', "")
lines = [
"*Trade ID:* `{trade_id}`" +

View File

@ -122,7 +122,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'order_date': ANY, 'order_timestamp': ANY, 'order_filled_date': ANY,
'order_filled_timestamp': ANY, 'order_type': 'limit', 'price': 1.098e-05,
'is_open': False, 'pair': 'ETH/BTC', 'order_id': ANY,
'remaining': ANY, 'status': ANY
'remaining': ANY, 'status': ANY, 'ft_is_entry': True,
}],
}
@ -204,7 +204,8 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'order_date': ANY, 'order_timestamp': ANY, 'order_filled_date': ANY,
'order_filled_timestamp': ANY, 'order_type': 'limit', 'price': 1.098e-05,
'is_open': False, 'pair': 'ETH/BTC', 'order_id': ANY,
'remaining': ANY, 'status': ANY}],
'remaining': ANY, 'status': ANY, 'ft_is_entry': True,
}],
}