Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(connectors): accept project 1H/4H periods on Alpaca bars

santhreald4d4e2762b1d
diff --git a/agent/src/trading/connectors/alpaca/sdk.py b/agent/src/trading/connectors/alpaca/sdk.py
index 26c55185e..931cf8d3d 100644
--- a/agent/src/trading/connectors/alpaca/sdk.py
+++ b/agent/src/trading/connectors/alpaca/sdk.py
@@ -244,7 +244,8 @@ def _rest_timeframe(period: str) -> str:
:func:`_timeframe`). Case-sensitive: ``1m`` is one minute, ``1M`` one month."""
return {
"1m": "1Min", "5m": "5Min", "15m": "15Min", "30m": "30Min",
- "1h": "1Hour", "4h": "4Hour", "1w": "1Week", "1M": "1Month",
+ "1h": "1Hour", "1H": "1Hour", "4h": "4Hour", "4H": "4Hour",
+ "1w": "1Week", "1W": "1Week", "1M": "1Month",
}.get(period.strip(), "1Day")
@@ -756,9 +757,9 @@ def _timeframe(period: str, time_frame_cls: Any, unit_cls: Any) -> Any:
minute_amounts = {"1m": 1, "5m": 5, "15m": 15, "30m": 30}
if token in minute_amounts:
return time_frame_cls(minute_amounts[token], unit_cls.Minute)
- if token in ("1h", "4h"):
- return time_frame_cls(1 if token == "1h" else 4, unit_cls.Hour)
- if token == "1w":
+ if token in ("1h", "1H", "4h", "4H"):
+ return time_frame_cls(1 if token in ("1h", "1H") else 4, unit_cls.Hour)
+ if token in ("1w", "1W"):
return time_frame_cls(1, unit_cls.Week)
if token == "1M":
return time_frame_cls(1, unit_cls.Month)
diff --git a/agent/tests/test_alpaca_timeframe_map.py b/agent/tests/test_alpaca_timeframe_map.py
new file mode 100644
index 000000000..bfc25ea75
--- /dev/null
+++ b/agent/tests/test_alpaca_timeframe_map.py
@@ -0,0 +1,17 @@
+"""Tests for Alpaca period → timeframe mapping."""
+
+from __future__ import annotations
+
+from src.trading.connectors.alpaca.sdk import _rest_timeframe
+
+
+def test_project_hour_tokens_map_to_hour_not_day() -> None:
+ assert _rest_timeframe("1H") == "1Hour"
+ assert _rest_timeframe("4H") == "4Hour"
+ assert _rest_timeframe("1h") == "1Hour"
+ assert _rest_timeframe("4h") == "4Hour"
+
+
+def test_minute_month_case_still_distinct() -> None:
+ assert _rest_timeframe("1m") == "1Min"
+ assert _rest_timeframe("1M") == "1Month"