bybit/models/linear_ticker/linear_ticker_snapshot.rs
1use crate::prelude::*;
2
3#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
4#[serde(rename_all = "camelCase")]
5#[serde(deny_unknown_fields)]
6pub struct LinearTickerDataSnapshot {
7 /// The trading pair symbol (e.g., "BTCUSDT").
8 ///
9 /// The ONLY required field for the ticker data. Bots use this to identify the market they are trading in.
10 ///
11 /// Identifies the perpetual futures contract for the ticker data. Bots use this to verify the correct market.
12 pub symbol: String,
13
14 /// The tick direction of the last price change.
15 ///
16 /// Indicates whether the last price change was an uptick or downtick (e.g., "PlusTick"). Bots use this to analyze short-term price momentum.
17 pub tick_direction: TickDirection,
18
19 /// The 24-hour price change percentage.
20 ///
21 /// The percentage change in price over the last 24 hours. Bots use this to assess market trends and volatility.
22 #[serde(default, with = "string_to_float")]
23 pub price_24h_pcnt: f64,
24
25 /// The last traded price.
26 ///
27 /// The most recent price at which the contract was traded. Bots use this for real-time price tracking and technical analysis.
28 #[serde(default, with = "string_to_float")]
29 pub last_price: f64,
30
31 /// The price 24 hours ago.
32 ///
33 /// The price of the contract 24 hours prior. Bots use this to calculate price changes and validate `price_24h_pcnt`.
34 #[serde(default, with = "string_to_float")]
35 pub prev_price_24h: f64,
36
37 /// The highest price in the last 24 hours.
38 ///
39 /// The peak price reached in the last 24 hours. Bots use this to identify resistance levels and assess volatility.
40 #[serde(default, with = "string_to_float")]
41 pub high_price_24h: f64,
42
43 /// The lowest price in the last 24 hours.
44 ///
45 /// The lowest price reached in the last 24 hours. Bots use this to identify support levels and assess volatility.
46 #[serde(default, with = "string_to_float")]
47 pub low_price_24h: f64,
48
49 /// The price 1 hour ago.
50 ///
51 /// The price of the contract 1 hour prior. Bots use this to calculate short-term price changes and momentum.
52 #[serde(default, with = "string_to_float")]
53 pub prev_price_1h: f64,
54
55 /// The open interest value in settlement currency.
56 ///
57 /// The monetary value of open interest (`open_interest` * `mark_price`). Bots use this to assess market exposure and leverage levels.
58 #[serde(default, with = "string_to_float")]
59 pub open_interest_value: f64,
60
61 /// The 24-hour trading turnover.
62 ///
63 /// The total trading value in the last 24 hours, in settlement currency. Bots use this to assess market activity and liquidity.
64 #[serde(default, with = "string_to_float")]
65 pub turnover_24h: f64,
66
67 /// The 24-hour trading volume.
68 ///
69 /// The total quantity of contracts traded in the last 24 hours. Bots use this to analyze market activity and trading intensity.
70 #[serde(default, with = "string_to_float")]
71 pub volume_24h: f64,
72
73 /// The best bid price.
74 ///
75 /// The highest price at which someone is willing to buy. Bots use this to assess buy-side liquidity and calculate spreads.
76 #[serde(default, rename = "bid1Price", with = "string_to_float")]
77 pub bid_price: f64,
78
79 /// The best bid size.
80 ///
81 /// The quantity available at the best bid price. Bots use this to evaluate buy-side liquidity and potential slippage.
82 #[serde(default, rename = "bid1Size", with = "string_to_float")]
83 pub bid_size: f64,
84
85 /// The best ask price.
86 ///
87 /// The lowest price at which someone is willing to sell. Bots use this to assess sell-side liquidity and calculate spreads.
88 #[serde(default, rename = "ask1Price", with = "string_to_float")]
89 pub ask_price: f64,
90
91 /// The best ask size.
92 ///
93 /// The quantity available at the best ask price. Bots use this to evaluate sell-side liquidity and potential slippage.
94 #[serde(default, rename = "ask1Size", with = "string_to_float")]
95 pub ask_size: f64,
96
97 /// The pre-open price, set by Bybit for a trading pair before it enters
98 /// regular trading, often during phases like subscription, announcement,
99 /// or pre-trading for new pairs. This price guides early trading or
100 /// subscription activities.
101 #[serde(default, with = "string_to_float_optional")]
102 pub pre_open_price: Option<f64>,
103
104 /// The pre-open quantity, represents the indicative or reference price for
105 /// a trading pair during a pre-listing or pre-trading phase. This price is
106 /// typically set by the exchange to guide trading activity when the pair is
107 /// not yet fully open for unrestricted trading (e.g., during a subscription
108 /// or announcement phase for new pairs).
109 #[serde(default, with = "string_to_float_optional")]
110 pub pre_qty: Option<f64>,
111
112 /// Indicates the current stage of a trading pair in Bybit’s pre-listing
113 /// process. Pre-listing phases are used for new or upcoming trading pairs
114 /// that are not yet fully available for trading but may be in a preparatory
115 /// or promotional stage.
116 #[serde(
117 deserialize_with = "empty_string_as_none",
118 skip_serializing_if = "is_empty_or_none"
119 )]
120 pub cur_pre_listing_phase: Option<String>,
121
122 /// The current funding rate.
123 ///
124 /// The funding rate applied to positions, as a decimal (e.g., 0.0001 for 0.01%). Bots use this to calculate funding costs or profits for long/short positions.
125 #[serde(default, with = "string_to_float")]
126 pub funding_rate: f64,
127
128 /// The timestamp of the next funding event in milliseconds.
129 ///
130 /// Indicates when the next funding rate payment will occur. Bots use this to schedule funding fee calculations and position adjustments.
131 #[serde(default, with = "string_to_u64")]
132 pub next_funding_time: u64,
133
134 /// The current index price.
135 ///
136 /// The index price, based on external spot markets, used for reference in perpetual futures. Bots use this to compare with mark price for funding rate calculations.
137 #[serde(default, with = "string_to_float")]
138 pub index_price: f64,
139
140 /// The current mark price.
141 ///
142 /// The mark price used for P&L calculations in perpetual futures. Bots use this to calculate unrealized P&L and assess position health.
143 #[serde(default, with = "string_to_float")]
144 pub mark_price: f64,
145
146 /// The open interest in contracts.
147 ///
148 /// The total number of open contracts in the market. Bots use this to gauge market participation and liquidity.
149 #[serde(default, with = "string_to_float")]
150 pub open_interest: f64,
151}
152
153impl LinearTickerDataSnapshot {
154 pub fn update(&mut self, delta: LinearTickerDataDelta) {
155 if let Some(index_price) = delta.index_price {
156 self.index_price = index_price;
157 }
158 if let Some(tick_direction) = delta.tick_direction {
159 self.tick_direction = tick_direction;
160 }
161 if let Some(price_24h_pcnt) = delta.price_24h_pcnt {
162 self.price_24h_pcnt = price_24h_pcnt;
163 }
164 if let Some(last_price) = delta.last_price {
165 self.last_price = last_price;
166 }
167 if let Some(prev_price_24h) = delta.prev_price_24h {
168 self.prev_price_24h = prev_price_24h;
169 }
170 if let Some(high_price_24h) = delta.high_price_24h {
171 self.high_price_24h = high_price_24h;
172 }
173 if let Some(low_price_24h) = delta.low_price_24h {
174 self.low_price_24h = low_price_24h;
175 }
176 if let Some(prev_price_1h) = delta.prev_price_1h {
177 self.prev_price_1h = prev_price_1h;
178 }
179 if let Some(mark_price) = delta.mark_price {
180 self.mark_price = mark_price;
181 }
182 if let Some(open_interest) = delta.open_interest {
183 self.open_interest = open_interest;
184 }
185 if let Some(open_interest_value) = delta.open_interest_value {
186 self.open_interest_value = open_interest_value;
187 }
188 if let Some(turnover_24h) = delta.turnover_24h {
189 self.turnover_24h = turnover_24h;
190 }
191 if let Some(volume_24h) = delta.volume_24h {
192 self.volume_24h = volume_24h;
193 }
194 if let Some(next_funding_time) = delta.next_funding_time {
195 self.next_funding_time = next_funding_time;
196 }
197 if let Some(funding_rate) = delta.funding_rate {
198 self.funding_rate = funding_rate;
199 }
200 if let Some(bid_price) = delta.bid_price {
201 self.bid_price = bid_price;
202 }
203 if let Some(bid_size) = delta.bid_size {
204 self.bid_size = bid_size;
205 }
206 if let Some(ask_price) = delta.ask_price {
207 self.ask_price = ask_price;
208 }
209 if let Some(ask_size) = delta.ask_size {
210 self.ask_size = ask_size;
211 }
212 if let Some(pre_qty) = delta.pre_qty {
213 self.pre_qty = Some(pre_qty);
214 }
215 if let Some(cur_pre_listing_phase) = delta.cur_pre_listing_phase {
216 self.cur_pre_listing_phase = Some(cur_pre_listing_phase);
217 }
218 if let Some(pre_open_price) = delta.pre_open_price {
219 self.pre_open_price = Some(pre_open_price);
220 }
221 }
222}