from compass_api_sdk import CompassAPI
with CompassAPI(
api_key_auth="<YOUR_API_KEY_HERE>",
) as compass_api:
res = compass_api.perpetual_trading.perpetual_trading_ensure_leverage(owner="<value>", asset="<value>")
# Handle response
print(res)import { CompassApiSDK } from "@compass-labs/api-sdk";
const compassApiSDK = new CompassApiSDK({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await compassApiSDK.perpetualTrading.perpetualTradingEnsureLeverage({
owner: "<value>",
asset: "<value>",
});
console.log(result);
}
run();curl --request POST \
--url https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"owner": "<string>",
"asset": "<string>"
}
'const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({owner: '<string>', asset: '<string>'})
};
fetch('https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'owner' => '<string>',
'asset' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage"
payload := strings.NewReader("{\n \"owner\": \"<string>\",\n \"asset\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"owner\": \"<string>\",\n \"asset\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"owner\": \"<string>\",\n \"asset\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"action": {
"asset": 12,
"isCross": true,
"leverage": 1,
"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"
}
]
}
}
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Ensure 1x cross leverage
Check leverage and prepare an updateLeverage action if not 1x cross.
If the asset is already at 1x cross leverage, returns leverage_ok=true with null typed_data — no signing needed. Otherwise, returns EIP-712 typed data for the user to sign. After signing, submit the signature via the /execute endpoint.
from compass_api_sdk import CompassAPI
with CompassAPI(
api_key_auth="<YOUR_API_KEY_HERE>",
) as compass_api:
res = compass_api.perpetual_trading.perpetual_trading_ensure_leverage(owner="<value>", asset="<value>")
# Handle response
print(res)import { CompassApiSDK } from "@compass-labs/api-sdk";
const compassApiSDK = new CompassApiSDK({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await compassApiSDK.perpetualTrading.perpetualTradingEnsureLeverage({
owner: "<value>",
asset: "<value>",
});
console.log(result);
}
run();curl --request POST \
--url https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"owner": "<string>",
"asset": "<string>"
}
'const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({owner: '<string>', asset: '<string>'})
};
fetch('https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'owner' => '<string>',
'asset' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage"
payload := strings.NewReader("{\n \"owner\": \"<string>\",\n \"asset\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"owner\": \"<string>\",\n \"asset\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.compasslabs.ai/v2/perpetual_trading/ensure_leverage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"owner\": \"<string>\",\n \"asset\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"action": {
"asset": 12,
"isCross": true,
"leverage": 1,
"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"
}
]
}
}
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Body
Response
Successful Response
Returned by the ensure_leverage endpoint.
If the asset is already at 1x cross leverage, typed_data/action/nonce are null. If not (or no position exists), they contain the EIP-712 payload the user must sign.
True if leverage is already 1x cross, false if update needed
EIP-712 typed data for wallet signing, or null if already 1x cross
Raw Hyperliquid action (passed back to the execute endpoint), or null
Timestamp-based nonce, or null if no action needed
Was this page helpful?