Add trade duration by win/loss.

This commit is contained in:
Xu Wang 2020-09-28 20:30:20 +01:00
parent 627e221b65
commit 7bce2cd29d

View File

@ -763,16 +763,10 @@ class Telegram(RPC):
# Sell reason # Sell reason
sell_reasons = {} sell_reasons = {}
for trade in trades_closed: for trade in trades_closed:
if trade['sell_reason'] 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']][trade_win_loss(trade)] += 1 sell_reasons[trade['sell_reason']][trade_win_loss(trade)] += 1
else:
win_loss_count = {'Wins': 0, 'Losses': 0, 'Draws': 0}
win_loss_count[trade_win_loss(trade)] += 1
sell_reasons[trade['sell_reason']] = win_loss_count
sell_reasons_tabulate = [] sell_reasons_tabulate = []
# | Sell Reason | Sells | Wins | Draws | Losses |
# |-------------|------:|-----:|------:|-------:|
# | test | 1 | 2 | 3 | 4 |
for reason, count in sell_reasons.items(): for reason, count in sell_reasons.items():
sell_reasons_tabulate.append([ sell_reasons_tabulate.append([
reason, sum(count.values()), reason, sum(count.values()),
@ -785,8 +779,21 @@ class Telegram(RPC):
headers=['Sell Reason', 'Sells', 'Wins', 'Draws', 'Losses'] headers=['Sell Reason', 'Sells', 'Wins', 'Draws', 'Losses']
) )
# TODO: Duration # Duration
dur = {'Wins': [], 'Draws': [], 'Losses': []}
for trade in trades_closed:
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'])
dur[trade_win_loss(trade)].append(trade_dur)
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'
losses_dur = sum(dur['Losses']) / len(dur['Losses']) if len(dur['Losses']) > 0 else 'N/A'
duration_msg = tabulate(
[['Wins', str(wins_dur)], ['Draws', str(draws_dur)], ['Losses', str(losses_dur)]],
headers=['', 'Duration']
)
self._send_msg('\n'.join([sell_reasons_msg, duration_msg]))
@authorized_only @authorized_only
def _show_config(self, update: Update, context: CallbackContext) -> None: def _show_config(self, update: Update, context: CallbackContext) -> None: