nexustrader.exchange.okx.websockets

This module implements the WebSocket client for OKX exchange, providing both public and private data stream functionality.

Class Overview

WebSocket Subscriptions

Public Channels

nexustrader.exchange.okx.websockets.subscribe_order_book(symbol: str, channel: str)

Subscribe to order book updates.

Parameters:
  • symbol – Trading pair symbol

  • channel – Order book channel type (books, books5, bbo-tbt, etc.)

nexustrader.exchange.okx.websockets.subscribe_trade(symbol: str)

Subscribe to trade updates.

Parameters:

symbol – Trading pair symbol

nexustrader.exchange.okx.websockets.subscribe_candlesticks(symbol: str, interval: str)

Subscribe to candlestick data.

Parameters:
  • symbol – Trading pair symbol

  • interval – Time interval (1m, 3m, 5m, etc.)

Private Channels

nexustrader.exchange.okx.websockets.subscribe_account()

Subscribe to account updates.

nexustrader.exchange.okx.websockets.subscribe_positions(inst_type: str = 'ANY')

Subscribe to position updates.

Parameters:

inst_type – Instrument type (MARGIN, SWAP, FUTURES, etc.)

nexustrader.exchange.okx.websockets.subscribe_orders(inst_type: str = 'ANY')

Subscribe to order updates.

Parameters:

inst_type – Instrument type

Authentication

The client supports API key authentication with:

  • API Key

  • Secret Key

  • Passphrase

  • Automatic authentication renewal

  • Support for demo/live environments