Skip to content
Docs
Open Legend

About

AboutGetting startedWhat is Legend?Why are we building this?Who is this for?

Platform

Web appiOSAndroidTelegram

Trading

TradingOrder typesDeposits and withdrawalsRanks

Capital

Legend CapitalCapital Affiliate Rewards

Autocopy

Copy tradingAutocopyLimits and safeguards

Social

SocialActivityFeedClansChat

Rewards

Referrals and rewards

API reference

Trading APIAuthentication and API keysAPI key actionsOrdersAccount, positions, and fillsLeverage, margin, and TWAPsRate limitsErrors and idempotency

Legend Research

Connect Legend to an AI assistantConnector permissionsMCP tools and order review

Fees

Fees

Support

FAQ
Trade onLEGEND

Trade where legends are made.

Download on theApp StoreGet it onGoogle Play
Product
TradeMobile app
Resources
BlogLearnFAQDocsCareers
© 2026 Legend. All rights reserved.
Privacy policyTerms of service
Ctrl K

Legend documentation

Leverage, margin, and TWAPs

Request parameters and responses for leverage, margin, and twaps.

View Markdown ↗
Account, positions, and fillsPreviousRate limitsNext

All paths are relative to the base URL. See authentication and errors and idempotency.

Native Hyperliquid TWAPs do not support a builder-fee parameter and do not charge Legend’s builder fee. Hyperliquid trading fees still apply.

These actions require perpetual markets. Positive isolated-margin amounts add margin; negative amounts remove it. Margin amounts use USDC decimal strings with at most six decimal places. TWAP duration follows the exchange’s 5–10,080 minute range. A command returns an operation UUID; TWAP creation also returns its native ID in exchange_id.

Set leverage and margin type

POST /v1/leverage

Requires trading:write and Idempotency-Key.

Parameters

NameLocationRequiredType
Idempotency-KeyheaderYesstring

Request body

FieldTypeRequiredDetails
marketstringYesMax length: 100
leverageintegerYesMaximum: 9007199254740991
margin_typestringYescross, isolated
{
  "market": "BTC",
  "leverage": 3,
  "margin_type": "cross"
}

Example request

curl -X POST "$LEGEND_API_BASE/v1/leverage" \
  -H "Authorization: Bearer $LEGEND_API_KEY" \
  -H "Idempotency-Key: UNIQUE_ACTION_KEY" \
  -H "Content-Type: application/json" \
  --data '{"market":"BTC","leverage":3,"margin_type":"cross"}'

Response

FieldTypeRequiredDetails
idstringYesFormat: uuid
objectstringYesoperation
accountstringYesFormat: uuid
actionstringYes
statusstringYesprocessing, succeeded, rejected, unknown
exchange_idstring or nullYes
errorstring or nullYes

See the OpenAPI schema for nested response objects and validation patterns.

Illustrative successful response:

{
  "id": "00000000-0000-4000-8000-000000000002",
  "object": "operation",
  "account": "00000000-0000-4000-8000-000000000001",
  "action": "leverage",
  "status": "succeeded",
  "exchange_id": null,
  "error": null
}

Add or remove isolated margin

POST /v1/margin

Requires trading:write and Idempotency-Key.

Hyperliquid checks the remaining margin before accepting a negative amount. Remaining margin must satisfy the initial-margin requirement and be at least 10% of the position’s notional value. Adding margin does not necessarily make that same amount immediately removable. Strict-isolated markets do not allow margin removal. See Hyperliquid’s margining rules.

Check the returned operation’s status and error: a venue rejection returns status: "rejected", even when the HTTP request succeeds.

Parameters

NameLocationRequiredType
Idempotency-KeyheaderYesstring

Request body

FieldTypeRequiredDetails
marketstringYesMax length: 100
amountstringYes
{
  "market": "BTC",
  "amount": "10"
}

Example request

curl -X POST "$LEGEND_API_BASE/v1/margin" \
  -H "Authorization: Bearer $LEGEND_API_KEY" \
  -H "Idempotency-Key: UNIQUE_ACTION_KEY" \
  -H "Content-Type: application/json" \
  --data '{"market":"BTC","amount":"10"}'

Response

FieldTypeRequiredDetails
idstringYesFormat: uuid
objectstringYesoperation
accountstringYesFormat: uuid
actionstringYes
statusstringYesprocessing, succeeded, rejected, unknown
exchange_idstring or nullYes
errorstring or nullYes

See the OpenAPI schema for nested response objects and validation patterns.

Illustrative successful response:

{
  "id": "00000000-0000-4000-8000-000000000002",
  "object": "operation",
  "account": "00000000-0000-4000-8000-000000000001",
  "action": "isolated_margin",
  "status": "succeeded",
  "exchange_id": null,
  "error": null
}

Create a native Hyperliquid TWAP

POST /v1/twaps

Requires trading:write and Idempotency-Key.

Parameters

NameLocationRequiredType
Idempotency-KeyheaderYesstring

Request body

FieldTypeRequiredDetails
marketstringYesMax length: 100
sidestringYesbuy, sell
sizestringYesMax length: 40
duration_minutesintegerYesMinimum: 5; Maximum: 10080
randomizebooleanNoDefault: false
reduce_onlybooleanNoDefault: false
{
  "market": "BTC",
  "side": "buy",
  "size": "0.001",
  "duration_minutes": 5,
  "randomize": false,
  "reduce_only": false
}

Example request

curl -X POST "$LEGEND_API_BASE/v1/twaps" \
  -H "Authorization: Bearer $LEGEND_API_KEY" \
  -H "Idempotency-Key: UNIQUE_ACTION_KEY" \
  -H "Content-Type: application/json" \
  --data '{"market":"BTC","side":"buy","size":"0.001","duration_minutes":5,"randomize":false,"reduce_only":false}'

Response

FieldTypeRequiredDetails
idstringYesFormat: uuid
objectstringYesoperation
accountstringYesFormat: uuid
actionstringYes
statusstringYesprocessing, succeeded, rejected, unknown
exchange_idstring or nullYes
errorstring or nullYes

See the OpenAPI schema for nested response objects and validation patterns.

Illustrative successful response:

{
  "id": "00000000-0000-4000-8000-000000000002",
  "object": "operation",
  "account": "00000000-0000-4000-8000-000000000001",
  "action": "twap",
  "status": "succeeded",
  "exchange_id": "123",
  "error": null
}

Cancel a native Hyperliquid TWAP

POST /v1/twaps/cancel

Requires trading:write and Idempotency-Key.

Parameters

NameLocationRequiredType
Idempotency-KeyheaderYesstring

Request body

FieldTypeRequiredDetails
marketstringYesMax length: 100
twap_idintegerYesMinimum: 0; Maximum: 9007199254740991
{
  "market": "BTC",
  "twap_id": 123
}

Example request

curl -X POST "$LEGEND_API_BASE/v1/twaps/cancel" \
  -H "Authorization: Bearer $LEGEND_API_KEY" \
  -H "Idempotency-Key: UNIQUE_ACTION_KEY" \
  -H "Content-Type: application/json" \
  --data '{"market":"BTC","twap_id":123}'

Response

FieldTypeRequiredDetails
idstringYesFormat: uuid
objectstringYesoperation
accountstringYesFormat: uuid
actionstringYes
statusstringYesprocessing, succeeded, rejected, unknown
exchange_idstring or nullYes
errorstring or nullYes

See the OpenAPI schema for nested response objects and validation patterns.

Illustrative successful response:

{
  "id": "00000000-0000-4000-8000-000000000002",
  "object": "operation",
  "account": "00000000-0000-4000-8000-000000000001",
  "action": "twap_cancel",
  "status": "succeeded",
  "exchange_id": null,
  "error": null
}

Retrieve an action result

GET /v1/operations/{id}

Requires trading:read.

Parameters

NameLocationRequiredType
idpathYesstring

Example request

curl "$LEGEND_API_BASE/v1/operations/ORDER_OR_OPERATION_ID" \
  -H "Authorization: Bearer $LEGEND_API_KEY"

Response

FieldTypeRequiredDetails
idstringYesFormat: uuid
objectstringYesoperation
accountstringYesFormat: uuid
actionstringYes
statusstringYesprocessing, succeeded, rejected, unknown
exchange_idstring or nullYes
errorstring or nullYes

See the OpenAPI schema for nested response objects and validation patterns.

Illustrative successful response:

{
  "id": "00000000-0000-4000-8000-000000000002",
  "object": "operation",
  "account": "00000000-0000-4000-8000-000000000001",
  "action": "leverage",
  "status": "succeeded",
  "exchange_id": null,
  "error": null
}