Exchange endpoint
The exchange endpoint is used to interact with and trade on the Hyperliquid chain. See the Python SDK for code to generate signatures for these requests.
For spot endpoints, use 10000 + index
where index
is the corresponding index in spotMeta
. For example, when submitting an order for PURR/USDC
, the asset that should be used is 10000
because its asset index in the spot metadata is 0
.
Place an order
POST
https://api.hyperliquid.xyz/exchange
See Python SDK for full featured examples on the fields of the order request.
For limit orders, TIF (time-in-force) sets the behavior of the order upon first hitting the book.
ALO (add liquidity only, i.e. "post only") will be canceled instead of immediately matching.
IOC (immediate or cancel) will have the unfilled part canceled instead of resting.
GTC (good til canceled) orders have no special behavior.
Client Order ID (cloid) is an optional 128 bit hex string, e.g. 0x1234567890abcdef1234567890abcdef
Headers
Name | Type | Description |
---|---|---|
Content-Type* | String | "application/json" |
Request Body
Name | Type | Description |
---|---|---|
action* | Object | { "type": "order", "grouping": "na", "orders": [{ "asset": Number, "isBuy": Boolean, "limitPx": String, "sz": String, "reduceOnly": Boolean, "cloid": Cloid (optional), "orderType": { "limit": { "tif": "Alo" | "Ioc" | "Gtc" } or "trigger": { "triggerPx": String, "isMarket": Boolean, "tpsl": "tp" | "sl" } }, }] } |
nonce* | Number | Recommended to use the current timestamp in milliseconds |
signature* | String | |
vaultAddress | String | If trading on behalf of a vault, its Onchain address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000 |
Cancel order(s)
POST
https://api.hyperliquid.xyz/exchange
Headers
Name | Type | Description |
---|---|---|
Content-Type* | String | "application/json" |
Request Body
Name | Type | Description |
---|---|---|
action* | Object | { "type": "cancel", "cancels": [ { "asset": Number, "oid": Number } ] } |
nonce* | Number | Recommended to use the current timestamp in milliseconds |
signature* | String | |
vaultAddress | String | If trading on behalf of a vault, its address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000 |
Cancel order(s) by cloid
POST
https://api.hyperliquid.xyz/exchange
Headers
Name | Type | Description |
---|---|---|
Content-Type* | String | "application/json" |
Request Body
Name | Type | Description |
---|---|---|
action* | Object | { "type": "cancelByCloid", "cancels": [ { "asset": Number, "cloid": String } ] } |
nonce* | Number | Recommended to use the current timestamp in milliseconds |
signature* | String | |
vaultAddress | String | If trading on behalf of a vault, its address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000 |
Modify an order
POST
https://api.hyperliquid.xyz/exchange
Headers
Name | Type | Description |
---|---|---|
Content-Type* | String | "application/json" |
Request Body
Name | Type | Description |
---|---|---|
action* | String | { "type": "modify", "oid": Number, "order": { "asset": Number, "isBuy": Boolean, "limitPx": String, "sz": String, "reduceOnly": Boolean, "cloid": Cloid (optional), "orderType": { "limit": { "tif": "Alo" | "Ioc" | "Gtc" } or "trigger": { "trigerPx": Number, "isMarket": Boolean, "tpsl": "tp" | "sl" } }, } } |
nonce* | Number | Recommended to use the current timestamp in milliseconds |
signature* | String | |
vaultAddress | String | If trading on behalf of a vault, its Onchain address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000 |
Modify multiple orders
POST
https://api.hyperliquid.xyz/exchange
Headers
Name | Type | Description |
---|---|---|
Content-Type* | String | "application/json" |
Request Body
Name | Type | Description |
---|---|---|
action* | String | { "type": "batchModify", "modifies": [ "oid": Number, "order": { "asset": Number, "isBuy": Boolean, "limitPx": String, "sz": String, "reduceOnly": Boolean, "cloid": Cloid (optional), "orderType": { "limit": { "tif": "Alo" | "Ioc" | "Gtc" } or "trigger": { "trigerPx": Number, "isMarket": Boolean, "tpsl": "tp" | "sl" } }, } ] } |
nonce* | Number | Recommended to use the current timestamp in milliseconds |
signature* | String | |
vaultAddress | String | If trading on behalf of a vault, its Onchain address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000 |
Update leverage
POST
https://api.hyperliquid.xyz/exchange
Update cross or isolated leverage on a coin.
Headers
Name | Type | Description |
---|---|---|
Content-Type* | String | "application/json" |
Request Body
Name | Type | Description |
---|---|---|
action* | Object | { "type": "updateLeverage", "asset": index of coin, "isCross": true or false if updating cross-leverage, "leverage": integer representing new leverage, subject to leverage constraints on that coin } |
nonce* | Number | Recommended to use the current timestamp in milliseconds |
signature* | String | |
vaultAddress | String | If trading on behalf of a vault, its Onchain address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000 |
Update isolated margin
POST
https://api.hyperliquid.xyz/exchange
Add or remove margin from isolated position
Headers
Name | Type | Description |
---|---|---|
Content-Type* | String | "application/json" |
Request Body
Name | Type | Description |
---|---|---|
action* | Object | { "type": "updateIsolatedMargin", "asset": index of coin, "isBuy": true, (this parameter won't have any effect until hedge mode is introduced) "ntli": float representing amount to add or remove, } |
nonce* | Number | Recommended to use the current timestamp in milliseconds |
signature* | String | |
vaultAddress | String | If trading on behalf of a vault, its Onchain address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000 |
L1 USDC transfer
POST
https://api.hyperliquid.xyz/exchange
Send usd to another address. This transfer does not touch the EVM bridge. The signature format is human readable for wallet interfaces.
Headers
Name | Type | Description |
---|---|---|
Content-Type* | String | "application/json" |
Request Body
Name | Type | Description |
---|---|---|
action* | Object | { "type": "usdTransfer", "chain": "Arbitrum" (on testnet use "ArbitrumGoerli" instead), "payload": { "destination": address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000, "amount": amount of usd to send as a string, e.g. "1" for 1 usd, "time": current timestamp in milliseconds as a Number, should match nonce } } |
nonce* | Number | Recommended to use the current timestamp in milliseconds |
signature* | String |
Initiate a Withdrawal Request
POST
https://api.hyperliquid.xyz/exchange
This method is used to initiate the withdrawal flow. After making this request, the L1 validators will sign and send the withdrawal request to the bridge contract. There is a $1 fee for withdrawing at the time of this writing and withdrawals take approximately 5 minutes to finalize.
Headers
Name | Type | Description |
---|---|---|
Content-Type* | String | "application/json" |
Request Body
Name | Type | Description |
---|---|---|
action* | Object | { "type": "withdraw2", "chain": "Arbitrum" | "ArbitrumTestnet", "payload": { "usd": amount of usd to send as a string, e.g. "1" for 1 usd, "time": current timestamp in milliseconds as a Number, should match nonce, "destination": address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000 } } |
nonce* | Number | Recommended to use the current timestamp in milliseconds, must match the nonce in the action Object above |
signature | String |
Transfer from Spot account to Perp account (and vice versa)
POST
https://api.hyperliquid.xyz/exchange
This method is used to transfer USDC from the user's spot wallet to perp wallet and vice versa.
Headers
Name | Value |
---|---|
Content-Type* | "application/json" |
Body
Name | Type | Description |
---|---|---|
action | Object | { "type": "spotUser", "classTransfer": { "usdc": amount of raw usdc to send (i.e. float amount times 1e6), "toPerp": True if (spot -> perp) else False } } |
nonce | Number | Recommended to use the current timestamp in milliseconds, must match the nonce in the action Object above |
signature | String |
Response
Last updated