feat: add historic_balance api endpoint
This commit is contained in:
@@ -31,6 +31,7 @@ from freqtrade.rpc.api_server.api_schemas import (
|
|||||||
ResultMsg,
|
ResultMsg,
|
||||||
Stats,
|
Stats,
|
||||||
StatusMsg,
|
StatusMsg,
|
||||||
|
WalletsSummary,
|
||||||
WhitelistResponse,
|
WhitelistResponse,
|
||||||
)
|
)
|
||||||
from freqtrade.rpc.api_server.deps import get_config, get_rpc
|
from freqtrade.rpc.api_server.deps import get_config, get_rpc
|
||||||
@@ -104,6 +105,21 @@ def stats(rpc: RPC = Depends(get_rpc)):
|
|||||||
return rpc._rpc_stats()
|
return rpc._rpc_stats()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get(
|
||||||
|
"/historic_balance",
|
||||||
|
response_model=WalletsSummary,
|
||||||
|
tags=["info"],
|
||||||
|
)
|
||||||
|
def api_get_backtest_wallet(rpc: RPC = Depends(get_rpc)):
|
||||||
|
results = rpc._rpc_get_historic_balance()
|
||||||
|
|
||||||
|
return {
|
||||||
|
"columns": results.columns.tolist(),
|
||||||
|
"data": results.values.tolist(),
|
||||||
|
"length": len(results),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/daily", response_model=DailyWeeklyMonthly, tags=["Trading-info"])
|
@router.get("/daily", response_model=DailyWeeklyMonthly, tags=["Trading-info"])
|
||||||
def daily(
|
def daily(
|
||||||
timescale: int = Query(7, ge=1, description="Number of days to fetch data for"),
|
timescale: int = Query(7, ge=1, description="Number of days to fetch data for"),
|
||||||
|
|||||||
+14
-1
@@ -12,7 +12,7 @@ import psutil
|
|||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from dateutil.tz import tzlocal
|
from dateutil.tz import tzlocal
|
||||||
from numpy import inf, int64, isnan, mean, nan
|
from numpy import inf, int64, isnan, mean, nan
|
||||||
from pandas import DataFrame, NaT
|
from pandas import DataFrame, NaT, read_sql
|
||||||
from sqlalchemy import func, select
|
from sqlalchemy import func, select
|
||||||
|
|
||||||
from freqtrade import __version__
|
from freqtrade import __version__
|
||||||
@@ -785,6 +785,19 @@ class RPC:
|
|||||||
"bot_start_date": format_date(bot_start),
|
"bot_start_date": format_date(bot_start),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _rpc_get_historic_balance(self) -> DataFrame:
|
||||||
|
"""
|
||||||
|
Returns the historic balance of the bot
|
||||||
|
:return: DataFrame with the balance history
|
||||||
|
"""
|
||||||
|
results = read_sql("wallet_balance", con=Trade.session.bind, parse_dates=["timestamp"])
|
||||||
|
results.loc[:, "total"] = results["price"] * results["balance"]
|
||||||
|
results = results.rename({"timestamp": "date"}, axis=1)
|
||||||
|
results.loc[:, "__date_ts"] = results.loc[:, "date"].astype("int64") // 1000 // 1000
|
||||||
|
|
||||||
|
results = results.groupby(["date", "__date_ts"]).agg({"total": "sum"}).reset_index()
|
||||||
|
return results
|
||||||
|
|
||||||
def __balance_get_est_stake(
|
def __balance_get_est_stake(
|
||||||
self, coin: str, stake_currency: str, amount: float, balance: Wallet
|
self, coin: str, stake_currency: str, amount: float, balance: Wallet
|
||||||
) -> tuple[float, float]:
|
) -> tuple[float, float]:
|
||||||
|
|||||||
Reference in New Issue
Block a user