Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(cli): print every historical bar the limit requested

Rudy Celekli67dfa00b7089
diff --git a/agent/cli/_legacy.py b/agent/cli/_legacy.py
index a7978dc59..956414d6b 100644
--- a/agent/cli/_legacy.py
+++ b/agent/cli/_legacy.py
@@ -5251,7 +5251,10 @@ def cmd_connector_history(
console.print(f"[red]{rich_escape(str(result.get('error')))}[/red]")
return EXIT_RUN_FAILED
rows = result.get("bars", [])
- if not rows:
+ # The table used to keep only the last 20 bars, so --limit 40 still
+ # printed 20. Honor the same limit that was sent to the connector.
+ shown = rows[-limit:] if isinstance(limit, int) and limit >= 1 else []
+ if not shown:
console.print("[dim]No historical bars returned.[/dim]")
return EXIT_SUCCESS
table = Table(title=f"History {result.get('symbol', symbol)} · {result.get('profile_id')}", box=box.SIMPLE_HEAVY)
@@ -5261,7 +5264,7 @@ def cmd_connector_history(
table.add_column("Low", justify="right")
table.add_column("Close", justify="right")
table.add_column("Volume", justify="right")
- for row in rows[-20:]:
+ for row in shown:
table.add_row(
str(row.get("date") or ""),
str(row.get("open") or ""),
diff --git a/agent/tests/test_connector_history_display.py b/agent/tests/test_connector_history_display.py
new file mode 100644
index 000000000..0a13d411b
--- /dev/null
+++ b/agent/tests/test_connector_history_display.py
@@ -0,0 +1,49 @@
+"""Connector history should print the bars the user asked for."""
+
+from __future__ import annotations
+
+from io import StringIO
+
+from rich.console import Console
+
+import cli._legacy as legacy
+
+
+def _bars(n: int) -> list[dict[str, object]]:
+ return [
+ {"date": f"2026-01-{i:02d}", "open": i, "high": i, "low": i, "close": i, "volume": i}
+ for i in range(1, n + 1)
+ ]
+
+
+def _run(monkeypatch, rows: list[dict[str, object]], limit: int) -> str:
+ monkeypatch.setattr(
+ "src.trading.service.get_history",
+ lambda *args, **kwargs: {
+ "status": "ok",
+ "symbol": "AAPL",
+ "profile_id": "paper",
+ "bars": rows,
+ },
+ )
+ buf = StringIO()
+ monkeypatch.setattr(
+ legacy,
+ "console",
+ Console(file=buf, force_terminal=False, width=200, no_color=True),
+ )
+ assert legacy.cmd_connector_history("AAPL", limit=limit) == 0
+ return buf.getvalue()
+
+
+def test_history_prints_every_bar_inside_the_requested_limit(monkeypatch) -> None:
+ text = _run(monkeypatch, _bars(40), 40)
+ assert "2026-01-01" in text
+ assert "2026-01-40" in text
+
+
+def test_history_does_not_print_bars_outside_the_limit(monkeypatch) -> None:
+ text = _run(monkeypatch, _bars(40), 5)
+ assert "2026-01-36" in text
+ assert "2026-01-40" in text
+ assert "2026-01-01" not in text