fix(backtest): handle Databento errors gracefully during page load
- Set default dates to 2024-07-01 to 2024-12-31 (valid for XNAS.BASIC) - Catch all exceptions during entry spot derivation, not just ValueError - Don't auto-run backtest on page load - let user configure first - Use recent GLD price (~30) as fallback
This commit is contained in:
@@ -254,24 +254,25 @@ def _render_backtests_page(workspace_id: str | None = None) -> None:
|
|||||||
default_data_source = "databento"
|
default_data_source = "databento"
|
||||||
default_dataset = "XNAS.BASIC"
|
default_dataset = "XNAS.BASIC"
|
||||||
default_schema = "ohlcv-1d"
|
default_schema = "ohlcv-1d"
|
||||||
default_start_date = DEFAULT_BACKTEST_START
|
# Use a start date that's valid for the default dataset (XNAS.BASIC starts 2024-07-01)
|
||||||
default_end_date = DEFAULT_BACKTEST_END
|
default_start_date = date(2024, 7, 1).isoformat()
|
||||||
|
default_end_date = date(2024, 12, 31).isoformat()
|
||||||
default_symbol = "GLD"
|
default_symbol = "GLD"
|
||||||
default_start_price = 0.0
|
default_start_price = 0.0
|
||||||
|
|
||||||
# Derive entry spot from default date range
|
# Derive entry spot from default date range
|
||||||
# Fall back to a reasonable default if fixture source doesn't support the date range
|
# Fall back to a reasonable default if data source doesn't support the date range
|
||||||
try:
|
try:
|
||||||
default_entry_spot = service.derive_entry_spot(
|
default_entry_spot = service.derive_entry_spot(
|
||||||
"GLD",
|
"GLD",
|
||||||
date.fromisoformat(DEFAULT_BACKTEST_START),
|
date.fromisoformat(default_start_date),
|
||||||
date.fromisoformat(DEFAULT_BACKTEST_END),
|
date.fromisoformat(default_end_date),
|
||||||
data_source="databento", # Use databento for default dates
|
data_source="databento",
|
||||||
)
|
)
|
||||||
except ValueError:
|
except Exception:
|
||||||
# Fixture source may not support the default date range
|
# Data source may not support the default date range or API error
|
||||||
# Fall back to a reasonable GLD price
|
# Fall back to a reasonable GLD price (recent ~$230/oz)
|
||||||
default_entry_spot = 185.0
|
default_entry_spot = 230.0
|
||||||
default_units = (
|
default_units = (
|
||||||
asset_quantity_from_workspace_config(config, entry_spot=default_entry_spot, symbol="GLD")
|
asset_quantity_from_workspace_config(config, entry_spot=default_entry_spot, symbol="GLD")
|
||||||
if config is not None and default_entry_spot > 0
|
if config is not None and default_entry_spot > 0
|
||||||
@@ -937,4 +938,4 @@ def _render_backtests_page(workspace_id: str | None = None) -> None:
|
|||||||
|
|
||||||
# Initial render
|
# Initial render
|
||||||
render_seeded_summary(entry_spot=float(default_start_price) if default_start_price > 0 else None)
|
render_seeded_summary(entry_spot=float(default_start_price) if default_start_price > 0 else None)
|
||||||
run_backtest()
|
# Don't auto-run backtest on page load - let user configure and click Run
|
||||||
|
|||||||
Reference in New Issue
Block a user