refactor: pair_history should only be available in webserver mode
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
import logging
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
|
||||||
|
from freqtrade.rpc.api_server.api_schemas import PairHistory, PairHistoryRequest
|
||||||
|
from freqtrade.rpc.api_server.deps import get_config, get_exchange
|
||||||
|
from freqtrade.rpc.rpc import RPC
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/pair_history", response_model=PairHistory, tags=["candle data"])
|
||||||
|
def pair_history(
|
||||||
|
pair: str,
|
||||||
|
timeframe: str,
|
||||||
|
timerange: str,
|
||||||
|
strategy: str,
|
||||||
|
freqaimodel: str | None = None,
|
||||||
|
config=Depends(get_config),
|
||||||
|
exchange=Depends(get_exchange),
|
||||||
|
):
|
||||||
|
# The initial call to this endpoint can be slow, as it may need to initialize
|
||||||
|
# the exchange class.
|
||||||
|
config = deepcopy(config)
|
||||||
|
config.update(
|
||||||
|
{
|
||||||
|
"timeframe": timeframe,
|
||||||
|
"strategy": strategy,
|
||||||
|
"timerange": timerange,
|
||||||
|
"freqaimodel": freqaimodel if freqaimodel else config.get("freqaimodel"),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
return RPC._rpc_analysed_history_full(config, pair, timeframe, exchange, None)
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=502, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/pair_history", response_model=PairHistory, tags=["candle data"])
|
||||||
|
def pair_history_filtered(
|
||||||
|
payload: PairHistoryRequest, config=Depends(get_config), exchange=Depends(get_exchange)
|
||||||
|
):
|
||||||
|
# The initial call to this endpoint can be slow, as it may need to initialize
|
||||||
|
# the exchange class.
|
||||||
|
config = deepcopy(config)
|
||||||
|
config.update(
|
||||||
|
{
|
||||||
|
"timeframe": payload.timeframe,
|
||||||
|
"strategy": payload.strategy,
|
||||||
|
"timerange": payload.timerange,
|
||||||
|
"freqaimodel": (
|
||||||
|
payload.freqaimodel if payload.freqaimodel else config.get("freqaimodel")
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
return RPC._rpc_analysed_history_full(
|
||||||
|
config, payload.pair, payload.timeframe, exchange, payload.columns
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=502, detail=str(e))
|
||||||
@@ -34,7 +34,6 @@ from freqtrade.rpc.api_server.api_schemas import (
|
|||||||
OpenTradeSchema,
|
OpenTradeSchema,
|
||||||
PairCandlesRequest,
|
PairCandlesRequest,
|
||||||
PairHistory,
|
PairHistory,
|
||||||
PairHistoryRequest,
|
|
||||||
PerformanceEntry,
|
PerformanceEntry,
|
||||||
Ping,
|
Ping,
|
||||||
PlotConfig,
|
PlotConfig,
|
||||||
@@ -49,7 +48,7 @@ from freqtrade.rpc.api_server.api_schemas import (
|
|||||||
Version,
|
Version,
|
||||||
WhitelistResponse,
|
WhitelistResponse,
|
||||||
)
|
)
|
||||||
from freqtrade.rpc.api_server.deps import get_config, get_exchange, get_rpc, get_rpc_optional
|
from freqtrade.rpc.api_server.deps import get_config, get_rpc, get_rpc_optional
|
||||||
from freqtrade.rpc.rpc import RPCException
|
from freqtrade.rpc.rpc import RPCException
|
||||||
|
|
||||||
|
|
||||||
@@ -342,58 +341,6 @@ def pair_candles_filtered(payload: PairCandlesRequest, rpc: RPC = Depends(get_rp
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/pair_history", response_model=PairHistory, tags=["candle data"])
|
|
||||||
def pair_history(
|
|
||||||
pair: str,
|
|
||||||
timeframe: str,
|
|
||||||
timerange: str,
|
|
||||||
strategy: str,
|
|
||||||
freqaimodel: str | None = None,
|
|
||||||
config=Depends(get_config),
|
|
||||||
exchange=Depends(get_exchange),
|
|
||||||
):
|
|
||||||
# The initial call to this endpoint can be slow, as it may need to initialize
|
|
||||||
# the exchange class.
|
|
||||||
config = deepcopy(config)
|
|
||||||
config.update(
|
|
||||||
{
|
|
||||||
"timeframe": timeframe,
|
|
||||||
"strategy": strategy,
|
|
||||||
"timerange": timerange,
|
|
||||||
"freqaimodel": freqaimodel if freqaimodel else config.get("freqaimodel"),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
return RPC._rpc_analysed_history_full(config, pair, timeframe, exchange, None)
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(status_code=502, detail=str(e))
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/pair_history", response_model=PairHistory, tags=["candle data"])
|
|
||||||
def pair_history_filtered(
|
|
||||||
payload: PairHistoryRequest, config=Depends(get_config), exchange=Depends(get_exchange)
|
|
||||||
):
|
|
||||||
# The initial call to this endpoint can be slow, as it may need to initialize
|
|
||||||
# the exchange class.
|
|
||||||
config = deepcopy(config)
|
|
||||||
config.update(
|
|
||||||
{
|
|
||||||
"timeframe": payload.timeframe,
|
|
||||||
"strategy": payload.strategy,
|
|
||||||
"timerange": payload.timerange,
|
|
||||||
"freqaimodel": (
|
|
||||||
payload.freqaimodel if payload.freqaimodel else config.get("freqaimodel")
|
|
||||||
),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
return RPC._rpc_analysed_history_full(
|
|
||||||
config, payload.pair, payload.timeframe, exchange, payload.columns
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(status_code=502, detail=str(e))
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/plot_config", response_model=PlotConfig, tags=["candle data"])
|
@router.get("/plot_config", response_model=PlotConfig, tags=["candle data"])
|
||||||
def plot_config(
|
def plot_config(
|
||||||
strategy: str | None = None,
|
strategy: str | None = None,
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ class ApiServer(RPCHandler):
|
|||||||
from freqtrade.rpc.api_server.api_background_tasks import router as api_bg_tasks
|
from freqtrade.rpc.api_server.api_background_tasks import router as api_bg_tasks
|
||||||
from freqtrade.rpc.api_server.api_backtest import router as api_backtest
|
from freqtrade.rpc.api_server.api_backtest import router as api_backtest
|
||||||
from freqtrade.rpc.api_server.api_download_data import router as api_download_data
|
from freqtrade.rpc.api_server.api_download_data import router as api_download_data
|
||||||
|
from freqtrade.rpc.api_server.api_pair_history import router as api_pair_history
|
||||||
from freqtrade.rpc.api_server.api_pairlists import router as api_pairlists
|
from freqtrade.rpc.api_server.api_pairlists import router as api_pairlists
|
||||||
from freqtrade.rpc.api_server.api_v1 import router as api_v1
|
from freqtrade.rpc.api_server.api_v1 import router as api_v1
|
||||||
from freqtrade.rpc.api_server.api_v1 import router_public as api_v1_public
|
from freqtrade.rpc.api_server.api_v1 import router_public as api_v1_public
|
||||||
@@ -145,6 +146,11 @@ class ApiServer(RPCHandler):
|
|||||||
prefix="/api/v1",
|
prefix="/api/v1",
|
||||||
dependencies=[Depends(http_basic_or_jwt_token), Depends(is_webserver_mode)],
|
dependencies=[Depends(http_basic_or_jwt_token), Depends(is_webserver_mode)],
|
||||||
)
|
)
|
||||||
|
app.include_router(
|
||||||
|
api_pair_history,
|
||||||
|
prefix="/api/v1",
|
||||||
|
dependencies=[Depends(http_basic_or_jwt_token), Depends(is_webserver_mode)],
|
||||||
|
)
|
||||||
app.include_router(
|
app.include_router(
|
||||||
api_pairlists,
|
api_pairlists,
|
||||||
prefix="/api/v1",
|
prefix="/api/v1",
|
||||||
|
|||||||
@@ -1914,6 +1914,15 @@ def test_api_pair_history(botclient, tmp_path, mocker):
|
|||||||
|
|
||||||
timeframe = "5m"
|
timeframe = "5m"
|
||||||
lfm = mocker.patch("freqtrade.strategy.interface.IStrategy.load_freqAI_model")
|
lfm = mocker.patch("freqtrade.strategy.interface.IStrategy.load_freqAI_model")
|
||||||
|
# Wrong mode
|
||||||
|
rc = client_get(
|
||||||
|
client,
|
||||||
|
f"{BASE_URI}/pair_history?timeframe={timeframe}"
|
||||||
|
f"&timerange=20180111-20180112&strategy={CURRENT_TEST_STRATEGY}",
|
||||||
|
)
|
||||||
|
assert_response(rc, 503)
|
||||||
|
_ftbot.config["runmode"] = RunMode.WEBSERVER
|
||||||
|
|
||||||
# No pair
|
# No pair
|
||||||
rc = client_get(
|
rc = client_get(
|
||||||
client,
|
client,
|
||||||
|
|||||||
Reference in New Issue
Block a user