Skip to main content
POST
/
v2
/
global_markets_perps
/
set_leverage
Python (SDK)
from compass_api_sdk import CompassAPI


with CompassAPI(
    api_key_auth="<YOUR_API_KEY_HERE>",
) as compass_api:

    res = compass_api.global_markets_perps.global_markets_perps_set_leverage(owner="<value>", asset="<value>")

    # Handle response
    print(res)
{
  "action": {
    "asset": 12,
    "isCross": true,
    "leverage": 5,
    "type": "updateLeverage"
  },
  "leverage_ok": false,
  "nonce": 1747010983250,
  "typed_data": {
    "domain": {
      "chainId": 1337,
      "name": "Exchange",
      "verifyingContract": "0x0000000000000000000000000000000000000000",
      "version": "1"
    },
    "message": {
      "connectionId": "0xc4e1f04d6b1bf2f2f7a6c0e8a5f3b1d2c9e0a4b7d1c3e5f7a9b1d3e5f7a9e9a2",
      "source": "a"
    },
    "primaryType": "Agent",
    "types": {
      "Agent": [
        {
          "name": "source",
          "type": "string"
        },
        {
          "name": "connectionId",
          "type": "bytes32"
        }
      ]
    }
  }
}

Authorizations

x-api-key
string
header
required

Your Compass API Key. Get your key here.

Body

application/json

Request to set leverage on a global markets perps asset.

Omit leverage (or pass null) to target the asset's maximum leverage.

owner
string
required

User's EOA address

asset
string
required

Asset ticker (e.g. 'AAPL', 'CL')

leverage
integer | null

Target leverage as a whole-number multiplier. Omit (or pass null) to use the asset's maximum leverage. Must be between 1 and the asset's max leverage, which is available from the /opportunities endpoint.

Required range: x >= 1

Response

Successful Response

Returned by the set_leverage endpoint.

If the asset is already at the requested leverage, typed_data/action/nonce are null. If not, they contain the EIP-712 payload the user must sign.

leverage_ok
boolean
required

True if leverage already matches the requested value, false if an update is needed

typed_data
Typed Data · object

EIP-712 typed data for wallet signing, or null if no change is needed

action
Action · object

Raw Hyperliquid action (passed back to the execute endpoint), or null

nonce
integer | null

Timestamp-based nonce, or null if no action needed