Avoid mixed types in the api for /stats
This commit is contained in:
parent
af984bdc0d
commit
be84a028c1
@ -109,7 +109,7 @@ class SellReason(BaseModel):
|
|||||||
|
|
||||||
class Stats(BaseModel):
|
class Stats(BaseModel):
|
||||||
sell_reasons: Dict[str, SellReason]
|
sell_reasons: Dict[str, SellReason]
|
||||||
durations: Dict[str, Union[str, float]]
|
durations: Dict[str, Optional[float]]
|
||||||
|
|
||||||
|
|
||||||
class DailyRecord(BaseModel):
|
class DailyRecord(BaseModel):
|
||||||
|
@ -440,9 +440,9 @@ class RPC:
|
|||||||
trade_dur = (trade.close_date - trade.open_date).total_seconds()
|
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 None
|
||||||
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 None
|
||||||
losses_dur = sum(dur['losses']) / len(dur['losses']) if len(dur['losses']) > 0 else 'N/A'
|
losses_dur = sum(dur['losses']) / len(dur['losses']) if len(dur['losses']) > 0 else None
|
||||||
|
|
||||||
durations = {'wins': wins_dur, 'draws': draws_dur, 'losses': losses_dur}
|
durations = {'wins': wins_dur, 'draws': draws_dur, 'losses': losses_dur}
|
||||||
return {'sell_reasons': sell_reasons, 'durations': durations}
|
return {'sell_reasons': sell_reasons, 'durations': durations}
|
||||||
|
@ -766,9 +766,9 @@ class Telegram(RPCHandler):
|
|||||||
duration_msg = tabulate(
|
duration_msg = tabulate(
|
||||||
[
|
[
|
||||||
['Wins', str(timedelta(seconds=durations['wins']))
|
['Wins', str(timedelta(seconds=durations['wins']))
|
||||||
if durations['wins'] != 'N/A' else 'N/A'],
|
if durations['wins'] is not None else 'N/A'],
|
||||||
['Losses', str(timedelta(seconds=durations['losses']))
|
['Losses', str(timedelta(seconds=durations['losses']))
|
||||||
if durations['losses'] != 'N/A' else 'N/A']
|
if durations['losses'] is not None else 'N/A']
|
||||||
],
|
],
|
||||||
headers=['', 'Avg. Duration']
|
headers=['', 'Avg. Duration']
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user