Make /stats working
This commit is contained in:
parent
8f61b68b2a
commit
c556d1b37e
@ -275,6 +275,10 @@ class RPC:
|
|||||||
"trades_count": len(output)
|
"trades_count": len(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _rpc_stats(self):
|
||||||
|
trades = trades = Trade.get_trades([Trade.is_open.is_(False)])
|
||||||
|
return trades
|
||||||
|
|
||||||
def _rpc_trade_statistics(
|
def _rpc_trade_statistics(
|
||||||
self, stake_currency: str, fiat_display_currency: str) -> Dict[str, Any]:
|
self, stake_currency: str, fiat_display_currency: str) -> Dict[str, Any]:
|
||||||
""" Returns cumulative profit statistics """
|
""" Returns cumulative profit statistics """
|
||||||
|
@ -782,22 +782,22 @@ class Telegram(RPC):
|
|||||||
"""
|
"""
|
||||||
# TODO: self._send_msg(...)
|
# TODO: self._send_msg(...)
|
||||||
def trade_win_loss(trade):
|
def trade_win_loss(trade):
|
||||||
if trade['profit_abs'] > 0:
|
if trade.close_profit_abs > 0:
|
||||||
return 'Wins'
|
return 'Wins'
|
||||||
elif trade['profit_abs'] < 0:
|
elif trade.close_profit_abs < 0:
|
||||||
return 'Losses'
|
return 'Losses'
|
||||||
else:
|
else:
|
||||||
return 'Draws'
|
return 'Draws'
|
||||||
|
|
||||||
trades = self._rpc_trade_history(-1)
|
trades = self._rpc_stats()
|
||||||
trades_closed = [trade for trade in trades if not trade['is_open']]
|
trades_closed = [trade for trade in trades if not trade.is_open]
|
||||||
|
|
||||||
# Sell reason
|
# Sell reason
|
||||||
sell_reasons = {}
|
sell_reasons = {}
|
||||||
for trade in trades_closed:
|
for trade in trades_closed:
|
||||||
if trade['sell_reason'] not in sell_reasons:
|
if trade.sell_reason not in sell_reasons:
|
||||||
sell_reasons[trade['sell_reason']] = {'Wins': 0, 'Losses': 0, 'Draws': 0}
|
sell_reasons[trade.sell_reason] = {'Wins': 0, 'Losses': 0, 'Draws': 0}
|
||||||
sell_reasons[trade['sell_reason']][trade_win_loss(trade)] += 1
|
sell_reasons[trade.sell_reason][trade_win_loss(trade)] += 1
|
||||||
sell_reasons_tabulate = []
|
sell_reasons_tabulate = []
|
||||||
for reason, count in sell_reasons.items():
|
for reason, count in sell_reasons.items():
|
||||||
sell_reasons_tabulate.append([
|
sell_reasons_tabulate.append([
|
||||||
@ -814,8 +814,8 @@ class Telegram(RPC):
|
|||||||
# Duration
|
# Duration
|
||||||
dur: Dict[str, List[int]] = {'Wins': [], 'Draws': [], 'Losses': []}
|
dur: Dict[str, List[int]] = {'Wins': [], 'Draws': [], 'Losses': []}
|
||||||
for trade in trades_closed:
|
for trade in trades_closed:
|
||||||
if trade['close_date'] is not None and trade['open_date'] is not None:
|
if trade.close_date is not None and trade.open_date is not None:
|
||||||
trade_dur = arrow.get(trade['close_date']) - arrow.get(trade['open_date'])
|
trade_dur = (trade.close_date - trade.open_date).total_seconds()
|
||||||
dur[trade_win_loss(trade)].append(trade_dur)
|
dur[trade_win_loss(trade)].append(trade_dur)
|
||||||
wins_dur = sum(dur['Wins']) / len(dur['Wins']) if len(dur['Wins']) > 0 else 'N/A'
|
wins_dur = sum(dur['Wins']) / len(dur['Wins']) if len(dur['Wins']) > 0 else 'N/A'
|
||||||
draws_dur = sum(dur['Draws']) / len(dur['Draws']) if len(dur['Draws']) > 0 else 'N/A'
|
draws_dur = sum(dur['Draws']) / len(dur['Draws']) if len(dur['Draws']) > 0 else 'N/A'
|
||||||
@ -824,8 +824,9 @@ class Telegram(RPC):
|
|||||||
[['Wins', str(wins_dur)], ['Draws', str(draws_dur)], ['Losses', str(losses_dur)]],
|
[['Wins', str(wins_dur)], ['Draws', str(draws_dur)], ['Losses', str(losses_dur)]],
|
||||||
headers=['', 'Duration']
|
headers=['', 'Duration']
|
||||||
)
|
)
|
||||||
|
msg = (f"""```{sell_reasons_msg}```\n```{duration_msg}```""")
|
||||||
|
|
||||||
self._send_msg('\n'.join([sell_reasons_msg, duration_msg]))
|
self._send_msg(msg, ParseMode.MARKDOWN)
|
||||||
|
|
||||||
@authorized_only
|
@authorized_only
|
||||||
def _show_config(self, update: Update, context: CallbackContext) -> None:
|
def _show_config(self, update: Update, context: CallbackContext) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user