Subscriptions
This page describes subscribing to data streams using the WebSocket API.
Subscription Messages
To subscribe to specific data feeds, you need to send a subscription message. The subscription message format is as follows:
The subscription object contains the details of the specific feed you want to subscribe to. Choose from the following subscription types and provide the corresponding properties:
allMids
:Subscription message:
{ "type": "allMids" }
Data format:
AllMids
notification
:Subscription message:
{ "type": "notification", "user": "<address>" }
Data format:
Notification
webData2
Subscription message:
{ "type": "webData2", "user": "<address>" }
Data format:
WebData2
candle
:Subscription message:
{ "type": "candle", "coin": "<coin_symbol>", "interval": "<candle_interval>" }
Data format:
Candle[]
l2Book
:Subscription message:
{ "type": "l2Book", "coin": "<coin_symbol>" }
Optional parameters: nSigFigs: int, mantissa: int
Data format:
WsBook
trades
:Subscription message:
{ "type": "trades", "coin": "<coin_symbol>" }
Data format:
WsTrade[]
orderUpdates
:Subscription message:
{ "type": "orderUpdates", "user": "<address>" }
Data format:
WsOrder[]
userEvents
:Subscription message:
{ "type": "userEvents", "user": "<address>" }
Data format:
WsUserEvent
userFills
:Subscription message:
{ "type": "userFills", "user": "<address>" }
Optional parameter:
aggregateByTime: bool
Data format:
WsUserFills
userFundings
:Subscription message:
{ "type": "userFundings", "user": "<address>" }
Data format:
WsUserFundings
userNonFundingLedgerUpdates
:Subscription message:
{ "type": "userNonFundingLedgerUpdates", "user": "<address>" }
Data format:
WsUserNonFundingLedgerUpdates
activeAssetCtx
:Subscription message:
{ "type": "activeAssetCtx", "coin": "coin_symbol>" }
Data format:
WsActiveAssetCtx
orWsActiveSpotAssetCtx
activeAssetData
: (only supports Perps)Subscription message:
{ "type": "activeAssetData", "user": "<address>", "coin": "coin_symbol>" }
Data format:
WsActiveAssetData
Data Formats
The server will respond to successful subscriptions with a message containing the channel
property set to "subscriptionResponse"
, along with the data
field providing the original subscription. The server will then start sending messages with the channel
property set to the corresponding subscription type e.g. "allMids"
and the data
field providing the subscribed data.
The data
field format depends on the subscription type:
AllMids
: All mid prices.Format:
AllMids { mids: Record<string, string> }
Notification
: A notification message.Format:
Notification { notification: string }
WebData2
: Aggregate information about a user, used primarily for the frontend.Format:
WebData2
WsTrade[]
: An array of trade updates.Format:
WsTrade[]
WsBook
: Order book snapshot updates.Format:
WsBook { coin: string; levels: [Array<WsLevel>, Array<WsLevel>]; time: number; }
WsOrder
: User order updates.Format:
WsOrder[]
WsUserEvent
: User events that are not order updatesFormat:
WsUserEvent { "fills": [WsFill] | "funding": WsUserFunding | "liquidation": WsLiquidation | "nonUserCancel": [WsNonUserCancel] }
WsUserFills
: Fills snapshot followed by streaming fillsWsUserFundings
: Funding payments snapshot followed by funding payments on the hourWsUserNonFundingLedgerUpdates
: Ledger updates not including funding payments: withdrawals, deposits, transfers, and liquidations
For the streaming user endpoints such as WsUserFills
,WsUserFundings
the first message has isSnapshot: true
and the following streaming updates have isSnapshot: false
.
Data Type Definitions
Here are the definitions of the data types used in the WebSocket API:
Please note that the above data types are in TypeScript format, and their usage corresponds to the respective subscription types.
Examples
Here are a few examples of subscribing to different feeds using the subscription messages:
Subscribe to all mid prices:
Subscribe to notifications for a specific user:
Subscribe to web data for a specific user:
Subscribe to candle updates for a specific coin and interval:
Subscribe to order book updates for a specific coin:
Subscribe to trades for a specific coin:
Unsubscribing from WebSocket Feeds
To unsubscribe from a specific data feed on the Hyperliquid WebSocket API, you need to send an unsubscribe message with the following format:
The subscription
object should match the original subscription message that was sent when subscribing to the feed. This allows the server to identify the specific feed you want to unsubscribe from. By sending this unsubscribe message, you inform the server to stop sending further updates for the specified feed.
Please note that unsubscribing from a specific feed does not affect other subscriptions you may have active at that time. To unsubscribe from multiple feeds, you can send multiple unsubscribe messages, each with the appropriate subscription details.
Last updated