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

# Post apiv1marginsub accounts close

> Close a sub-account. Refused unless it is flat: no position and no order,
 conditional order or TWAP. Its flat, solvent risk buckets close in the
 same step, and all of its remaining collateral moves to the default
 margin account. A risk bucket in liquidation or bad debt refuses the
 close, and nothing moves.



## OpenAPI

````yaml /proto-openapi/api/openapi.yaml post /api/v1/margin/sub-accounts/{marginAccountId}/close
openapi: 3.0.3
info:
  title: Monaco Protocol API
  description: REST API for the Monaco Protocol hybrid CLOB exchange.
  version: 1.0.0
servers:
  - url: https://staging.apimonaco.xyz
    description: Staging server (Testnet)
security: []
tags:
  - name: AccountsService
  - name: ApplicationsService
  - name: AuthService
  - name: BuildercodeRewardsService
  - name: CopyTradingService
  - name: DelegatedAgentsService
  - name: FaucetService
  - name: FeesService
  - name: HealthService
  - name: ManagedMarketsService
    description: |-
      Wallet-authenticated maker assignments. The signed session must match both
       configured maker user and application. Owner IDs are process fences, never auth.
       Only wallet sessions are supported; delegated-agent sessions receive 403.
  - name: MarginAccountsService
    description: |-
      Current public isolated-margin semantics:
       - a user has one parent margin account per application scope
       - opening orders create or reuse isolated position buckets under that parent
       - parent account creation is handled internally by margin workflows
  - name: MarketService
  - name: OrderbookService
  - name: OrdersService
  - name: PositionsService
    description: |-
      Current public isolated-margin semantics:
       - positions link to a parent margin account and, when applicable, a bucket id
       - opening orders create or reuse isolated position buckets under the parent
       - users can open another isolated position by reusing the parent account with a different market bucket
  - name: PulseService
  - name: SweeperService
  - name: TraderCodeService
  - name: TradesService
  - name: WhitelistService
  - name: WithdrawalsService
paths:
  /api/v1/margin/sub-accounts/{marginAccountId}/close:
    post:
      tags:
        - MarginAccountsService
      description: >-
        Close a sub-account. Refused unless it is flat: no position and no
        order,
         conditional order or TWAP. Its flat, solvent risk buckets close in the
         same step, and all of its remaining collateral moves to the default
         margin account. A risk bucket in liquidation or bad debt refuses the
         close, and nothing moves.
      operationId: close_sub_account
      parameters:
        - name: marginAccountId
          in: path
          required: true
          schema:
            type: string
            default: 2b1a5f9c-0000-4000-8000-000000000001
          example: 2b1a5f9c-0000-4000-8000-000000000001
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CloseSubAccountRequest'
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CloseSubAccountResponse'
        '429':
          description: >-
            Movement rate limit exceeded — withdrawals and collateral transfers
            share a per-user budget; retry after the interval in
            details.retryAfter
      security:
        - monacoSignature: []
        - monacoHttpSignature: []
components:
  schemas:
    CloseSubAccountRequest:
      type: object
      properties:
        marginAccountId:
          type: string
          nullable: true
    CloseSubAccountResponse:
      type: object
      properties:
        marginAccountId:
          type: string
          nullable: true
        defaultMarginAccountId:
          type: string
          description: The default margin account that received the remaining collateral.
          nullable: true
        amount:
          type: string
          description: Collateral moved to the default margin account.
          nullable: true
  securitySchemes:
    monacoSignature:
      type: apiKey
      description: >-
        Ed25519 session-key request signing. Every authenticated request carries
        three headers: `X-Monaco-PublicKey` (64-char lowercase-hex session
        public key), `X-Monaco-Timestamp` (Unix milliseconds, within 30s of
        server time), and `X-Monaco-Signature` (hex ed25519 signature). The
        signature is over `METHOD\npath?query\ntimestamp_ms\nSHA256_hex(body)`,
        where the body hash is the SHA-256 of the empty byte string when there
        is no body. Obtain the session keypair from `POST
        /api/v1/auth/challenge` followed by `POST /api/v1/auth/verify`.
      name: X-Monaco-Signature
      in: header
    monacoHttpSignature:
      type: apiKey
      description: >-
        RFC 9421 Ed25519 session-key request signatures. Send Signature-Input,
        Signature, and Content-Digest together; never combine them with
        X-Monaco-* credentials. The monaco signature covers @method, @path,
        @query, and content-digest in that order, with created (Unix seconds
        within 30s of server time), keyid (registered lowercase-hex session
        public key), and alg=ed25519 parameters. Content-Digest uses RFC 9530
        sha-256 over the exact body bytes, including the empty body. Query
        coverage retains ordering and percent encoding. Timestamp freshness does
        not reject repeated identical requests; use endpoint idempotency where
        supported. Existing legacy signing remains supported during server-first
        migration; SDK RFC 9421 signing is opt-in. See
        https://docs.0xmonaco.com/reference/http-message-signatures for the
        complete profile and trust model.
      name: Signature
      in: header

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.