---
title: "private/get_margin"
method: POST
path: "/private/get_margin"
tags: ["Subaccounts"]
---

# private/get_margin

`POST /private/get_margin`

## Request

- Base URL: `https://api.derive.xyz/v3`
- URL: `https://api.derive.xyz/v3/private/get_margin`
- Auth: API key in header `X-DeriveWallet` and API key in header `X-DeriveTimestamp` and API key in header `X-DeriveSignature`

Calculates net initial and maintenance margin for a subaccount before and after an optional simulated state change (position and/or collateral deltas), and whether that change would pass the margin requirement. Values are net margin — mark-to-market value minus the requirement — so positive means healthy. Does not take open-order margin into account. Margins use the subaccount's manager's params. Set is_delayed_liquidation to use its delayed-liquidation override instead, as order checks do; the request is rejected for a subaccount without one.

## Request body

- PrivateGetMarginRequest
  - `is_delayed_liquidation` boolean: `true` margins under the subaccount's delayed-liquidation override, as order checks do. Rejected for a subaccount without one.
  - `simulated_collateral_changes` SimulatedCollateralRequest[], nullable: Optional collateral deltas to simulate deposits / withdrawals / spot trades.
    - `amount` string, decimal, required: Collateral amount to simulate, as a decimal string or JSON number.
    - `asset_name` string, required: Collateral ERC20 asset name (e.g. ETH, USDC, WSTETH).
  - `simulated_position_changes` SimulatedPositionRequest[], nullable: Optional position deltas to simulate perp / option trades.
    - `amount` string, decimal, required: Position amount to simulate, as a decimal string or JSON number.
    - `entry_price` string, decimal, nullable: Perps only: entry price to simulate against; mark price when omitted.
    - `instrument_name` string, required: Perp or option instrument name.
  - `subaccount_id` integer, required

## Response `200`

Success

- GetMarginResponse: Result of `public/get_margin` / `private/get_margin`: net margin (MtM minus requirement; positive = healthy) before and after the simulated changes, as USD decimal strings.
  - `is_valid_trade` boolean, required: `true` when post-change initial margin passes, or the change is risk-reducing while maintenance margin stays healthy.
  - `post_initial_margin` string, required
  - `post_maintenance_margin` string, required
  - `pre_initial_margin` string, required
  - `pre_maintenance_margin` string, required
  - `subaccount_id` integer, required: `0` for the public simulated-portfolio variant.

## Other responses

- `default`: JSON-RPC error (see Error Codes)

## Changes

- **2026-10-20** `0c500202be49`: 2 info
  - the endpoint scheme security `DeriveWallet AND DeriveTimestamp AND DeriveSignature` was added to the API
  - added the media type `application/json` for the response with the status `default`

[Operation history](https://skmtc.dev/lyra/apis/derive-v3-api/changes/private/get_margin/post.md)

---

[API](https://skmtc.dev/lyra/apis/derive-v3-api.md) - [All operations](https://skmtc.dev/lyra/apis/derive-v3-api/llms.txt) - [OpenAPI document](https://skmtc.dev/lyra/apis/derive-v3-api/revisions/415f8a73b10c?raw)
