{"templateId":"markdown","sharedDataIds":{},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"WebSocket API Overview","description":"Write your own software to control Collective2","keywords":"documentation,api,automated trading,Collective2 API Documentation","lang":"en-US","siteUrl":"https://c2-api.redocly.app/","meta":[{"name":"charset","content":"utf-8"}],"llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"websocket-api-overview","__idx":0},"children":["WebSocket API Overview"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Collective2 API provides a WebSocket endpoint for receiving real-time trading signals and position updates"," ","as they are published. Use WebSocket when you need low-latency push updates — instead of"," ","polling the REST API on a schedule such as GetStrategyActiveOrders, GetStrategyHistoricalOrders"," ","or GetStrategyHistoricalClosedTrades."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"when-to-use-websocket","__idx":1},"children":["When to Use WebSocket"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use the WebSocket API when you need signals & positions delivered to your application as soon as they"," ","are published. For historical data, use the REST endpoints."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"base-url","__idx":2},"children":["Base URL"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"wss://api4-general.collective2.com/ws\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"authentication","__idx":3},"children":["Authentication"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Pass your API key as a Bearer token in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Authorization"]}," header during the HTTP upgrade"," ","handshake:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"Authorization: Bearer YOUR_API_KEY\n"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Authentication happens at connection time. If your API key is invalid or missing, the"," ","server returns HTTP 401 before the WebSocket upgrade completes."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"available-channels","__idx":4},"children":["Available Channels"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Channel"},"children":["Channel"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["strategy.signal"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Real-time trading signals for a strategy"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["strategy.positions"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Real-time position updates for a strategy"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["See ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/guides/websocket-subscribe"},"children":["Subscribing to Channels"]}," for details on how to use channels."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"limits","__idx":5},"children":["Limits"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Limit"},"children":["Limit"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Value"},"children":["Value"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Connections per API key"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["10"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Channel subscriptions per connection"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["100"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"message-envelope","__idx":6},"children":["Message Envelope"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Every message — sent or received — uses the same JSON envelope:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n  \"msg_type\": \"string\",\n  \"id\": \"msg_a1b2c3d4e5f64a2b8c3d4e5f6a7b8\",\n  \"seq_id\": 98765,\n  \"request_id\": \"my-req-1\",\n  \"timestamp\": \"2024-01-01T12:00:00Z\",\n  \"v\": 4,\n  \"payload\": {}\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Field"},"children":["Field"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Type"},"children":["Type"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["msg_type"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Message type identifier"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["id"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Unique message ID assigned by the server"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["seq_id"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["integer"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Monotonically increasing sequence number for ordered streams. ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["null"]}," or absent on non-stream messages (heartbeats, acks)."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["request_id"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Optional. Echoes the client's ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["request_id"]}," for correlating requests to responses. Max 50 characters."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["timestamp"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["UTC timestamp in ISO 8601 format"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["v"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Protocol version"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["payload"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["object"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Message-specific data"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"client-message-types","__idx":7},"children":["Client Message Types"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Your application may only send two message types to the server:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"msg_type"},"children":["msg_type"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Purpose"},"children":["Purpose"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["subscription.request"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Subscribe or unsubscribe from a channel"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["heartbeat.ack"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Acknowledge a server heartbeat"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["All other message types are server-only. Sending an unknown type returns an error."]}]},"headings":[{"value":"WebSocket API Overview","id":"websocket-api-overview","depth":1},{"value":"When to Use WebSocket","id":"when-to-use-websocket","depth":2},{"value":"Base URL","id":"base-url","depth":2},{"value":"Authentication","id":"authentication","depth":2},{"value":"Available Channels","id":"available-channels","depth":2},{"value":"Limits","id":"limits","depth":2},{"value":"Message Envelope","id":"message-envelope","depth":2},{"value":"Client Message Types","id":"client-message-types","depth":3}],"frontmatter":{"title":"WebSocket API Overview","description":"Real-time trading signals via WebSocket","seo":{"title":"WebSocket API Overview"}},"lastModified":"2026-04-16T16:08:40.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/guides/websocket-overview","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}