Add pair_history post endpoint, too

This commit is contained in:
Matthias
2024-04-28 11:44:21 +02:00
parent ccd788e2ce
commit ab10379833
3 changed files with 72 additions and 31 deletions
+6
View File
@@ -496,6 +496,12 @@ class PairCandlesRequest(BaseModel):
columns: Optional[List[str]] = None columns: Optional[List[str]] = None
class PairHistoryRequest(PairCandlesRequest):
timerange: str
strategy: str
freqaimodel: Optional[str] = None
class PairHistory(BaseModel): class PairHistory(BaseModel):
strategy: str strategy: str
pair: str pair: str
+23 -5
View File
@@ -17,11 +17,11 @@ from freqtrade.rpc.api_server.api_schemas import (AvailablePairs, Balances, Blac
ForceEnterResponse, ForceExitPayload, ForceEnterResponse, ForceExitPayload,
FreqAIModelListResponse, Health, Locks, FreqAIModelListResponse, Health, Locks,
LocksPayload, Logs, MixTag, OpenTradeSchema, LocksPayload, Logs, MixTag, OpenTradeSchema,
PairCandlesRequest, PairHistory, PerformanceEntry, PairCandlesRequest, PairHistory,
Ping, PlotConfig, Profit, ResultMsg, ShowConfig, PairHistoryRequest, PerformanceEntry, Ping,
Stats, StatusMsg, StrategyListResponse, PlotConfig, Profit, ResultMsg, ShowConfig, Stats,
StrategyResponse, SysInfo, Version, StatusMsg, StrategyListResponse, StrategyResponse,
WhitelistResponse) SysInfo, Version, WhitelistResponse)
from freqtrade.rpc.api_server.deps import get_config, get_exchange, get_rpc, get_rpc_optional from freqtrade.rpc.api_server.deps import get_config, get_exchange, get_rpc, get_rpc_optional
from freqtrade.rpc.rpc import RPCException from freqtrade.rpc.rpc import RPCException
@@ -321,6 +321,24 @@ def pair_history(pair: str, timeframe: str, timerange: str, strategy: str,
raise HTTPException(status_code=502, detail=str(e)) raise HTTPException(status_code=502, detail=str(e))
@router.post('/pair_history', response_model=PairHistory, tags=['candle data'])
def pair_history_filtered(payload: PairHistoryRequest,
config=Depends(get_config), exchange=Depends(get_exchange)):
# The initial call to this endpoint can be slow, as it may need to initialize
# the exchange class.
config = deepcopy(config)
config.update({
'strategy': payload.strategy,
'timerange': payload.timerange,
'freqaimodel': payload.freqaimodel if payload.freqaimodel else config.get('freqaimodel'),
})
try:
return RPC._rpc_analysed_history_full(
config, payload.pair, payload.timeframe, exchange, payload.columns)
except Exception as e:
raise HTTPException(status_code=502, detail=str(e))
@router.get('/plot_config', response_model=PlotConfig, tags=['candle data']) @router.get('/plot_config', response_model=PlotConfig, tags=['candle data'])
def plot_config(strategy: Optional[str] = None, config=Depends(get_config), def plot_config(strategy: Optional[str] = None, config=Depends(get_config),
rpc: Optional[RPC] = Depends(get_rpc_optional)): rpc: Optional[RPC] = Depends(get_rpc_optional)):
+19 -2
View File
@@ -1654,9 +1654,23 @@ def test_api_pair_history(botclient, tmp_path, mocker):
assert_response(rc, 502) assert_response(rc, 502)
# Working # Working
for call in ('get', 'post'):
if call == 'get':
rc = client_get(client, rc = client_get(client,
f"{BASE_URI}/pair_history?pair=UNITTEST%2FBTC&timeframe={timeframe}" f"{BASE_URI}/pair_history?pair=UNITTEST%2FBTC&timeframe={timeframe}"
f"&timerange=20180111-20180112&strategy={CURRENT_TEST_STRATEGY}") f"&timerange=20180111-20180112&strategy={CURRENT_TEST_STRATEGY}")
else:
rc = client_post(
client,
f"{BASE_URI}/pair_history",
data={
"pair": "UNITTEST/BTC",
"timeframe": timeframe,
"timerange": "20180111-20180112",
"strategy": CURRENT_TEST_STRATEGY,
"columns": ['rsi', 'fastd', 'fastk'],
})
assert_response(rc, 200) assert_response(rc, 200)
result = rc.json() result = rc.json()
assert result['length'] == 289 assert result['length'] == 289
@@ -1665,9 +1679,11 @@ def test_api_pair_history(botclient, tmp_path, mocker):
assert 'data' in result assert 'data' in result
data = result['data'] data = result['data']
assert len(data) == 289 assert len(data) == 289
col_count = 30 if call == 'get' else 18
# analyzed DF has 30 columns # analyzed DF has 30 columns
assert len(result['columns']) == 30 assert len(result['columns']) == col_count
assert len(data[0]) == 30 assert len(result['all_columns']) == 25
assert len(data[0]) == col_count
date_col_idx = [idx for idx, c in enumerate(result['columns']) if c == 'date'][0] date_col_idx = [idx for idx, c in enumerate(result['columns']) if c == 'date'][0]
rsi_col_idx = [idx for idx, c in enumerate(result['columns']) if c == 'rsi'][0] rsi_col_idx = [idx for idx, c in enumerate(result['columns']) if c == 'rsi'][0]
@@ -1681,6 +1697,7 @@ def test_api_pair_history(botclient, tmp_path, mocker):
assert result['data_start_ts'] == 1515628800000 assert result['data_start_ts'] == 1515628800000
assert result['data_stop'] == '2018-01-12 00:00:00+00:00' assert result['data_stop'] == '2018-01-12 00:00:00+00:00'
assert result['data_stop_ts'] == 1515715200000 assert result['data_stop_ts'] == 1515715200000
lfm.reset_mock()
# No data found # No data found
rc = client_get(client, rc = client_get(client,