Subscription and authorization to Yuzu's streaming API is super easy, and requires no special subscription messages to be sent over your websocket connection.
Yuzu supports two protocols for streaming connections, Websockets, and Server-sent events.
Endpoint | Base URL |
---|---|
WebSocket | wss://ws.yuzu.dev/ws |
Server-sent events | https://sse.yuzu.dev/sse |
Pass the following query params to either base url to initiate a streaming session:
Parameter Name | Required? | Sample Value | Notes |
---|---|---|---|
token |
Yes | demo-gbcJ93WMe9S |
|
streams |
Yes | C:1S:BTC-USD,S:T:AAPL |
Comma-delimited set of stream tokens |
You can pass as many streams
to a given endpoint as you like. Read more about how our stream stream symbols are generated here.
$ |
|
$ |
|
1 2 3 4 5 6 7 8 |
|
1 2 3 4 5 6 7 8 |
|
Websockets and server-sent events are both convenient ways to get streaming data from servers to clients, but what's the difference? Why do we offer both, and which one should you use? We're going to try to answer those questions below.
Websockets are a full-duplex transport protocol built on top of TCP. It's fully separate from HTTP, and being full-duplex means that messages can be sent in two directions, from server to client and vice versa. Most browsers support the WebSocket API, and there libraries available to handle websockets in most languages.
Meanwhile, the Server-sent events protocol is built into the HTTP spec, and only operates in one direction, from server to client. When the client makes an HTTP GET
request to the server, the server responds with a Content-Type
header set to text/event-stream
, and holds the connection open. The Content-Type
header instructs the client to keep reading from the connection until it's closed by either end. Most browsers have support for the EventSource API.
In most cases, the WebSocket API should be the preferred integration. It's lightweight, easy-to-use, and well-supported across most modern platforms. However, Server-sent events is great when you want to test things out using cURL or in the browser, or you're on a platform without support for WebSockets.