Adjusts margin on an open position. The exact semantics depend on the DEX:
- Lighter — supply
usdcAmount and increase to add or remove USDC collateral on the market’s position.
- Gains — supply
newLeverage to change the trade’s leverage, which effectively adjusts its collateral.
Request Body
Mobula market identifier.
Gains trade index. Required for Gains.
Lighter only. USDC amount to add or remove (> 0).
Lighter only. true to add margin, false to remove it.
Gains only. New per-trade leverage (> 0).
Endpoint-specific errors
| Status | message |
|---|
| 400 | update-margin payload action failed — missing position, wrong leg supplied for the DEX, or DEX refusal |
Example — Lighter add 50 USDC margin
const endpoint = 'api/2/perp/payloads/update-margin';
const timestamp = Date.now();
const signature = await wallet.signMessage(`${endpoint}-${timestamp}`);
const res = await fetch(`https://api.mobula.io/${endpoint}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
timestamp,
signature,
dex: 'lighter',
chainId: 'lighter:301',
marketId: 'lighter-btc-usd',
usdcAmount: 50,
increase: true,
}),
}).then(r => r.json());
Example — Gains lower leverage on a trade
const res = await fetch('https://api.mobula.io/api/2/perp/payloads/update-margin', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
timestamp, signature,
dex: 'gains',
chainId: 'evm:42161',
marketId: 'gains-btc-usd',
positionId: '12345',
newLeverage: 5,
}),
}).then(r => r.json());