Add /pairlists endpoint to api

This commit is contained in:
Matthias 2023-04-19 18:35:52 +02:00
parent f1e03a6873
commit 2df80fc49a
3 changed files with 40 additions and 6 deletions

View File

@ -389,6 +389,10 @@ class StrategyListResponse(BaseModel):
strategies: List[str]
class PairListResponse(BaseModel):
pairlists: List[Dict[str, Any]]
class FreqAIModelListResponse(BaseModel):
freqaimodels: List[str]

View File

@ -15,11 +15,11 @@ from freqtrade.rpc.api_server.api_schemas import (AvailablePairs, Balances, Blac
DeleteLockRequest, DeleteTrade, ForceEnterPayload,
ForceEnterResponse, ForceExitPayload,
FreqAIModelListResponse, Health, Locks, Logs,
OpenTradeSchema, PairHistory, PerformanceEntry,
Ping, PlotConfig, Profit, ResultMsg, ShowConfig,
Stats, StatusMsg, StrategyListResponse,
StrategyResponse, SysInfo, Version,
WhitelistResponse)
OpenTradeSchema, PairHistory, PairListResponse,
PerformanceEntry, Ping, PlotConfig, Profit,
ResultMsg, ShowConfig, Stats, StatusMsg,
StrategyListResponse, StrategyResponse, SysInfo,
Version, WhitelistResponse)
from freqtrade.rpc.api_server.deps import get_config, get_exchange, get_rpc, get_rpc_optional
from freqtrade.rpc.rpc import RPCException
@ -43,7 +43,8 @@ logger = logging.getLogger(__name__)
# 2.23: Allow plot config request in webserver mode
# 2.24: Add cancel_open_order endpoint
# 2.25: Add several profit values to /status endpoint
API_VERSION = 2.25
# 2.26: new /pairlists endpoint
API_VERSION = 2.26
# Public API, requires no auth.
router_public = APIRouter()
@ -300,6 +301,19 @@ def get_strategy(strategy: str, config=Depends(get_config)):
}
@router.get('/pairlists', response_model=PairListResponse)
def list_pairlists(config=Depends(get_config)):
from freqtrade.resolvers import PairListResolver
pairlists = PairListResolver.search_all_objects(
config, False)
pairlists = sorted(pairlists, key=lambda x: x['name'])
return {'pairlists': [{
"name": x['name'],
} for x in pairlists
]}
@router.get('/freqaimodels', response_model=FreqAIModelListResponse, tags=['freqai'])
def list_freqaimodels(config=Depends(get_config)):
from freqtrade.resolvers.freqaimodel_resolver import FreqaiModelResolver

View File

@ -1580,6 +1580,22 @@ def test_api_freqaimodels(botclient, tmpdir, mocker):
]}
def test_api_pairlists(botclient, tmpdir, mocker):
ftbot, client = botclient
ftbot.config['user_data_dir'] = Path(tmpdir)
rc = client_get(client, f"{BASE_URI}/pairlists")
assert_response(rc)
response = rc.json()
assert isinstance(response['pairlists'], list)
assert len(response['pairlists']) > 0
assert len([r for r in response['pairlists'] if r['name'] == 'AgeFilter']) == 1
assert len([r for r in response['pairlists'] if r['name'] == 'VolumePairList']) == 1
assert len([r for r in response['pairlists'] if r['name'] == 'StaticPairList']) == 1
def test_list_available_pairs(botclient):
ftbot, client = botclient