mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-02 18:13:04 +00:00
feat: get_backtest_market_change should support zip files
This commit is contained in:
@@ -279,7 +279,11 @@ def get_backtest_market_change(filename: Path, include_ts: bool = True) -> pd.Da
|
||||
"""
|
||||
Read backtest market change file.
|
||||
"""
|
||||
df = pd.read_feather(filename)
|
||||
if filename.suffix == ".zip":
|
||||
data = load_file_from_zip(filename, f"{filename.stem}_market_change.feather")
|
||||
df = pd.read_feather(BytesIO(data))
|
||||
else:
|
||||
df = pd.read_feather(filename)
|
||||
if include_ts:
|
||||
df.loc[:, "__date_ts"] = df.loc[:, "date"].astype(np.int64) // 1000 // 1000
|
||||
return df
|
||||
|
||||
@@ -350,10 +350,17 @@ def api_update_backtest_history_entry(
|
||||
)
|
||||
def api_get_backtest_market_change(file: str, config=Depends(get_config)):
|
||||
bt_results_base: Path = config["user_data_dir"] / "backtest_results"
|
||||
file_abs = (bt_results_base / f"{file}_market_change").with_suffix(".feather")
|
||||
# Ensure file is in backtest_results directory
|
||||
if not is_file_in_dir(file_abs, bt_results_base):
|
||||
for fn in (
|
||||
Path(file).with_suffix(".zip"),
|
||||
Path(f"{file}_market_change").with_suffix(".feather"),
|
||||
):
|
||||
file_abs = bt_results_base / fn
|
||||
# Ensure file is in backtest_results directory
|
||||
if is_file_in_dir(file_abs, bt_results_base):
|
||||
break
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="File not found.")
|
||||
|
||||
df = get_backtest_market_change(file_abs)
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user