mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-13 03:33:55 +00:00
Handle pairlist evaluation errors gracefully
This commit is contained in:
parent
c2010d160f
commit
4c52109fa3
|
@ -4,6 +4,7 @@ from typing import List, Optional
|
||||||
|
|
||||||
from fastapi import APIRouter, BackgroundTasks, Depends, Query
|
from fastapi import APIRouter, BackgroundTasks, Depends, Query
|
||||||
from fastapi.exceptions import HTTPException
|
from fastapi.exceptions import HTTPException
|
||||||
|
from sympy import O
|
||||||
|
|
||||||
from freqtrade import __version__
|
from freqtrade import __version__
|
||||||
from freqtrade.constants import Config
|
from freqtrade.constants import Config
|
||||||
|
@ -343,7 +344,9 @@ def __run_pairlist(config_loc: Config):
|
||||||
'length': len(pairlists.whitelist),
|
'length': len(pairlists.whitelist),
|
||||||
'whitelist': pairlists.whitelist
|
'whitelist': pairlists.whitelist
|
||||||
}
|
}
|
||||||
|
except (OperationalException, Exception) as e:
|
||||||
|
logger.exception(e)
|
||||||
|
ApiBG.pairlist_error = str(e)
|
||||||
finally:
|
finally:
|
||||||
ApiBG.pairlist_running = False
|
ApiBG.pairlist_running = False
|
||||||
|
|
||||||
|
@ -360,7 +363,8 @@ def pairlists_evaluate(payload: PairListsPayload, background_tasks: BackgroundTa
|
||||||
# TODO: overwrite blacklist? make it optional and fall back to the one in config?
|
# TODO: overwrite blacklist? make it optional and fall back to the one in config?
|
||||||
# Outcome depends on the UI approach.
|
# Outcome depends on the UI approach.
|
||||||
config_loc['exchange']['pair_blacklist'] = payload.blacklist
|
config_loc['exchange']['pair_blacklist'] = payload.blacklist
|
||||||
|
ApiBG.pairlist_error = None
|
||||||
|
ApiBG.pairlist_result = {}
|
||||||
background_tasks.add_task(__run_pairlist, config_loc)
|
background_tasks.add_task(__run_pairlist, config_loc)
|
||||||
ApiBG.pairlist_running = True
|
ApiBG.pairlist_running = True
|
||||||
return {
|
return {
|
||||||
|
@ -370,6 +374,10 @@ def pairlists_evaluate(payload: PairListsPayload, background_tasks: BackgroundTa
|
||||||
|
|
||||||
@router.get('/pairlists/evaluate', response_model=WhitelistResponse, tags=['pairlists'])
|
@router.get('/pairlists/evaluate', response_model=WhitelistResponse, tags=['pairlists'])
|
||||||
def pairlists_evaluate_get():
|
def pairlists_evaluate_get():
|
||||||
|
if ApiBG.pairlist_error:
|
||||||
|
raise HTTPException(status_code=500,
|
||||||
|
detail='Pairlist evaluation failed: ' + ApiBG.pairlist_error)
|
||||||
|
|
||||||
if ApiBG.pairlist_running:
|
if ApiBG.pairlist_running:
|
||||||
raise HTTPException(status_code=202, detail='Pairlist evaluation is currently running.')
|
raise HTTPException(status_code=202, detail='Pairlist evaluation is currently running.')
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
|
|
||||||
class ApiBG():
|
class ApiBG():
|
||||||
|
@ -15,5 +15,6 @@ class ApiBG():
|
||||||
# Exchange - only available in webserver mode.
|
# Exchange - only available in webserver mode.
|
||||||
exchange = None
|
exchange = None
|
||||||
# Pairlist evaluate things
|
# Pairlist evaluate things
|
||||||
|
pairlist_error: Optional[str] = None
|
||||||
pairlist_running: bool = False
|
pairlist_running: bool = False
|
||||||
pairlist_result: Dict[str, Any] = {}
|
pairlist_result: Dict[str, Any] = {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user