Documentation Index
Fetch the complete documentation index at: https://docs.struct.to/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Struct’s websocket API lets you stream real-time Polymarket data directly to your application without polling the REST API. Connect once, subscribe to any number of rooms, and receive live updates for trades, prices, metrics, positions, PnL, order books, and more. Websockets are ideal for trading UIs, dashboards, and agents that need low-latency access to what’s happening on Polymarket right now.Endpoints
There are two websocket endpoints available:| Endpoint | Purpose |
|---|---|
wss://api.struct.to/ws | Rooms: subscribe to data streams by topic (trades, prices, metrics, etc.) |
wss://api.struct.to/ws/alerts | Alerts: receive webhook-style events pushed over the same connection |
Authentication
Authenticate by appending your API key as a query parameter:Your First Connection
Create an account
Sign up at struct.to/dashboard and create an organisation.
Open a connection
Use any WebSocket client to connect. Below is a JavaScript example that connects, subscribes to the Trades room for a specific market, and logs messages as they arrive.
Message Protocol
All messages sent and received are JSON. Client messages use atype and payload envelope:
Joining and Subscribing
Subscribing to a room is a two-step flow:- Join the room with
join_room. - Configure the subscription by sending a
room_messagewith anaction: "subscribe"payload and any filters.
subscribe message. The new filters replace the previous ones.
Unsubscribing
To stop receiving messages from a room, sendunsubscribe_all followed by leave_room:
Keepalive
Send a ping every 30 seconds to keep the connection alive:{ "type": "pong" }, which you can safely ignore.
Connection Limits
Each plan has a cap on the number of concurrent websocket connections your organisation can have open at once:| Plan | Concurrent connections |
|---|---|
| Free | 1 |
| Hobby | 50 |
| Startup | 250 |
| Scale | 1,000 |
| Enterprise | Unlimited |