"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(toss): a hasNext page without a cursor is an error, not the last page
Haozhe Wub5ff36ba013a
diff --git a/agent/src/trading/connectors/toss/sdk.py b/agent/src/trading/connectors/toss/sdk.pyindex 9e793ffcc..be07163b2 100644--- a/agent/src/trading/connectors/toss/sdk.py+++ b/agent/src/trading/connectors/toss/sdk.py@@ -273,7 +273,13 @@ def _fetch_closed_orders(cfg: TossConfig) -> list[Any]:return rowscursor = page.get("nextCursor")if not cursor:- return rows # hasNext claimed true with nothing to continue from+ # The spec makes both fields required: hasNext=true with no cursor+ # is a broken page, and returning what we have would be the same+ # silently truncated history the cap above refuses.+ raise TossAPIError(+ "Toss reported hasNext=true without a nextCursor; refusing to "+ "return a silently truncated closed-order list"+ )raise TossAPIError(f"Toss closed-order history has more than {_MAX_ORDER_HISTORY_PAGES} pages "f"of {_ORDER_HISTORY_PAGE_SIZE}; refusing to return a silently truncated list"diff --git a/agent/tests/test_sdk_connectors_toss.py b/agent/tests/test_sdk_connectors_toss.pyindex b838a2960..1a925eb1d 100644--- a/agent/tests/test_sdk_connectors_toss.py+++ b/agent/tests/test_sdk_connectors_toss.py@@ -268,6 +268,25 @@ def test_toss_closed_orders_pagination_cap_errors_instead_of_truncating(monkeypaassert "executions" not in result+def test_toss_closed_orders_has_next_without_cursor_is_an_error(monkeypatch) -> None:+ """``hasNext`` with no ``nextCursor`` is a broken page, not the last one:+ stopping there would hand back the same silently truncated history the+ page cap refuses."""++ def fake_get(cfg, path, *, authed, account_scoped, params=None):+ if params.get("status") == "OPEN":+ return _closed_page([], has_next=False)+ return _closed_page([{"orderId": "1"}], has_next=True, next_cursor=None)++ monkeypatch.setattr(toss, "_get", fake_get)+ cfg = toss.TossConfig(client_id="c", client_secret="s", account_seq="1")+ result = toss.get_open_orders(cfg, include_executions=True)++ assert result["status"] == "error"+ assert "nextCursor" in result["error"]+ assert "executions" not in result++def test_toss_get_quote_unwraps_result_list(monkeypatch) -> None:def fake_get(cfg, path, *, authed, account_scoped, params=None):assert path == "/api/v1/prices"