Merge pull request #6964 from freqtrade/rpc_rel_daily

Telegram / api daily relative profit
This commit is contained in:
Matthias
2022-06-11 19:31:32 +02:00
committed by GitHub
7 changed files with 54 additions and 40 deletions

View File

@@ -120,6 +120,8 @@ class Stats(BaseModel):
class DailyRecord(BaseModel):
date: date
abs_profit: float
rel_profit: float
starting_balance: float
fiat_value: float
trade_count: int

View File

@@ -36,7 +36,8 @@ logger = logging.getLogger(__name__)
# versions 2.xx -> futures/short branch
# 2.14: Add entry/exit orders to trade response
# 2.15: Add backtest history endpoints
API_VERSION = 2.15
# 2.16: Additional daily metrics
API_VERSION = 2.16
# Public API, requires no auth.
router_public = APIRouter()

View File

@@ -302,11 +302,12 @@ class RPC:
return relativedelta(months=step)
return timedelta(**{timeunit: step})
profit_units: Dict[date, Dict] = {}
if not (isinstance(timescale, int) and timescale > 0):
raise RPCException('timescale must be an integer greater than 0')
profit_units: Dict[date, Dict] = {}
daily_stake = self._freqtrade.wallets.get_total_stake_amount()
for day in range(0, timescale):
profitday = start_date - time_offset(day)
# Only query for necessary columns for performance reasons.
@@ -318,8 +319,12 @@ class RPC:
curdayprofit = sum(
trade.close_profit_abs for trade in trades if trade.close_profit_abs is not None)
# Calculate this periods starting balance
daily_stake = daily_stake - curdayprofit
profit_units[profitday] = {
'amount': curdayprofit,
'daily_stake': daily_stake,
'rel_profit': round(curdayprofit / daily_stake, 8) if daily_stake > 0 else 0,
'trades': len(trades),
}
@@ -327,6 +332,8 @@ class RPC:
{
'date': f"{key.year}-{key.month:02d}" if timeunit == 'months' else key,
'abs_profit': value["amount"],
'starting_balance': value["daily_stake"],
'rel_profit': value["rel_profit"],
'fiat_value': self._fiat_converter.convert_amount(
value['amount'],
stake_currency,

View File

@@ -605,14 +605,16 @@ class Telegram(RPCHandler):
unit
)
stats_tab = tabulate(
[[period['date'],
[[f"{period['date']} ({period['trade_count']})",
f"{round_coin_value(period['abs_profit'], stats['stake_currency'])}",
f"{period['fiat_value']:.2f} {stats['fiat_display_currency']}",
f"{period['trade_count']} trades"] for period in stats['data']],
f"{period['rel_profit']:.2%}",
] for period in stats['data']],
headers=[
val.header,
f'Profit {stake_cur}',
f'Profit {fiat_disp_cur}',
f"{val.header} (count)",
f'{stake_cur}',
f'{fiat_disp_cur}',
'Profit %',
'Trades',
],
tablefmt='simple')