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.
|
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:
|
if include_ts:
|
||||||
df.loc[:, "__date_ts"] = df.loc[:, "date"].astype(np.int64) // 1000 // 1000
|
df.loc[:, "__date_ts"] = df.loc[:, "date"].astype(np.int64) // 1000 // 1000
|
||||||
return df
|
return df
|
||||||
|
|||||||
@@ -350,10 +350,17 @@ def api_update_backtest_history_entry(
|
|||||||
)
|
)
|
||||||
def api_get_backtest_market_change(file: str, config=Depends(get_config)):
|
def api_get_backtest_market_change(file: str, config=Depends(get_config)):
|
||||||
bt_results_base: Path = config["user_data_dir"] / "backtest_results"
|
bt_results_base: Path = config["user_data_dir"] / "backtest_results"
|
||||||
file_abs = (bt_results_base / f"{file}_market_change").with_suffix(".feather")
|
for fn in (
|
||||||
# Ensure file is in backtest_results directory
|
Path(file).with_suffix(".zip"),
|
||||||
if not is_file_in_dir(file_abs, bt_results_base):
|
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.")
|
raise HTTPException(status_code=404, detail="File not found.")
|
||||||
|
|
||||||
df = get_backtest_market_change(file_abs)
|
df = get_backtest_market_change(file_abs)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user