Developers do not have to directly rely on the SDK to subscribe to the Stream API. Any language with a websocket client can directly subscribe to the Stream API and receive updates. The developer will need the following to subscribe:
- Base Endpoint:
- Mainnet:
wss://stream.openseabeta.com/socket/websocket
- Testnet:
wss://testnets-stream.openseabeta.com/socket/websocket
- Mainnet:
- API Key
- Collection they’d like to subscribe to
- Can use
*
to subscribe to all
- Can use
- Event types to subscribe to
item_metadata_updated
item_listed
item_sold
item_transferred
item_received_offer
item_received_bid
item_cancelled
Construct your full connection string as:Step 1. Connecting
**{base_endpoint}?token={api_key}**
For example:
wss://testnets-stream.openseabeta.com/socket/websocket?token=<API_KEY>
And set up your client to connect to this endpoint. You should ping the Server every 30 seconds with a heartbeat message that should look as follows:{ "topic": "phoenix", "event": "heartbeat", "payload": {}, "ref": 0 }
Figure out the slug of the collection you’d like to join and the event type you’d like to subscribe to. One current limitation is that you will only be able to subscribe to all events for this collection, and will therefore need to filter client-side as needed on event_types.Step 2: Subscribing to a collection
Send the following message to subscribe to a collection:Keep track of the{ "topic": "collection:boredapeyachtclub", "event": "phx_join", "payload": {}, "ref": 0 }
ref
number used here, as it can be used later when unsubscribing
To unsubscribe, you’ll need to just change theStep 3: Unsubscribing from a collectionevent
field tophx_leave
and pass in the sameref
value used earlier.ref
allows you to use multiple concurrent connection to different Collections as needed. You can also simply close your websocket client’s connection to disconnect.
Firecamp is a popular API GUI client that supports making websocket requests. We’ve prepared a ready-to-use example in testnets that can be imported directly to your Firecamp app to see how we are able to connect to the Stream API and make requests. It also automatically pings for a heartbeat every 30 seconds to ensure your client remains connected.Example: Firecamp
Stream API Example_firecamp.json
Simply import this into your Firecamp UI to get a working, ready to use example of connecting to the Stream API Websocket
Source for websocket connecting