color:red;">\*</mark> | String | "application/json" |
#### Request Body
| Name | Type | Description |
| ------------------------------------------- | ------ | -------------------------------------------------------- |
| action<mark style="color:red;">\*</mark> | Object | <p>{</p><p> "type": "noop"</p><p>}</p> |
| nonce<mark style="color:red;">\*</mark> | Number | Recommended to use the current timestamp in milliseconds |
| signature<mark style="color:red;">\*</mark> | Object | |
| expiresAfter | Number | Timestamp in milliseconds |
{% tabs %}
{% tab title="200: OK Successful Response" %}
```
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
## Enable HIP-3 DEX abstraction
<mark style="color:green;">`POST`</mark> `https://api.hyperliquid.xyz/exchange`
NOTE: deprecrated. Prefer `userSetAbstraction`.
If set, actions on HIP-3 perps will automatically transfer collateral from validator-operated USDC perps balance for HIP-3 DEXs where USDC is the collateral token, and spot otherwise. When HIP-3 DEX abstraction is active, collateral is returned to the same source (validator-operated USDC perps or spot balance) when released from positions or open orders.
#### Headers
| Name | Type | Description |
| ---------------------------------------------- | ------ | ------------------ |
| Content-Type<mark style="color:red;">\*</mark> | String | "application/json" |
#### Request Body
<table><thead><tr><th width="106.30859375">Name</th><th width="159.5078125">Type</th><th>Description</th></tr></thead><tbody><tr><td>action<mark style="color:red;">*</mark></td><td>Object</td><td><p>{</p><p> "type": "userDexAbstraction",</p><p> "hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),</p><p> "signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,</p><p> "user": address in 42-character hexadecimal format. Can be a sub-account of the user,</p><p> "enabled": boolean,</p><p> "nonce": current timestamp in milliseconds as a Number, should match nonce</p><p>}</p></td></tr><tr><td>nonce<mark style="color:red;">*</mark></td><td>Number</td><td>Recommended to use the current timestamp in milliseconds</td></tr><tr><td>signature<mark style="color:red;">*</mark></td><td>Object</td><td></td></tr></tbody></table>
{% tabs %}
{% tab title="200: OK Successful Response" %}
```
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
## Enable HIP-3 DEX abstraction (agent)
NOTE: deprecrated. Prefer `agentSetAbstraction`.
Same effect as UserDexAbstraction above, but only works if setting the value from `null` to `true`.
#### Headers
| Name | Type | Description |
| ---------------------------------------------- | ------ | ------------------ |
| Content-Type<mark style="color:red;">\*</mark> | String | "application/json" |
#### Request Body
| Name | Type | Description |
| ------------------------------------------- | ------ | ------------------------------------------------------------ |
| action<mark style="color:red;">\*</mark> | Object | <p>{</p><p> "type": "agentEnableDexAbstraction"</p><p>}</p> |
| nonce<mark style="color:red;">\*</mark> | Number | Recommended to use the current timestamp in milliseconds |
| signature<mark style="color:red;">\*</mark> | Object | |
{% tabs %}
{% tab title="200: OK Successful Response" %}
```
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
## Set User Abstraction
<mark style="color:green;">`POST`</mark> `https://api.hyperliquid.xyz/exchange`
#### Headers
| Name | Type | Description |
| ---------------------------------------------- | ------ | ------------------ |
| Content-Type<mark style="color:red;">\*</mark> | String | "application/json" |
#### Request Body
| Name | Type | Description |
| ------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| action<mark style="color:red;">\*</mark> | Object | <p>{</p><p>"type": "userSetAbstraction",</p><p>"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),</p><p>"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,</p><p>"user": address in 42-character hexadecimal format. Can be a sub-account of the user,</p><p>"abstraction": one of the strings \["disabled", "unifiedAccount", "portfolioMargin"],</p><p>"nonce": current timestamp in milliseconds as a Number, should match nonce</p><p>}</p> |
| nonce<mark style="color:red;">\*</mark> | Number | Recommended to use the current timestamp in milliseconds |
| signature<mark style="color:red;">\*</mark> | Object | |
{% tabs %}
{% tab title="200: OK Successful Response" %}
```json
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
## Set User Abstraction (agent)
<mark style="color:green;">`POST`</mark> `https://api.hyperliquid.xyz/exchange`
#### Headers
| Name | Type | Description |
| ---------------------------------------------- | ------ | ------------------ |
| Content-Type<mark style="color:red;">\*</mark> | String | "application/json" |
#### Request Body
| Name | Type | Description |
| ------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| action<mark style="color:red;">\*</mark> | Object | <p>{</p><p>"type": "agentSetAbstraction",</p><p> "abstraction": one of the strings \["i", "u", "p"] where "i" is "disabled", "u" is "unifiedAccount", and "p" is "portfolioMargin"</p><p>}</p> |
| nonce<mark style="color:red;">\*</mark> | Number | Recommended to use the current timestamp in milliseconds |
| signature<mark style="color:red;">\*</mark> | Object | |
{% tabs %}
{% tab title="200: OK Successful Response" %}
```json
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
## Split outcome
Split `X` quote tokens into `X` Yes and `X` No shares.
<mark style="color:green;">`POST`</mark> `https://api.hyperliquid.xyz/exchange`
#### Headers
| Name | Type | Description |
| ---------------------------------------------- | ------ | ------------------ |
| Content-Type<mark style="color:red;">\*</mark> | String | "application/json" |
#### Request Body
| Name | Type | Description |
| ------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------- |
| action<mark style="color:red;">\*</mark> | Object | <p>{</p><p> "type": "userOutcome",</p><p> "splitOutcome": { "outcome": Number, amount: String (e.g., "123.0") }</p><p>}</p> |
| nonce<mark style="color:red;">\*</mark> | Number | Recommended to use the current timestamp in milliseconds |
| signature<mark style="color:red;">\*</mark> | Object | |
{% tabs %}
{% tab title="200: OK Successful Response" %}
```
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
## Merge outcome
Merge `X` Yes and `X` No shares into `X` quote tokens.
<mark style="color:green;">`POST`</mark> `https://api.hyperliquid.xyz/exchange`
#### Headers
| Name | Type | Description |
| ---------------------------------------------- | ------ | ------------------ |
| Content-Type<mark style="color:red;">\*</mark> | String | "application/json" |
#### Request Body
| Name | Type | Description | |
| ------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------- | ----------------------------------- |
| action<mark style="color:red;">\*</mark> | Object | <p>{</p><p> "type": "userOutcome",</p><p> "mergeOutcome": { "outcome": Number, amount: String | null (null means max) }</p><p>}</p> |
| nonce<mark style="color:red;">\*</mark> | Number | Recommended to use the current timestamp in milliseconds | |
| signature<mark style="color:red;">\*</mark> | Object | | |
{% tabs %}
{% tab title="200: OK Successful Response" %}
```
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
## Merge question
Merge `X` Yes shares from each outcome associated to the same question into `X` quote tokens.
<mark style="color:green;">`POST`</mark> `https://api.hyperliquid.xyz/exchange`
#### Headers
| Name | Type | Description |
| ---------------------------------------------- | ------ | ------------------ |
| Content-Type<mark style="color:red;">\*</mark> | String | "application/json" |
#### Request Body
| Name | Type | Description | |
| ------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------- | ----------------------------------- |
| action<mark style="color:red;">\*</mark> | Object | <p>{</p><p> "type": "userOutcome",</p><p> "mergeQuestion": { "question": Number, amount: String | null (null means max) }</p><p>}</p> |
| nonce<mark style="color:red;">\*</mark> | Number | Recommended to use the current timestamp in milliseconds | |
| signature<mark style="color:red;">\*</mark> | Object | | |
{% tabs %}
{% tab title="200: OK Successful Response" %}
```
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
## Negate outcome
Convert `X` No shares from an outcome associated with a question into `X` Yes shares of every other outcome associated with the question.
<mark style="color:green;">`POST`</mark> `https://api.hyperliquid.xyz/exchange`
#### Headers
| Name | Type | Description |
| ---------------------------------------------- | ------ | ------------------ |
| Content-Type<mark style="color:red;">\*</mark> | String | "application/json" |
#### Request Body
| Name | Type | Description |
| ------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| action<mark style="color:red;">\*</mark> | Object | <p>{</p><p> "type": "userOutcome",</p><p> "negateOutcome": { "question": Number, "outcome": Number, amount: String }</p><p>}</p> |
| nonce<mark style="color:red;">\*</mark> | Number | Recommended to use the current timestamp in milliseconds |
| signature<mark style="color:red;">\*</mark> | Object | |
{% tabs %}
{% tab title="200: OK Successful Response" %}
```
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
## Validator vote on risk-free rate for aligned quote asset
<mark style="color:green;">`POST`</mark> `https://api.hyperliquid.xyz/exchange`
#### Headers
| Name | Type | Description |
| ---------------------------------------------- | ------ | ------------------ |
| Content-Type<mark style="color:red;">\*</mark> | String | "application/json" |
#### Request Body
| Name | Type | Description |
| ------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------- |
| action<mark style="color:red;">\*</mark> | Object | <p>{</p><p> "type": "validatorL1Stream",</p><p> "riskFreeRate": String // e.g. "0.04" for 4%</p><p>}</p> |
| nonce<mark style="color:red;">\*</mark> | Number | Recommended to use the current timestamp in milliseconds |
| signature<mark style="color:red;">\*</mark> | Object | |
{% tabs %}
{% tab title="200: OK Successful Response" %}
```
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
## Authorize AQAv2 role
<mark style="color:green;">`POST`</mark> `https://api.hyperliquid.xyz/exchange`
#### Headers
| Name | Type | Description |
| ---------------------------------------------- | ------ | ------------------ |
| Content-Type<mark style="color:red;">\*</mark> | String | "application/json" |
#### Request Body
| Name | Type | Description | |
| ------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------ | ---------------------- |
| action<mark style="color:red;">\*</mark> | Object | <p>{</p><p> "type": "authorizeAqav2Role",</p><p> "token": number // e.g. 0 for USDC,</p><p> "role": "technical" | "treasury"</p><p>}</p> |
| nonce<mark style="color:red;">\*</mark> | Number | Recommended to use the current timestamp in milliseconds | |
| signature<mark style="color:red;">\*</mark> | Object | | |
{% tabs %}
{% tab title="200: OK Successful Response" %}
```
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
## Claim rewards
<mark style="color:green;">`POST`</mark> `https://api.hyperliquid.xyz/exchange`
#### Headers
| Name | Type | Description |
| ---------------------------------------------- | ------ | ------------------ |
| Content-Type<mark style="color:red;">\*</mark> | String | "application/json" |
#### Request Body
| Name | Type | Description |
| ------------------------------------------- | ------ | -------------------------------------------------------- |
| action<mark style="color:red;">\*</mark> | Object | <p>{</p><p> "type": "claimRewards"</p><p>}</p> |
| nonce<mark style="color:red;">\*</mark> | Number | Recommended to use the current timestamp in milliseconds |
| signature<mark style="color:red;">\*</mark> | Object | |
{% tabs %}
{% tab title="200: OK Successful Response" %}
```json
{'status': 'ok', 'response': {'type': 'default'}}
```
{% endtab %}
{% endtabs %}
# Websocket
WebSocket endpoints are available for real-time data streaming and as an alternative to HTTP request sending on the Hyperliquid exchange. The WebSocket URLs by network are:
* Mainnet: `wss://api.hyperliquid.xyz/ws` 
* Testnet: `wss://api.hyperliquid-testnet.xyz/ws`.
### Connecting
To connect to the WebSocket API, establish a WebSocket connection to the respective URL based on the desired network. Once connected, you can start sending subscription messages to receive real-time data updates.
Example from command line:
```
$ wscat -c wss://api.hyperliquid.xyz/ws
Connected (press CTRL+C to quit)
> { "method": "subscribe", "subscription": { "type": "trades", "coin": "SOL" } }
< {"channel":"subscriptionResponse","data":{"method":"subscribe","subscription":{"type":"trades","coin":"SOL"}}}
```
Important: all automated users should handle disconnects from the server side and gracefully reconnect. Disconnection from API servers may happen periodically and without announcement. Missed data during the reconnect will be present in the snapshot ack on reconnect. Users can also manually query any missed data using the corresponding info request.
Note: this doc uses Typescript for defining many of the message types. The python SDK also has examples [here](https://github.com/hyperliquid-dex/hyperliquid-python-sdk/blob/master/hyperliquid/utils/types.py) and example connection code [here](https://github.com/hyperliquid-dex/hyperliquid-python-sdk/blob/master/hyperliquid/websocket_manager.py).
# 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:
```json
{
"method": "subscribe",
"subscription": { ... }
}
```
The subscription ack provides a snapshot of previous data for time series data (e.g. user fills). These snapshot messages are tagged with `isSnapshot: true` and can be ignored if the previous messages were already processed.
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:
1. `allMids`:
* Subscription message: `{ "type": "allMids", "dex": "<dex>" }`
* Data format: `AllMids` 
* The `dex` field represents the perp dex to source mids from.
* Note that the `dex` field is optional. If not provided, then the first perp dex is used. Spot mids are only included with the first perp dex.
2. `notification`:
* Subscription message: `{ "type": "notification", "user": "<address>" }`
* Data format: `Notification`
3. `webData3` :
* Subscription message: `{ "type": "webData3", "user": "<address>" }`
* Data format: `WebData3` 
4. `twapStates` :
* Subscription message: `{ "type": "twapStates", "user": "<address>", "dex": "<dex>" }`
* Data format: `TwapStates` 
5. `clearinghouseState:`
* Subscription message: `{ "type": "clearinghouseState", "user": "<address>", "dex": "<dex>" }`
* Data format: `ClearinghouseState` 
6. `openOrders`:
* Subscription message: `{ "type": "openOrders", "user": "<address>", "dex": "<dex>" }`
* Data format: `OpenOrders` 
7. `candle`:
* Subscription message: `{ "type": "candle", "coin": "<coin_symbol>", "interval": "<candle_interval>" }`
*  Supported intervals: "1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "8h", "12h", "1d", "3d", "1w", "1M"
* Data format: `Candle[]`
8. `l2Book`:
* Subscription message: `{ "type": "l2Book", "coin": "<coin_symbol>" }`
* Optional parameters: `nSigFigs: int`, `mantissa: int` , `fast: boolean` (5 levels if fast, 20 levels if slow)
* Data format: `WsBook`
9. `trades`:
* Subscription message: `{ "type": "trades", "coin": "<coin_symbol>" }`
* Data format: `WsTrade[]`
10. `orderUpdates`:
* Subscription message: `{ "type": "orderUpdates", "user": "<address>" }`
* Data format: `WsOrder[]`
11. `userEvents`: 
* Subscription message: `{ "type": "userEvents", "user": "<address>" }`
* Data format: `WsUserEvent`
* Note: The channel name for `userEvents` messages is `"channel": "user"`
12. `userFills`: 
* Subscription message: `{ "type": "userFills", "user": "<address>" }`
* Optional parameter: `aggregateByTime: bool` 
* Data format: `WsUserFills`
13. `userFundings`: 
* Subscription message: `{ "type": "userFundings", "user": "<address>" }`
* Data format: `WsUserFundings`
14. `userNonFundingLedgerUpdates`: 
* Subscription message: `{ "type": "userNonFundingLedgerUpdates", "user": "<address>" }`
* Data format: `WsUserNonFundingLedgerUpdates`
15. `activeAssetCtx`: 
* Subscription message: `{ "type": "activeAssetCtx", "coin": "<coin_symbol>" }`
* Data format: `WsActiveAssetCtx` or `WsActiveSpotAssetCtx` 
16. `activeAssetData`: (only supports Perps)
* Subscription message: `{ "type": "activeAssetData", "user": "<address>", "coin": "<coin_symbol>" }`
* Data format: `WsActiveAssetData`
17. `userTwapSliceFills`: 
* Subscription message: `{ "type": "userTwapSliceFills", "user": "<address>" }`
* Data format: `WsUserTwapSliceFills`
18. `userTwapHistory`: 
* Subscription message: `{ "type": "userTwapHistory", "user": "<address>" }`
* Data format: `WsUserTwapHistory`
19. `bbo` :
* Subscription message: `{ "type": "bbo", "coin": "<coin>" }`
* Data format: `WsBbo`
20. `spotState`
* Subscription message: `{ "type": "spotState", "user": "<address>", "isPortfolioMargin": bool }`
* Data format: `WsSpotState` 
* `isPortfolioMargin` is an optional argument
21. `allDexsClearinghouseState`
1. Subscription message: `{ "type": "allDexsClearinghouseState", "user": "<address>" }`
2. Data format: `WsAllDexsClearinghouseState`
22. `allDexsAssetCtxs` 
1. Subscription message: `{ "type": "allDexsAssetCtxs" }`
2. Data format: `WsAllDexsAssetCtxs`
23. `outcomeMetaUpdates`
1. Subscription message: `{ 프로젝트로 돌아가기