diff --git a/src/polymarket/_internal/streams/clob/user_protocol.py b/src/polymarket/_internal/streams/clob/user_protocol.py index cb7d9c2..87f1a41 100644 --- a/src/polymarket/_internal/streams/clob/user_protocol.py +++ b/src/polymarket/_internal/streams/clob/user_protocol.py @@ -35,15 +35,17 @@ def derive_state(subs: Iterable[UserSubscription]) -> UserServerState: def build_initial_frame(state: UserServerState, credentials: ApiKeyCreds) -> dict[str, Any]: - return { + frame: dict[str, Any] = { "type": "user", "auth": { "apiKey": credentials.key, "secret": credentials.secret, "passphrase": credentials.passphrase, }, - "markets": list(state.markets), } + if not state.include_all_markets: + frame["markets"] = list(state.markets) + return frame def _build_subscribe_update(markets: Iterable[str]) -> dict[str, Any]: diff --git a/tests/unit/test_streams_user_manager.py b/tests/unit/test_streams_user_manager.py index 7411fe6..c687ed0 100644 --- a/tests/unit/test_streams_user_manager.py +++ b/tests/unit/test_streams_user_manager.py @@ -75,7 +75,7 @@ async def run() -> None: } -def test_initial_frame_for_all_markets_uses_empty_markets() -> None: +def test_initial_frame_for_all_markets_omits_market_filter() -> None: received: list[dict[str, Any]] = [] async def handler(ws: ServerConnection) -> None: @@ -95,7 +95,7 @@ async def run() -> None: await mgr.close() asyncio.run(run()) - assert received[0]["markets"] == [] + assert "markets" not in received[0] def test_credentials_resolved_fresh_per_connection() -> None: @@ -204,7 +204,7 @@ async def run() -> None: asyncio.run(run()) assert received[0]["type"] == "user" - assert received[0]["markets"] == [] + assert "markets" not in received[0] assert {"operation": "subscribe", "markets": ["m1"]} in received diff --git a/tests/unit/test_streams_user_protocol.py b/tests/unit/test_streams_user_protocol.py index cbf5f1e..35dbd1a 100644 --- a/tests/unit/test_streams_user_protocol.py +++ b/tests/unit/test_streams_user_protocol.py @@ -63,9 +63,12 @@ def test_initial_frame_shape() -> None: } -def test_initial_frame_all_markets_sends_empty_markets() -> None: +def test_initial_frame_all_markets_omits_market_filter() -> None: state = UserServerState(include_all_markets=True, markets=()) - assert build_initial_frame(state, _CREDS)["markets"] == [] + assert build_initial_frame(state, _CREDS) == { + "type": "user", + "auth": {"apiKey": "K", "secret": "S", "passphrase": "P"}, + } def test_diff_no_change() -> None: