mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 02:12:01 +00:00
Implment weekly/monthly RPC endpoints
This commit is contained in:
parent
e5a88fdeda
commit
f838bc760f
|
@ -151,6 +151,8 @@ python3 scripts/rest_client.py --config rest_config.json <command> [optional par
|
|||
| `performance` | Show performance of each finished trade grouped by pair.
|
||||
| `balance` | Show account balance per currency.
|
||||
| `daily <n>` | Shows profit or loss per day, over the last n days (n defaults to 7).
|
||||
| `weekly <n>` | Shows profit or loss per week, over the last n days (n defaults to 4).
|
||||
| `monthly <n>` | Shows profit or loss per month, over the last n days (n defaults to 3).
|
||||
| `stats` | Display a summary of profit / loss reasons as well as average holding times.
|
||||
| `whitelist` | Show the current whitelist.
|
||||
| `blacklist [pair]` | Show the current blacklist, or adds a pair to the blacklist.
|
||||
|
|
|
@ -157,7 +157,7 @@ class Stats(BaseModel):
|
|||
durations: Dict[str, Optional[float]]
|
||||
|
||||
|
||||
class DailyRecord(BaseModel):
|
||||
class DailyWeeklyMonthlyRecord(BaseModel):
|
||||
date: date
|
||||
abs_profit: float
|
||||
rel_profit: float
|
||||
|
@ -166,8 +166,8 @@ class DailyRecord(BaseModel):
|
|||
trade_count: int
|
||||
|
||||
|
||||
class Daily(BaseModel):
|
||||
data: List[DailyRecord]
|
||||
class DailyWeeklyMonthly(BaseModel):
|
||||
data: List[DailyWeeklyMonthlyRecord]
|
||||
fiat_display_currency: str
|
||||
stake_currency: str
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ from freqtrade.enums import CandleType, TradingMode
|
|||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.rpc import RPC
|
||||
from freqtrade.rpc.api_server.api_schemas import (AvailablePairs, Balances, BlacklistPayload,
|
||||
BlacklistResponse, Count, Daily,
|
||||
BlacklistResponse, Count, DailyWeeklyMonthly,
|
||||
DeleteLockRequest, DeleteTrade,
|
||||
ExchangeListResponse, ForceEnterPayload,
|
||||
ForceEnterResponse, ForceExitPayload,
|
||||
|
@ -51,7 +51,8 @@ logger = logging.getLogger(__name__)
|
|||
# 2.30: new /pairlists endpoint
|
||||
# 2.31: new /backtest/history/ delete endpoint
|
||||
# 2.32: new /backtest/history/ patch endpoint
|
||||
API_VERSION = 2.32
|
||||
# 2.33: Additional weekly/monthly metrics
|
||||
API_VERSION = 2.33
|
||||
|
||||
# Public API, requires no auth.
|
||||
router_public = APIRouter()
|
||||
|
@ -99,12 +100,24 @@ def stats(rpc: RPC = Depends(get_rpc)):
|
|||
return rpc._rpc_stats()
|
||||
|
||||
|
||||
@router.get('/daily', response_model=Daily, tags=['info'])
|
||||
@router.get('/daily', response_model=DailyWeeklyMonthly, tags=['info'])
|
||||
def daily(timescale: int = 7, rpc: RPC = Depends(get_rpc), config=Depends(get_config)):
|
||||
return rpc._rpc_timeunit_profit(timescale, config['stake_currency'],
|
||||
config.get('fiat_display_currency', ''))
|
||||
|
||||
|
||||
@router.get('/weekly', response_model=DailyWeeklyMonthly, tags=['info'])
|
||||
def weekly(timescale: int = 4, rpc: RPC = Depends(get_rpc), config=Depends(get_config)):
|
||||
return rpc._rpc_timeunit_profit(timescale, config['stake_currency'],
|
||||
config.get('fiat_display_currency', 'weeks'))
|
||||
|
||||
|
||||
@router.get('/monthly', response_model=DailyWeeklyMonthly, tags=['info'])
|
||||
def monthly(timescale: int = 3, rpc: RPC = Depends(get_rpc), config=Depends(get_config)):
|
||||
return rpc._rpc_timeunit_profit(timescale, config['stake_currency'],
|
||||
config.get('fiat_display_currency', 'months'))
|
||||
|
||||
|
||||
@router.get('/status', response_model=List[OpenTradeSchema], tags=['info'])
|
||||
def status(rpc: RPC = Depends(get_rpc)):
|
||||
try:
|
||||
|
|
|
@ -134,6 +134,20 @@ class FtRestClient:
|
|||
"""
|
||||
return self._get("daily", params={"timescale": days} if days else None)
|
||||
|
||||
def weekly(self, weeks=None):
|
||||
"""Return the profits for each week, and amount of trades.
|
||||
|
||||
:return: json object
|
||||
"""
|
||||
return self._get("weekly", params={"timescale": weeks} if weeks else None)
|
||||
|
||||
def monthly(self, months=None):
|
||||
"""Return the profits for each month, and amount of trades.
|
||||
|
||||
:return: json object
|
||||
"""
|
||||
return self._get("monthly", params={"timescale": months} if months else None)
|
||||
|
||||
def edge(self):
|
||||
"""Return information about edge.
|
||||
|
||||
|
|
|
@ -617,6 +617,42 @@ def test_api_daily(botclient, mocker, ticker, fee, markets):
|
|||
assert rc.json()['data'][0]['date'] == str(datetime.now(timezone.utc).date())
|
||||
|
||||
|
||||
def test_api_weekly(botclient, mocker, ticker, fee, markets):
|
||||
ftbot, client = botclient
|
||||
patch_get_signal(ftbot)
|
||||
mocker.patch.multiple(
|
||||
EXMS,
|
||||
get_balances=MagicMock(return_value=ticker),
|
||||
fetch_ticker=ticker,
|
||||
get_fee=fee,
|
||||
markets=PropertyMock(return_value=markets)
|
||||
)
|
||||
rc = client_get(client, f"{BASE_URI}/weekly")
|
||||
assert_response(rc)
|
||||
assert len(rc.json()['data']) == 4
|
||||
assert rc.json()['stake_currency'] == 'BTC'
|
||||
assert rc.json()['fiat_display_currency'] == 'USD'
|
||||
assert rc.json()['data'][0]['date'] == str(datetime.now(timezone.utc).date())
|
||||
|
||||
|
||||
def test_api_monthly(botclient, mocker, ticker, fee, markets):
|
||||
ftbot, client = botclient
|
||||
patch_get_signal(ftbot)
|
||||
mocker.patch.multiple(
|
||||
EXMS,
|
||||
get_balances=MagicMock(return_value=ticker),
|
||||
fetch_ticker=ticker,
|
||||
get_fee=fee,
|
||||
markets=PropertyMock(return_value=markets)
|
||||
)
|
||||
rc = client_get(client, f"{BASE_URI}/monthly")
|
||||
assert_response(rc)
|
||||
assert len(rc.json()['data']) == 3
|
||||
assert rc.json()['stake_currency'] == 'BTC'
|
||||
assert rc.json()['fiat_display_currency'] == 'USD'
|
||||
assert rc.json()['data'][0]['date'] == str(datetime.now(timezone.utc).date())
|
||||
|
||||
|
||||
@pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_api_trades(botclient, mocker, fee, markets, is_short):
|
||||
ftbot, client = botclient
|
||||
|
|
Loading…
Reference in New Issue
Block a user