> ## Documentation Index
> Fetch the complete documentation index at: https://docs.derive.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# private/get_margin

> 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.



## OpenAPI

````yaml /openapi.json post /private/get_margin
openapi: 3.1.0
info:
  title: Derive v3 API
  version: 0.2.0
  description: JSON-RPC 2.0 methods, served over WebSocket and HTTP POST.
servers:
  - url: https://api.derive.xyz/v3
    description: Production (HTTP POST base)
  - url: https://testnet.api.derive.xyz/v3
    description: Testnet (HTTP POST base)
security: []
tags:
  - name: Subaccounts
    description: >-
      List, inspect, and label subaccounts, portfolios, positions, and
      collateral.
  - name: Session Keys
    description: Register, edit, and list delegated signing keys.
  - name: Account
    description: Wallet-level account information and settings.
  - name: Orderbook
    description: Place, replace, cancel, and query orders, trigger orders, and algos.
  - name: RFQ
    description: 'Request-for-quote: send RFQs, quote, and execute block trades.'
  - name: Vault Shareholders
    description: >-
      Deposit into and withdraw from vaults, and track shares, requests, and
      performance.
  - name: Vault Curators
    description: >-
      Create and operate curated vaults: settle deposit and withdrawal requests,
      and manage vault metadata.
  - name: History
    description: >-
      Per-account historical records: orders, trades, transfers, and
      settlements.
  - name: Market Maker Protection
    description: Configure, read, and reset market-maker protection.
  - name: Transfers & Withdrawals
    description: Move collateral between subaccounts, to other wallets, and on-chain.
  - name: Onchain Actions
    description: >-
      L1 onchain actions submitted via OnchainActionManager: register deposit
      addresses, list pending deposits, and inspect onchain action history.
  - name: System
    description: Rate limits and transaction lookups.
  - name: Market Data
    description: Instruments, currencies, tickers, and market-wide feeds.
  - name: Referrals
    description: Referral codes and program performance.
  - name: Other
    description: Uncategorized.
paths:
  /private/get_margin:
    post:
      tags:
        - Subaccounts
      summary: private/get_margin
      description: >-
        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.
      operationId: private_get_margin
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PrivateGetMarginRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetMarginResponse'
        default:
          description: JSON-RPC error (see Error Codes)
components:
  schemas:
    PrivateGetMarginRequest:
      type: object
      required:
        - subaccount_id
      properties:
        simulated_collateral_changes:
          description: >-
            Optional collateral deltas to simulate deposits / withdrawals / spot
            trades.
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/SimulatedCollateralRequest'
        simulated_position_changes:
          description: Optional position deltas to simulate perp / option trades.
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/SimulatedPositionRequest'
        subaccount_id:
          type: integer
          format: uint64
          minimum: 0
      additionalProperties: false
    GetMarginResponse:
      description: >-
        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.
      type: object
      required:
        - is_valid_trade
        - post_initial_margin
        - post_maintenance_margin
        - pre_initial_margin
        - pre_maintenance_margin
        - subaccount_id
      properties:
        is_valid_trade:
          description: >-
            `true` when post-change initial margin passes, or the change is
            risk-reducing while maintenance margin stays healthy.
          type: boolean
        post_initial_margin:
          type: string
        post_maintenance_margin:
          type: string
        pre_initial_margin:
          type: string
        pre_maintenance_margin:
          type: string
        subaccount_id:
          description: '`0` for the public simulated-portfolio variant.'
          type: integer
          format: uint64
          minimum: 0
    SimulatedCollateralRequest:
      type: object
      required:
        - amount
        - asset_name
      properties:
        amount:
          description: Collateral amount to simulate, as a decimal string or JSON number.
          type: string
          format: decimal
        asset_name:
          description: Collateral ERC20 asset name (e.g. ETH, USDC, WSTETH).
          type: string
      additionalProperties: false
    SimulatedPositionRequest:
      type: object
      required:
        - amount
        - instrument_name
      properties:
        amount:
          description: Position amount to simulate, as a decimal string or JSON number.
          type: string
          format: decimal
        entry_price:
          description: >-
            Perps only: entry price to simulate against; mark price when
            omitted.
          default: null
          type:
            - string
            - 'null'
          format: decimal
        instrument_name:
          description: Perp or option instrument name.
          type: string
      additionalProperties: false

````

## Related topics

- [Coming soon](/migrating/coming-soon.md)
- [private/get_subaccount](/api-reference/subaccounts/privateget_subaccount.md)
- [public/get_margin](/api-reference/subaccounts/publicget_margin.md)
