test: add test for /markets endpoint

This commit is contained in:
Matthias
2025-02-02 14:33:13 +01:00
parent ecf013dd18
commit 0181e00c19
2 changed files with 54 additions and 2 deletions

View File

@@ -7,7 +7,7 @@ from fastapi.exceptions import HTTPException
from freqtrade import __version__
from freqtrade.data.history import get_datahandler
from freqtrade.enums import CandleType, State, TradingMode
from freqtrade.enums import CandleType, RunMode, State, TradingMode
from freqtrade.exceptions import OperationalException
from freqtrade.rpc import RPC
from freqtrade.rpc.api_server.api_pairlists import handleExchangePayload
@@ -483,7 +483,7 @@ def markets(
config=Depends(get_config),
rpc: RPC | None = Depends(get_rpc_optional),
):
if not rpc:
if not rpc or config["runmode"] == RunMode.WEBSERVER:
# webserver mode
config_loc = deepcopy(config)
handleExchangePayload(query, config_loc)

View File

@@ -3009,3 +3009,55 @@ def test_api_download_data(botclient, mocker, tmp_path):
assert response["job_category"] == "download_data"
assert response["status"] == "failed"
assert response["error"] == "Download error"
def test_api_markets_live(botclient):
ftbot, client = botclient
rc = client_get(client, f"{BASE_URI}/markets")
assert_response(rc, 200)
response = rc.json()
assert "markets" in response
assert len(response["markets"]) >= 0
assert response["markets"]["XRP/USDT"] == {
"base": "XRP",
"quote": "USDT",
"symbol": "XRP/USDT",
"spot": True,
"swap": False,
}
assert "BTC/USDT" in response["markets"]
assert "XRP/BTC" in response["markets"]
rc = client_get(
client,
f"{BASE_URI}/markets?base=XRP",
)
assert_response(rc, 200)
response = rc.json()
assert "XRP/USDT" in response["markets"]
assert "XRP/BTC" in response["markets"]
assert "BTC/USDT" not in response["markets"]
def test_api_markets_webserver(botclient):
# Ensure webserver exchanges are reset
ApiBG.exchanges = {}
ftbot, client = botclient
# Test in webserver mode
ftbot.config["runmode"] = RunMode.WEBSERVER
rc = client_get(client, f"{BASE_URI}/markets?exchange=binance")
assert_response(rc, 200)
response = rc.json()
assert "markets" in response
assert len(response["markets"]) >= 0
assert response["exchange_id"] == "binance"
rc = client_get(client, f"{BASE_URI}/markets?exchange=hyperliquid")
assert_response(rc, 200)
assert "hyperliquid_spot" in ApiBG.exchanges
assert "binance_spot" in ApiBG.exchanges