Skip to content

Commit ca35907

Browse files
author
Stefan Jansen
committed
fix: reject SDK-expanded symbols before targeted Databento requests
Databento normalizes whitespace and comma-separated strings, including strings inside a symbol list. Reject disguised ALL_SYMBOLS and comma expansion before acquisition so one missing-series report cannot trigger a universe or multi-instrument download. Three public workflow regressions fail before the guard and preserve the literal-universe control.
1 parent 830b451 commit ca35907

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

‎src/ml4t/data/providers/databento.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def fetch_ohlcv_range(
357357
selected_stype = self.stype_in if stype_in is None else stype_in
358358
if selected_stype not in {"raw_symbol", "continuous", "instrument_id"}:
359359
raise ValueError("stype_in must select a single series, not a parent or universe")
360-
if not isinstance(symbol, str) or symbol.upper() == "ALL_SYMBOLS":
360+
if not isinstance(symbol, str) or symbol.strip().upper() == "ALL_SYMBOLS" or "," in symbol:
361361
raise ValueError("symbol must identify a single instrument, not a universe")
362362
self._validate_inputs(symbol, start.date().isoformat(), end.date().isoformat(), frequency)
363363
self._acquire_rate_limit()

‎tests/test_targeted_databento_acquisition.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,11 @@ def test_generic_backfill_cannot_put_another_instrument_in_a_missing_bar(source,
290290
assert storage.get_metadata("BTC.c.0") == original
291291

292292

293-
def test_targeted_single_series_cannot_expand_to_all_vendor_instruments(source):
293+
@pytest.mark.parametrize("symbol", ["ALL_SYMBOLS", " ALL_SYMBOLS ", "ALL_SYMBOLS,", "BTCU6,MBTU6"])
294+
def test_targeted_single_series_cannot_expand_to_all_vendor_instruments(source, symbol):
294295
provider, _, calls = source
295296
with pytest.raises(ValueError, match="single|universe|instrument"):
296-
provider.fetch_ohlcv_range("ALL_SYMBOLS", instant("12:01"), instant("12:02"), "minute")
297+
provider.fetch_ohlcv_range(symbol, instant("12:01"), instant("12:02"), "minute")
297298
assert calls == []
298299

299300

0 commit comments

Comments
 (0)