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

# Update Margin Mode

> This endpoint updates the margin mode for a given market.

Use this endpoint only when the market has **no open position and no open orders**. Close the position and cancel any open orders for the market before changing its margin mode.


## OpenAPI

````yaml POST /api/v1/update-margin-mode
openapi: 3.1.0
info:
  title: Order API
  version: 1.0.0
servers:
  - url: https://order.sandbox.rails.xyz
security: []
paths:
  /api/v1/update-margin-mode:
    post:
      summary: Update Margin Mode
      operationId: updateMarginMode
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                market:
                  type: string
                  description: >-
                    Market name. Example value: `BTC-USDT`. To get all supported
                    markets, call
                    [/api/v1/markets](/latest/perps/rest-api/get-supported-markets)
                    endpoint.
                marginMode:
                  type: string
                  enum:
                    - C
                    - I
                  description: >-
                    Margin mode to set for the market. `C` for cross margin, `I`
                    for isolated margin. Defaults to `C` if this endpoint is
                    never called for the market.
              required:
                - market
                - marginMode
            example:
              market: BTC-USDT
              marginMode: C
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: >-
                      A message describing the result of the update margin mode
                      operation.
                required:
                  - message
              example:
                message: margin mode updated successfully
        '400':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  body:
                    type: string
                    description: A message describing the error.
                  statusCode:
                    type: integer
                    description: HTTP status code.
                required:
                  - body
                  - statusCode
              example:
                body: invalid market
                statusCode: 400
        '401':
          $ref: '#/components/responses/Unauthorized'
      security:
        - bearerAuth: []
components:
  responses:
    Unauthorized:
      description: ''
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: A human-readable message describing the error.
            required:
              - message
          example:
            message: Unauthorized
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````