bybit/models/spot_ticker_data.rs
1use crate::prelude::*;
2
3/// Represents spot market ticker data for a trading pair on Bybit.
4///
5/// This struct provides real-time market data for spot trading pairs, including price, volume, and 24-hour statistics. While the file focuses on perpetual futures, this struct is included for spot market data, which can be relevant for bots hedging or arbitraging between spot and futures markets.
6///
7/// # Bybit API Reference
8/// The Bybit API (https://bybit-exchange.github.io/docs/v5/market/ticker) provides ticker data for spot markets, including last price, 24-hour high/low, and volume. Fields are serialized as strings but deserialized to `f64` for numerical computations.
9///
10/// # Perpetual Futures Context
11/// Spot ticker data can be used in conjunction with perpetual futures to identify arbitrage opportunities (e.g., cash-and-carry trades) or to monitor funding rates, as spot prices often serve as a reference for futures pricing.
12#[derive(Serialize, Deserialize, Debug, Clone)]
13#[serde(rename_all = "camelCase")]
14pub struct SpotTickerData {
15 /// The trading pair symbol (e.g., "BTCUSDT").
16 ///
17 /// Identifies the market for which the ticker data applies. Bots use this to filter and process data for specific trading pairs.
18 pub symbol: String,
19
20 /// The most recent trade price.
21 ///
22 /// This is the price of the last executed trade in the spot market. For bots, this is critical for tracking market trends and triggering trades based on price thresholds.
23 #[serde(with = "string_to_float")]
24 pub last_price: f64,
25
26 /// The highest price in the last 24 hours.
27 ///
28 /// Useful for identifying price volatility and setting upper bounds for trading strategies. Bots can use this to detect breakout patterns or avoid trading during extreme volatility.
29 #[serde(with = "string_to_float")]
30 pub high_price_24h: f64,
31
32 /// The lowest price in the last 24 hours.
33 ///
34 /// Helps bots assess support levels and market ranges. Combined with `high_price_24h`, it provides a 24-hour price range for volatility-based strategies.
35 #[serde(with = "string_to_float")]
36 pub low_price_24h: f64,
37
38 /// The price 24 hours ago.
39 ///
40 /// Used to calculate price changes over the last 24 hours. Bots can use this to compute momentum or mean-reversion signals.
41 #[serde(with = "string_to_float")]
42 pub prev_price_24h: f64,
43
44 /// The trading volume in the last 24 hours (in base currency).
45 ///
46 /// Indicates market activity and liquidity. High volume suggests strong participation, which bots can use to prioritize liquid markets for lower slippage.
47 #[serde(with = "string_to_float")]
48 pub volume_24h: f64,
49
50 /// The turnover (value of trades) in the last 24 hours (in quote currency).
51 ///
52 /// Represents the total monetary value of trades. Bots can use this to gauge market interest and correlate with volume for liquidity analysis.
53 #[serde(with = "string_to_float")]
54 pub turnover_24h: f64,
55
56 /// The percentage price change over the last 24 hours.
57 ///
58 /// A key metric for momentum trading strategies. Bots can use this to identify trending markets or trigger mean-reversion trades based on overbought/oversold conditions.
59 #[serde(with = "string_to_float")]
60 pub price_24h_pcnt: f64,
61
62 /// The USD index price for the asset.
63 ///
64 /// Represents the fair value of the asset based on Bybit's index calculation. For bots, this is critical for pricing perpetual futures, as it influences funding rates and mark prices.
65 #[serde(with = "string_to_float")]
66 pub usd_index_price: f64,
67}