mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Improve responses for evaluate get endpoints
This commit is contained in:
parent
4c52109fa3
commit
9e75c768c0
|
@ -376,6 +376,12 @@ class WhitelistResponse(BaseModel):
|
|||
method: List[str]
|
||||
|
||||
|
||||
class WhitelistEvaluateResponse(BaseModel):
|
||||
result: Optional[WhitelistResponse]
|
||||
error: Optional[str]
|
||||
status: str
|
||||
|
||||
|
||||
class DeleteTrade(BaseModel):
|
||||
cancel_order_count: int
|
||||
result: str
|
||||
|
|
|
@ -21,7 +21,8 @@ from freqtrade.rpc.api_server.api_schemas import (AvailablePairs, Balances, Blac
|
|||
PairListsResponse, PerformanceEntry, Ping,
|
||||
PlotConfig, Profit, ResultMsg, ShowConfig, Stats,
|
||||
StatusMsg, StrategyListResponse, StrategyResponse,
|
||||
SysInfo, Version, WhitelistResponse)
|
||||
SysInfo, Version, WhitelistEvaluateResponse,
|
||||
WhitelistResponse)
|
||||
from freqtrade.rpc.api_server.deps import get_config, get_exchange, get_rpc, get_rpc_optional
|
||||
from freqtrade.rpc.api_server.webserver_bgwork import ApiBG
|
||||
from freqtrade.rpc.rpc import RPCException
|
||||
|
@ -372,19 +373,24 @@ def pairlists_evaluate(payload: PairListsPayload, background_tasks: BackgroundTa
|
|||
}
|
||||
|
||||
|
||||
@router.get('/pairlists/evaluate', response_model=WhitelistResponse, tags=['pairlists'])
|
||||
@router.get('/pairlists/evaluate', response_model=WhitelistEvaluateResponse, tags=['pairlists'])
|
||||
def pairlists_evaluate_get():
|
||||
if ApiBG.pairlist_error:
|
||||
raise HTTPException(status_code=500,
|
||||
detail='Pairlist evaluation failed: ' + ApiBG.pairlist_error)
|
||||
|
||||
if ApiBG.pairlist_running:
|
||||
raise HTTPException(status_code=202, detail='Pairlist evaluation is currently running.')
|
||||
return {'status': 'running'}
|
||||
if ApiBG.pairlist_error:
|
||||
return {
|
||||
'status': 'failed',
|
||||
'error': ApiBG.pairlist_error
|
||||
}
|
||||
|
||||
if not ApiBG.pairlist_result:
|
||||
raise HTTPException(status_code=400, detail='Pairlist evaluation not started yet.')
|
||||
return {'status': 'pending'}
|
||||
|
||||
return ApiBG.pairlist_result
|
||||
return {
|
||||
'status': 'success',
|
||||
'result': ApiBG.pairlist_result
|
||||
}
|
||||
|
||||
|
||||
@router.get('/freqaimodels', response_model=FreqAIModelListResponse, tags=['freqai'])
|
||||
|
|
|
@ -1645,13 +1645,13 @@ def test_api_pairlists_evaluate(botclient, tmpdir):
|
|||
|
||||
rc = client_get(client, f"{BASE_URI}/pairlists/evaluate")
|
||||
|
||||
assert_response(rc, 400)
|
||||
assert rc.json()['detail'] == 'Pairlist evaluation not started yet.'
|
||||
assert_response(rc)
|
||||
assert rc.json()['status'] == 'pending'
|
||||
|
||||
ApiBG.pairlist_running = True
|
||||
rc = client_get(client, f"{BASE_URI}/pairlists/evaluate")
|
||||
assert_response(rc, 202)
|
||||
assert rc.json()['detail'] == 'Pairlist evaluation is currently running.'
|
||||
assert_response(rc)
|
||||
assert rc.json()['status'] == 'running'
|
||||
|
||||
body = {
|
||||
"pairlists": [
|
||||
|
@ -1675,8 +1675,8 @@ def test_api_pairlists_evaluate(botclient, tmpdir):
|
|||
rc = client_get(client, f"{BASE_URI}/pairlists/evaluate")
|
||||
assert_response(rc)
|
||||
response = rc.json()
|
||||
assert response['whitelist'] == ['ETH/BTC', 'LTC/BTC', 'XRP/BTC', 'NEO/BTC',]
|
||||
assert response['length'] == 4
|
||||
assert response['result']['whitelist'] == ['ETH/BTC', 'LTC/BTC', 'XRP/BTC', 'NEO/BTC',]
|
||||
assert response['result']['length'] == 4
|
||||
|
||||
# Restart with additional filter, reducing the list to 2
|
||||
body['pairlists'].append({"method": "OffsetFilter", "number_assets": 2})
|
||||
|
@ -1687,8 +1687,8 @@ def test_api_pairlists_evaluate(botclient, tmpdir):
|
|||
rc = client_get(client, f"{BASE_URI}/pairlists/evaluate")
|
||||
assert_response(rc)
|
||||
response = rc.json()
|
||||
assert response['whitelist'] == ['ETH/BTC', 'LTC/BTC', ]
|
||||
assert response['length'] == 2
|
||||
assert response['result']['whitelist'] == ['ETH/BTC', 'LTC/BTC', ]
|
||||
assert response['result']['length'] == 2
|
||||
|
||||
|
||||
def test_list_available_pairs(botclient):
|
||||
|
|
Loading…
Reference in New Issue
Block a user