bothan_okx/api/types/
ticker.rs

1//! Types for OKX ticker data interaction.
2//!
3//! This module provides types for deserializing ticker data from the OKX WebSocket API,
4//! including request structures and ticker information. The module supports the OKX v5
5//! API format for real-time market data streaming.
6//!
7//! # Key Types
8//!
9//! - [`Request`] - Ticker subscription request structure
10//! - [`Ticker`] - Ticker data received from the API
11//! - [`InstrumentType`] - Supported instrument types
12
13use serde::{Deserialize, Serialize};
14
15/// Represents the arguments for a ticker subscription request.
16///
17/// This struct defines the parameters needed to subscribe to ticker updates
18/// from the OKX WebSocket API. It follows the OKX v5 API specification for
19/// channel subscriptions.
20#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
21#[serde(rename_all = "camelCase")]
22pub struct Request {
23    /// The name of the channel to subscribe to (e.g., "tickers").
24    pub channel: String,
25
26    /// The type of instrument (e.g., Spot).
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub inst_type: Option<InstrumentType>,
29
30    /// The instrument family (optional).
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub inst_family: Option<String>,
33
34    /// The instrument ID (e.g., "BTC-USDT").
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub inst_id: Option<String>,
37}
38
39/// Represents ticker data received from the OKX WebSocket API.
40///
41/// This struct contains comprehensive market data information including price,
42/// volume, and 24-hour statistics for a specific trading instrument.
43#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
44#[serde(rename_all = "camelCase")]
45pub struct Ticker {
46    /// The instrument type (e.g., "SPOT", "FUTURES").
47    pub inst_type: String,
48
49    /// The instrument ID (e.g., "BTC-USDT").
50    pub inst_id: String,
51
52    /// The last traded price.
53    pub last: String,
54
55    /// The size of the last trade.
56    pub last_sz: String,
57
58    /// The current best ask price.
59    pub ask_px: String,
60
61    /// The current best ask size.
62    pub ask_sz: String,
63
64    /// The current best bid price.
65    pub bid_px: String,
66
67    /// The current best bid size.
68    pub bid_sz: String,
69
70    /// The opening price from 24 hours ago.
71    pub open_24h: String,
72
73    /// The highest price in the last 24 hours.
74    pub high_24h: String,
75
76    /// The lowest price in the last 24 hours.
77    pub low_24h: String,
78
79    /// The 24-hour volume in quote currency.
80    pub vol_ccy_24h: String,
81
82    /// The 24-hour volume in base currency.
83    pub vol_24h: String,
84
85    /// The start of day price in UTC+0.
86    pub sod_utc0: String,
87
88    /// The start of day price in UTC+8.
89    pub sod_utc8: String,
90
91    /// The timestamp of the data in milliseconds.
92    pub ts: String,
93}
94
95/// Represents the supported instrument types for OKX.
96///
97/// This enum defines the different types of instruments that can be parsed
98/// from the OKX platform. Currently, only spot is supported.
99#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
100#[serde(rename_all = "UPPERCASE")]
101pub enum InstrumentType {
102    /// Spot instruments.
103    Spot,
104}