{"record":{"id":"7f01054eb35212b4","repo":"nautechsystems/nautilus_trader","slug":"subscribe-market-requires-a-market-channel-clien","errorCode":null,"errorMessage":"subscribe_market() requires a market-channel client (created with new_market())","messagePattern":"subscribe_market\\(\\) requires a market-channel client \\(created with new_market\\(\\)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/websocket/client.rs","lineNumber":523,"sourceCode":"    }\n\n    /// Returns `true` if the user channel has been authenticated.\n    #[must_use]\n    pub fn is_authenticated(&self) -> bool {\n        self.auth_tracker.is_authenticated()\n    }\n\n    /// Subscribe to market data for the given asset IDs.\n    ///\n    /// Sends a subscribe message immediately if connected; the IDs are also\n    /// retained so they are re-sent automatically on reconnect.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if called on a user-channel client (incompatible channel).\n    pub async fn subscribe_market(&self, asset_ids: Vec<String>) -> anyhow::Result<()> {\n        if self.channel != WsChannel::Market {\n            anyhow::bail!(\n                \"subscribe_market() requires a market-channel client (created with new_market())\"\n            );\n        }\n        self.cmd_tx\n            .read()\n            .await\n            .send(HandlerCommand::SubscribeMarket(asset_ids))\n            .map_err(|e| anyhow::anyhow!(\"Failed to send SubscribeMarket: {e}\"))\n    }\n\n    /// Remove asset IDs from the active subscription set.\n    ///\n    /// The IDs are dropped from the reconnect set so they will not be\n    /// re-subscribed after a reconnect. No wire message is sent.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if called on a user-channel client (incompatible channel).","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/websocket/client.rs#L505-L541","documentation":"PolymarketWebSocketClient is built either for the market channel (new_market) or the user channel (new_user); each channel has its own subscription message schema. subscribe_market checks the configured channel and refuses to run on a user-channel client because the command would be invalid for that connection.","triggerScenarios":"Calling subscribe_market(asset_ids) on a client constructed with PolymarketWebSocketClient::new_user() (or otherwise configured as WsChannel::User).","commonSituations":"Mixing up client constructors when wiring multiple connections; reusing one client for both book data and order/fill updates; copy-pasted client setup where the user-channel client is passed to a data-engine that calls subscribe_market.","solutions":["Create the client with PolymarketWebSocketClient::new_market() before subscribing to market data","Keep separate market-channel and user-channel clients and route each subscription call to the right instance","Check client.channel (or is_market()/is_user() helpers) before calling subscribe_market"],"exampleFix":"// before\nlet client = PolymarketWebSocketClient::new_user(creds);\nclient.subscribe_market(asset_ids).await?;\n// after\nlet client = PolymarketWebSocketClient::new_market().await?;\nclient.subscribe_market(asset_ids).await?;","handlingStrategy":"validation","validationCode":"if client.channel() != WsChannel::Market {\n    anyhow::bail!(\"subscribe_market needs a new_market() client\");\n}\nclient.subscribe_market(asset_ids).await?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use new_market() for data clients and new_user() for order/fill clients","Route subscription calls through helpers that check channel first","Keep one client per channel; never reuse across channels"],"tags":["rust","websocket","polymarket","channel-mismatch"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}