Build update-margin payload
Execution
Build Update-Margin Payload
Build a signed canonical payload to add or remove collateral from an open perpetual position (Lighter) or change its per-trade leverage (Gains).
POST
Build update-margin payload
Adjusts margin on an open position. The exact semantics depend on the DEX:
- Lighter — supply
usdcAmountandincreaseto add or remove USDC collateral on the market’s position. - Gains — supply
newLeverageto change the trade’s leverage, which effectively adjusts its collateral.
Request Body
string
required
gains or lighter.string
required
Chain of the position.
string
Mobula market identifier.
string
Gains trade index. Required for Gains.
number
Lighter only. USDC amount to add or remove (> 0).
boolean
Lighter only.
true to add margin, false to remove it.number
Gains only. New per-trade leverage (> 0).
Authentication
Every/2/perp/payloads/<action> endpoint verifies the caller by requiring two extra fields in the request body alongside the action parameters:
number
required
Unix timestamp in milliseconds. Must be within 30 seconds of server time. Older timestamps are rejected to prevent replay.
string
required
Hex signature (EIP-191
personal_sign) of the message `${endpoint}-${timestamp}`, where endpoint is the path of this endpoint without the leading slash (e.g., for this page: api/2/perp/payloads/<this-action>). The recovered signer address becomes the user for the request. Single-use — replay returns 403 signature already used.Authentication errors
Response envelope
Every/2/perp/payloads/<action> endpoint returns the same envelope shape. You pass these fields verbatim into POST /2/perp/execute-v2 to execute the action.
Top-level shape. Successful (2xx) responses return
{ data: { ... } }. A success: true flag is only present inside the body of execute-v2’s response, not on the payload-build endpoints. Parse defensively: read body.data, then check for the action-specific fields you need (e.g. data.payloadStr).object
Endpoint-specific errors
Full flow — update margin end-to-end
Single example covering both DEXes (Lighter offchain-api withusdcAmount+increase, Gains evm-tx with newLeverage). The flow branches on data.transport.
Body
application/json
Available options:
gains, lighter Gains trade index. Required for Gains.
Lighter only. USDC amount to add or remove (> 0).
Lighter only. true = add margin, false = remove.
Gains only. New per-trade leverage (> 0).