pyokx.websocket_handling
This module handles the real-time interaction with the OKX exchange Websocket APIs. It subscribes to various data streams including public, business, and private channels, processes the incoming data, and optionally stores the data in a Redis stream for further analysis or decision-making. The main function okx_websockets_main_run initializes the websocket connections, handles message receipt, and maintains a heartbeat to keep the connections alive.
- async pyokx.websocket_handling.okx_websockets_main_run(input_channel_models: list, apikey: str | None = None, passphrase: str | None = None, secretkey: str | None = None, sandbox_mode: bool = True, redis_store: bool = True)[source]
Initializes and manages websocket connections to the OKX exchange. It subscribes to the specified channels, processes incoming messages, and optionally stores structured data in a Redis stream.
- Parameters:
input_channel_models (list) – A list of channel input arguments specifying the channels to subscribe.
apikey (str, optional) – The API key for accessing private channels.
passphrase (str, optional) – The passphrase associated with the API key.
secretkey (str, optional) – The secret key for accessing private channels.
sandbox_mode (bool, optional) – If True, use the sandbox environment. Defaults to True.
redis_store (bool, optional) – If True, store the received messages in a Redis stream. Defaults to True.
- Raises:
Exception – If no channels are provided or if an invalid channel is specified.