Skip to main content

bybit/models/
kline_data.rs

1use crate::prelude::*;
2
3/// Represents a single k-line (candlestick) data point.
4///
5/// This struct contains the price, volume, and time data for a single candlestick, used for technical analysis in trading bots.
6///
7/// # Bybit API Reference
8/// Part of the k-line WebSocket stream (https://bybit-exchange.github.io/docs/v5/websocket/public/kline).
9///
10/// # Perpetual Futures Context
11/// Candlestick data is critical for strategies like moving averages, RSI, or Bollinger Bands. Bots rely on this data to make real-time trading decisions.
12#[derive(Serialize, Deserialize, Debug, Clone)]
13pub struct KlineData {
14    /// The start time of the candlestick (in milliseconds).
15    ///
16    /// Marks the beginning of the k-line interval. Bots use this to align candlesticks with other time-based data.
17    pub start: u64,
18
19    /// The end time of the candlestick (in milliseconds).
20    ///
21    /// Marks the end of the k-line interval. Bots verify this to ensure data continuity.
22    pub end: u64,
23
24    /// The time interval of the candlestick (e.g., "1m", "1h").
25    ///
26    /// Specifies the timeframe (e.g., 1 minute, 1 hour). Bots select intervals based on strategy requirements (e.g., short-term vs. long-term trading).
27    pub interval: String,
28
29    /// The opening price of the candlestick.
30    ///
31    /// The price at the start of the interval. Bots use this for calculating price changes and patterns.
32    #[serde(with = "string_to_float")]
33    pub open: f64,
34
35    /// The closing price of the candlestick.
36    ///
37    /// The price at the end of the interval. Critical for determining candlestick direction (bullish or bearish).
38    #[serde(with = "string_to_float")]
39    pub close: f64,
40
41    /// The highest price during the interval.
42    ///
43    /// Used to identify resistance levels or breakout points in technical analysis.
44    #[serde(with = "string_to_float")]
45    pub high: f64,
46
47    /// The lowest price during the interval.
48    ///
49    /// Used to identify support levels or reversal points.
50    #[serde(with = "string_to_float")]
51    pub low: f64,
52
53    /// The trading volume during the interval (in base currency).
54    ///
55    /// Indicates market activity. High volume on price movements can confirm trends for bots.
56    #[serde(with = "string_to_float")]
57    pub volume: f64,
58
59    /// The turnover (value of trades) during the interval (in quote currency).
60    ///
61    /// Represents the monetary value of trades. Bots use this to assess liquidity and market interest.
62    #[serde(with = "string_to_float")]
63    pub turnover: f64,
64
65    /// Whether the candlestick is confirmed (closed).
66    ///
67    /// A `true` value indicates the candlestick is finalized. Bots should wait for confirmation before acting on signals to avoid premature trades.
68    pub confirm: bool,
69
70    /// The timestamp of the candlestick (in milliseconds).
71    ///
72    /// Typically aligns with `end`. Bots use this for precise timing in strategies.
73    pub timestamp: u64,
74}