bothan_okx/api/types.rs
1//! Types for OKX WebSocket API interaction.
2//!
3//! This module provides types for deserializing events and responses from the OKX WebSocket API,
4//! including subscription responses, data updates, and ping messages. The module supports
5//! the OKX WebSocket v5 API format for real-time market data streaming.
6//!
7//! # Key Types
8//!
9//! - [`Response`] - Main response enum for all OKX WebSocket messages
10//! - [`DEFAULT_URL`] - Default WebSocket endpoint for OKX API
11
12pub use channel::{ChannelArgument, PushData};
13use serde::{Deserialize, Serialize};
14
15use crate::api::types::ticker::Ticker;
16
17pub mod channel;
18pub mod subscription;
19pub mod ticker;
20
21/// The default URL for the OKX WebSocket API.
22pub const DEFAULT_URL: &str = "wss://ws.okx.com:8443/ws/v5/public";
23
24/// Represents the different types of responses from the OKX WebSocket API.
25///
26/// The `Response` enum can represent various types of messages from the OKX WebSocket API,
27/// including subscription confirmations, ticker data updates, and ping messages.
28/// Each variant corresponds to a specific type of message, allowing for flexible handling
29/// of various response types.
30#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
31#[serde(rename_all = "camelCase", untagged)]
32pub enum Response {
33 /// A response from a WebSocket subscription message.
34 ///
35 /// This variant contains subscription-related responses from the OKX API,
36 /// including subscription confirmations and error messages.
37 TickerSubscription(subscription::Response<ticker::Request>),
38
39 /// A response containing data from a subscribed channel.
40 ///
41 /// This variant contains actual market data updates from subscribed channels,
42 /// such as ticker information for trading pairs.
43 TickersChannel(PushData<Vec<Ticker>>),
44
45 /// A ping message for connection keep-alive.
46 ///
47 /// This variant represents ping messages sent by the OKX API to maintain
48 /// the WebSocket connection.
49 Ping,
50}