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

# private/logout

> Gracefully terminate the current WebSocket connection and optionally invalidate all tokens associated with the session.

This method provides a clean way to close WebSocket connections while preserving active orders when [**Cancel On Disconnect (COD)**](https://docs.deribit.com/api-reference/session-management/private-enable_cancel_on_disconnect) is enabled.

**Use Cases:**

- **Clean Shutdown:** Properly close WebSocket connections during application shutdown or restart
- **Order Preservation:** Close connections without triggering order cancellations when COD is enabled
- **Session Management:** Invalidate tokens to ensure security when closing connections
- **Maintenance Operations:** Temporarily disconnect for system maintenance without affecting trading positions

**Cancel On Disconnect (COD) Behavior:**

When Cancel On Disconnect is enabled for your connection, this method provides a safe way to close the connection without triggering automatic order cancellations. This is different from other disconnection scenarios:

- **Graceful logout** (this method): Orders are **NOT cancelled**, even if COD is enabled
- **Unexpected disconnection:** Orders are **cancelled** if COD is enabled
- **Inactivity timeout:** Orders are **cancelled** if COD is enabled
- **Heartbeat failure:** Orders are **cancelled** if COD is enabled

This distinction allows you to perform planned disconnections (e.g., for maintenance, updates, or reconnection) while preserving your active orders.

**WebSocket Only:**

This method is designed exclusively for WebSocket connections. Attempting to use it via REST/HTTP will result in a 400 error response.

**Token invalidation:** With `invalidate_token=true` (default) the current token is invalidated. With `false` it stays valid but remains subject to its scope, session and expiry: a `connection` scope token stays bound to the connection it was issued on and cannot be used on a new connection; use a `session` scope token (or authenticate again) to continue after reconnecting.

**Note:** This method has no response. The WebSocket connection is closed immediately after the request is processed.

[Try in API console](https://test.deribit.com/api_console?method=%2Fprivate%2Flogout)





## OpenAPI

````yaml /specifications/deribit_upcoming_openapi.json get /private/logout
openapi: 3.0.0
info:
  title: Deribit API
  version: 2.1.1
servers:
  - url: https://test.deribit.com/api/v2
security: []
tags:
  - name: WebSocket Only
    description: Can only be used over websockets.
  - name: Public
    description: Public methods can be used without authentication.
  - name: Private
    description: >-
      <p>Private methods require authentication. All requests must include a
      valid OAuth2 token.</p>

      <p>A token can be requested using the <a
      href="#public-auth">/public/auth</a> method.</p>

      <p>When using the websockets protocol, the token must be included as a
      parameter <code>access_token</code> in the message. When using REST (HTTP
      GET), the token may also be passed in the <code>Authorization</code>
      header.</p>
  - name: Authentication
  - name: Session Management
  - name: Subscription Management
    description: >-
      Subscription works as [notifications](#notifications), so users will
      automatically (after subscribing) receive messages from the server.
      Overview for each channel response format is described in
      [subscriptions](#subscriptions) section.
  - name: Account Management
  - name: Trading
  - name: Market Data
  - name: Wallet
  - name: Chat
  - name: lsp
    description: >-
      Methods and notifications for the Liquidity Support Program (LSP), the
      mechanism that assigns risk from liquidated positions to designated LSP
      participant subaccounts before falling back to auto-deleveraging (ADL).
paths:
  /private/logout:
    get:
      tags:
        - Authentication
        - WebSocket Only
        - Private
      description: >+
        Gracefully terminate the current WebSocket connection and optionally
        invalidate all tokens associated with the session.


        This method provides a clean way to close WebSocket connections while
        preserving active orders when [**Cancel On Disconnect
        (COD)**](https://docs.deribit.com/api-reference/session-management/private-enable_cancel_on_disconnect)
        is enabled.


        **Use Cases:**


        - **Clean Shutdown:** Properly close WebSocket connections during
        application shutdown or restart

        - **Order Preservation:** Close connections without triggering order
        cancellations when COD is enabled

        - **Session Management:** Invalidate tokens to ensure security when
        closing connections

        - **Maintenance Operations:** Temporarily disconnect for system
        maintenance without affecting trading positions


        **Cancel On Disconnect (COD) Behavior:**


        When Cancel On Disconnect is enabled for your connection, this method
        provides a safe way to close the connection without triggering automatic
        order cancellations. This is different from other disconnection
        scenarios:


        - **Graceful logout** (this method): Orders are **NOT cancelled**, even
        if COD is enabled

        - **Unexpected disconnection:** Orders are **cancelled** if COD is
        enabled

        - **Inactivity timeout:** Orders are **cancelled** if COD is enabled

        - **Heartbeat failure:** Orders are **cancelled** if COD is enabled


        This distinction allows you to perform planned disconnections (e.g., for
        maintenance, updates, or reconnection) while preserving your active
        orders.


        **WebSocket Only:**


        This method is designed exclusively for WebSocket connections.
        Attempting to use it via REST/HTTP will result in a 400 error response.


        **Token invalidation:** With `invalidate_token=true` (default) the
        current token is invalidated. With `false` it stays valid but remains
        subject to its scope, session and expiry: a `connection` scope token
        stays bound to the connection it was issued on and cannot be used on a
        new connection; use a `session` scope token (or authenticate again) to
        continue after reconnecting.


        **Note:** This method has no response. The WebSocket connection is
        closed immediately after the request is processed.


        [Try in API
        console](https://test.deribit.com/api_console?method=%2Fprivate%2Flogout)

      parameters:
        - name: invalidate_token
          in: query
          required: false
          schema:
            type: boolean
            default: true
          description: >-
            Whether to invalidate session tokens (default true). If false,
            tokens remain subject to their scope, session and expiry; a
            connection-scope token cannot be used on a new connection.
      requestBody:
        content:
          application/json:
            examples:
              request:
                summary: JSON-RPC Request Example
                value:
                  jsonrpc: '2.0'
                  id: 42
                  method: private/logout
                  params:
                    access_token: >-
                      1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP
                    invalidate_token: true
        description: JSON-RPC request body
      responses:
        '200':
          description: Connection closed

````

## Related topics

- [API Authentication with OAuth 2.0 and Signatures](https://docs.deribit.com/articles/authentication.md)
- [private/enable_cancel_on_disconnect](https://docs.deribit.com/api-reference/upcoming/session-management/private-enable_cancel_on_disconnect.md)
- [private/unsubscribe](https://docs.deribit.com/api-reference/upcoming/subscription-management/private-unsubscribe.md)
- [private/subscribe](https://docs.deribit.com/api-reference/upcoming/subscription-management/private-subscribe.md)
- [private/withdraw](https://docs.deribit.com/api-reference/upcoming/wallet/private-withdraw.md)
