mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
Add /exchanges endpoint to list available exchanges
This commit is contained in:
@@ -5,6 +5,7 @@ from pydantic import BaseModel
|
|||||||
|
|
||||||
from freqtrade.constants import DATETIME_PRINT_FORMAT, IntOrInf
|
from freqtrade.constants import DATETIME_PRINT_FORMAT, IntOrInf
|
||||||
from freqtrade.enums import OrderTypeValues, SignalDirection, TradingMode
|
from freqtrade.enums import OrderTypeValues, SignalDirection, TradingMode
|
||||||
|
from freqtrade.types import ValidExchangesType
|
||||||
|
|
||||||
|
|
||||||
class Ping(BaseModel):
|
class Ping(BaseModel):
|
||||||
@@ -396,6 +397,10 @@ class StrategyListResponse(BaseModel):
|
|||||||
strategies: List[str]
|
strategies: List[str]
|
||||||
|
|
||||||
|
|
||||||
|
class ExchangeListResponse(BaseModel):
|
||||||
|
exchanges: List[ValidExchangesType]
|
||||||
|
|
||||||
|
|
||||||
class FreqAIModelListResponse(BaseModel):
|
class FreqAIModelListResponse(BaseModel):
|
||||||
freqaimodels: List[str]
|
freqaimodels: List[str]
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ from freqtrade.exceptions import OperationalException
|
|||||||
from freqtrade.rpc import RPC
|
from freqtrade.rpc import RPC
|
||||||
from freqtrade.rpc.api_server.api_schemas import (AvailablePairs, Balances, BlacklistPayload,
|
from freqtrade.rpc.api_server.api_schemas import (AvailablePairs, Balances, BlacklistPayload,
|
||||||
BlacklistResponse, Count, Daily,
|
BlacklistResponse, Count, Daily,
|
||||||
DeleteLockRequest, DeleteTrade, ForceEnterPayload,
|
DeleteLockRequest, DeleteTrade,
|
||||||
|
ExchangeListResponse, ForceEnterPayload,
|
||||||
ForceEnterResponse, ForceExitPayload,
|
ForceEnterResponse, ForceExitPayload,
|
||||||
FreqAIModelListResponse, Health, Locks, Logs,
|
FreqAIModelListResponse, Health, Locks, Logs,
|
||||||
OpenTradeSchema, PairHistory, PerformanceEntry,
|
OpenTradeSchema, PairHistory, PerformanceEntry,
|
||||||
@@ -312,6 +313,15 @@ def get_strategy(strategy: str, config=Depends(get_config)):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get('/exchanges', response_model=ExchangeListResponse, tags=[])
|
||||||
|
def list_exchanges(config=Depends(get_config)):
|
||||||
|
from freqtrade.exchange import list_available_exchanges
|
||||||
|
exchanges = list_available_exchanges(config)
|
||||||
|
return {
|
||||||
|
'exchanges': exchanges,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get('/freqaimodels', response_model=FreqAIModelListResponse, tags=['freqai'])
|
@router.get('/freqaimodels', response_model=FreqAIModelListResponse, tags=['freqai'])
|
||||||
def list_freqaimodels(config=Depends(get_config)):
|
def list_freqaimodels(config=Depends(get_config)):
|
||||||
from freqtrade.resolvers.freqaimodel_resolver import FreqaiModelResolver
|
from freqtrade.resolvers.freqaimodel_resolver import FreqaiModelResolver
|
||||||
|
|||||||
@@ -1578,6 +1578,38 @@ def test_api_strategy(botclient):
|
|||||||
assert_response(rc, 500)
|
assert_response(rc, 500)
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_exchanges(botclient):
|
||||||
|
ftbot, client = botclient
|
||||||
|
|
||||||
|
rc = client_get(client, f"{BASE_URI}/exchanges")
|
||||||
|
assert_response(rc)
|
||||||
|
response = rc.json()
|
||||||
|
assert isinstance(response['exchanges'], list)
|
||||||
|
assert len(response['exchanges']) > 20
|
||||||
|
okx = [x for x in response['exchanges'] if x['name'] == 'okx'][0]
|
||||||
|
assert okx == {
|
||||||
|
"name": "okx",
|
||||||
|
"valid": True,
|
||||||
|
"supported": True,
|
||||||
|
"comment": "",
|
||||||
|
"trade_modes": [
|
||||||
|
"spot",
|
||||||
|
"isolated futures",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
mexc = [x for x in response['exchanges'] if x['name'] == 'mexc'][0]
|
||||||
|
assert mexc == {
|
||||||
|
"name": "mexc",
|
||||||
|
"valid": True,
|
||||||
|
"supported": False,
|
||||||
|
"comment": "",
|
||||||
|
"trade_modes": [
|
||||||
|
"spot",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_api_freqaimodels(botclient, tmpdir, mocker):
|
def test_api_freqaimodels(botclient, tmpdir, mocker):
|
||||||
ftbot, client = botclient
|
ftbot, client = botclient
|
||||||
ftbot.config['user_data_dir'] = Path(tmpdir)
|
ftbot.config['user_data_dir'] = Path(tmpdir)
|
||||||
@@ -1933,3 +1965,4 @@ def test_api_ws_send_msg(default_conf, mocker, caplog):
|
|||||||
|
|
||||||
finally:
|
finally:
|
||||||
ApiServer.shutdown()
|
ApiServer.shutdown()
|
||||||
|
ApiServer.shutdown()
|
||||||
|
|||||||
Reference in New Issue
Block a user