Stream subscriptions
Listen Key Mechanism
Description
The listen_key is a unique token required for user authentication and to establish a WebSocket connection. It binds a user to a WebSocket session, ensuring that only authenticated users can access the private streams.
Acquiring a Listen Key
Users must first authenticate with the server to receive a
listen_keyThis key is then used in the WebSocket connection headers to validate the user's session
Listen Key Expirations
Listen keys have a limited lifetime of 60 minutes
Users can prolong the key's lifetime
The server monitors the listen's key expirations and will automatically close the WebSocket connection when they expire
WebSocket Connection Query parameters documentation
listen_key parameter
The listen_key parameter is crucial for accessing the WebSocket server. It carries the listen_key token that is unique to each user session.
Obtaining the listen_key:
listen_key:The
listen_keycan be obtained via aGETrequest to thelisten_keyendpoint provided by the server after user authentication.Once acquired, the
listen_keymust be included in the query parameter for the WebSocket handshake.
Signer parameter
The signer parameter identifies the main account associated with the WebSocket connection. This query parameter is used along with the listen_key to establish a secure and authenticated connection.
Usage:
Key:
SignerValue: Address of the signer of trading account.
WebSocket Server Streams Documentation
1. Fills Stream (fills_ prefix)
fills_ prefix)Description
This is a private stream that provides real-time information about order fills.
Requires authentication and authorization to access specific trading accounts.
Connection Request
To subscribe to the Fills Stream:
Action: "subscribe"
Stream: "fills_{trading_account_address}"
Replace
{trading_account_address}with the specific trading account you want to subscribe to.
ID: A unique request identifier.
Example subscription request:
Example subscription response (same response structure as for HTTP requests
Example Stream Events
Order flow:
submit -> if succ response -> put into processing queue ->:
failed to process -> NOT_PROCCESSED (matcher result = FAILED_VALIDATION)
processed -> ACK -> OPEN -> ...
Partially filled
Fully filled
Failed validation
Cancelled
Failed to cancel
Matching engine unable to match remaining amount
Examples of special events:
Cancel all order under specified ticker
FAILED_ROLLUP:
REIMBURSE:
EXPIRED:
2. Best Bid and Offer (BBO) Stream (bbo)
bbo)Description
Provides real-time best bid and offer updates for a specified trading pair.
Connection Request
To subscribe to the BBO Stream:
Action: "subscribe"
Stream: "bbo"
Base: The base token of the trading pair.
Quote: The quote token of the trading pair.
Ecosystem_book: Boolean indicating whether to use Ecosystem Book updates.
ID: A unique request identifier.
Example subscription request:
Example subscription response (same response structure as for HTTP requests)
Example Stream Event:
3. Trade Stream (trade)
trade)Description
Real-time stream of trade data for a specified trading pair.
Connection Request
To subscribe to the Trade Stream:
Use the same format as the BBO stream but with Stream: "trade".
Example subscription Request:
Example subscription Response (same response structure as for HTTP requests)
Example Stream Output
4. Snapshot Stream (snap)
snap)Description
Provides snapshots of trading data (specific details not provided in the code).
Connection Request
To subscribe to the Snapshot Stream:
Use the same format as the BBO stream but with Stream: "snap".
Example Stream Output
Unsubscribe from a Stream
To unsubscribe from any stream:
Action: "unsubscribe"
Stream: Specify the stream you want to unsubscribe from.
ID: A unique request identifier.
Example Stream Output
Last updated