nautilus_tardis/csv/
record.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use serde::{Deserialize, Serialize};
17use ustr::Ustr;
18
19use crate::{
20    enums::Exchange,
21    parse::{deserialize_trade_id, deserialize_uppercase},
22};
23
24/// Represents a Tardis format order book update record.
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct TardisBookUpdateRecord {
27    /// The exchange ID.
28    pub exchange: Exchange,
29    /// The instrument symbol as provided by the exchange.
30    #[serde(deserialize_with = "deserialize_uppercase")]
31    pub symbol: Ustr,
32    // UNIX microseconds timestamp provided by the exchange.
33    pub timestamp: u64,
34    // UNIX microseconds timestamp of message received.
35    pub local_timestamp: u64,
36    /// If update was a part of initial order book snapshot.
37    pub is_snapshot: bool,
38    /// The book side the update belongs to.
39    pub side: String,
40    /// The price identifying book level being updated.
41    pub price: f64,
42    /// The updated price level amount.
43    pub amount: f64,
44}
45
46/// Represents a Tardis format order book 5 level snapshot record.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct TardisOrderBookSnapshot5Record {
49    /// The exchange ID.
50    pub exchange: Exchange,
51    /// The instrument symbol as provided by the exchange.
52    #[serde(deserialize_with = "deserialize_uppercase")]
53    pub symbol: Ustr,
54    // UNIX microseconds timestamp provided by the exchange.
55    pub timestamp: u64,
56    // UNIX microseconds timestamp of message received.
57    pub local_timestamp: u64,
58    /// The price of the first ask.
59    pub asks_0_price: Option<f64>,
60    /// The amount of the first ask.
61    pub asks_0_amount: Option<f64>,
62    /// The price of the first bid.
63    pub bids_0_price: Option<f64>,
64    /// The amount of the first bid.
65    pub bids_0_amount: Option<f64>,
66    /// The price of the second ask.
67    pub asks_1_price: Option<f64>,
68    /// The amount of the second ask.
69    pub asks_1_amount: Option<f64>,
70    /// The price of the second bid.
71    pub bids_1_price: Option<f64>,
72    /// The amount of the second bid.
73    pub bids_1_amount: Option<f64>,
74    /// The price of the third ask.
75    pub asks_2_price: Option<f64>,
76    /// The amount of the third ask.
77    pub asks_2_amount: Option<f64>,
78    /// The price of the third bid.
79    pub bids_2_price: Option<f64>,
80    /// The amount of the third bid.
81    pub bids_2_amount: Option<f64>,
82    /// The price of the fourth ask.
83    pub asks_3_price: Option<f64>,
84    /// The amount of the fourth ask.
85    pub asks_3_amount: Option<f64>,
86    /// The price of the fourth bid.
87    pub bids_3_price: Option<f64>,
88    /// The amount of the fourth bid.
89    pub bids_3_amount: Option<f64>,
90    /// The price of the fifth ask.
91    pub asks_4_price: Option<f64>,
92    /// The amount of the fifth ask.
93    pub asks_4_amount: Option<f64>,
94    /// The price of the fifth bid.
95    pub bids_4_price: Option<f64>,
96    /// The amount of the fifth bid.
97    pub bids_4_amount: Option<f64>,
98}
99
100/// Represents a Tardis format order book 25 level snapshot record.
101#[derive(Debug, Clone, Serialize, Deserialize)]
102pub struct TardisOrderBookSnapshot25Record {
103    /// The exchange ID.
104    pub exchange: Exchange,
105    /// The instrument symbol as provided by the exchange.
106    #[serde(deserialize_with = "deserialize_uppercase")]
107    pub symbol: Ustr,
108    // UNIX microseconds timestamp provided by the exchange.
109    pub timestamp: u64,
110    // UNIX microseconds timestamp of message received.
111    pub local_timestamp: u64,
112
113    pub asks_0_price: Option<f64>,
114    pub asks_0_amount: Option<f64>,
115    pub bids_0_price: Option<f64>,
116    pub bids_0_amount: Option<f64>,
117
118    pub asks_1_price: Option<f64>,
119    pub asks_1_amount: Option<f64>,
120    pub bids_1_price: Option<f64>,
121    pub bids_1_amount: Option<f64>,
122
123    pub asks_2_price: Option<f64>,
124    pub asks_2_amount: Option<f64>,
125    pub bids_2_price: Option<f64>,
126    pub bids_2_amount: Option<f64>,
127
128    pub asks_3_price: Option<f64>,
129    pub asks_3_amount: Option<f64>,
130    pub bids_3_price: Option<f64>,
131    pub bids_3_amount: Option<f64>,
132
133    pub asks_4_price: Option<f64>,
134    pub asks_4_amount: Option<f64>,
135    pub bids_4_price: Option<f64>,
136    pub bids_4_amount: Option<f64>,
137
138    pub asks_5_price: Option<f64>,
139    pub asks_5_amount: Option<f64>,
140    pub bids_5_price: Option<f64>,
141    pub bids_5_amount: Option<f64>,
142
143    pub asks_6_price: Option<f64>,
144    pub asks_6_amount: Option<f64>,
145    pub bids_6_price: Option<f64>,
146    pub bids_6_amount: Option<f64>,
147
148    pub asks_7_price: Option<f64>,
149    pub asks_7_amount: Option<f64>,
150    pub bids_7_price: Option<f64>,
151    pub bids_7_amount: Option<f64>,
152
153    pub asks_8_price: Option<f64>,
154    pub asks_8_amount: Option<f64>,
155    pub bids_8_price: Option<f64>,
156    pub bids_8_amount: Option<f64>,
157
158    pub asks_9_price: Option<f64>,
159    pub asks_9_amount: Option<f64>,
160    pub bids_9_price: Option<f64>,
161    pub bids_9_amount: Option<f64>,
162
163    pub asks_10_price: Option<f64>,
164    pub asks_10_amount: Option<f64>,
165    pub bids_10_price: Option<f64>,
166    pub bids_10_amount: Option<f64>,
167
168    pub asks_11_price: Option<f64>,
169    pub asks_11_amount: Option<f64>,
170    pub bids_11_price: Option<f64>,
171    pub bids_11_amount: Option<f64>,
172
173    pub asks_12_price: Option<f64>,
174    pub asks_12_amount: Option<f64>,
175    pub bids_12_price: Option<f64>,
176    pub bids_12_amount: Option<f64>,
177
178    pub asks_13_price: Option<f64>,
179    pub asks_13_amount: Option<f64>,
180    pub bids_13_price: Option<f64>,
181    pub bids_13_amount: Option<f64>,
182
183    pub asks_14_price: Option<f64>,
184    pub asks_14_amount: Option<f64>,
185    pub bids_14_price: Option<f64>,
186    pub bids_14_amount: Option<f64>,
187
188    pub asks_15_price: Option<f64>,
189    pub asks_15_amount: Option<f64>,
190    pub bids_15_price: Option<f64>,
191    pub bids_15_amount: Option<f64>,
192
193    pub asks_16_price: Option<f64>,
194    pub asks_16_amount: Option<f64>,
195    pub bids_16_price: Option<f64>,
196    pub bids_16_amount: Option<f64>,
197
198    pub asks_17_price: Option<f64>,
199    pub asks_17_amount: Option<f64>,
200    pub bids_17_price: Option<f64>,
201    pub bids_17_amount: Option<f64>,
202
203    pub asks_18_price: Option<f64>,
204    pub asks_18_amount: Option<f64>,
205    pub bids_18_price: Option<f64>,
206    pub bids_18_amount: Option<f64>,
207
208    pub asks_19_price: Option<f64>,
209    pub asks_19_amount: Option<f64>,
210    pub bids_19_price: Option<f64>,
211    pub bids_19_amount: Option<f64>,
212
213    pub asks_20_price: Option<f64>,
214    pub asks_20_amount: Option<f64>,
215    pub bids_20_price: Option<f64>,
216    pub bids_20_amount: Option<f64>,
217
218    pub asks_21_price: Option<f64>,
219    pub asks_21_amount: Option<f64>,
220    pub bids_21_price: Option<f64>,
221    pub bids_21_amount: Option<f64>,
222
223    pub asks_22_price: Option<f64>,
224    pub asks_22_amount: Option<f64>,
225    pub bids_22_price: Option<f64>,
226    pub bids_22_amount: Option<f64>,
227
228    pub asks_23_price: Option<f64>,
229    pub asks_23_amount: Option<f64>,
230    pub bids_23_price: Option<f64>,
231    pub bids_23_amount: Option<f64>,
232
233    pub asks_24_price: Option<f64>,
234    pub asks_24_amount: Option<f64>,
235    pub bids_24_price: Option<f64>,
236    pub bids_24_amount: Option<f64>,
237}
238
239/// Represents a Tardis format quote record.
240#[derive(Debug, Clone, Serialize, Deserialize)]
241pub struct TardisQuoteRecord {
242    /// The exchande ID.
243    pub exchange: Exchange,
244    /// The instrument symbol as provided by the exchange.
245    #[serde(deserialize_with = "deserialize_uppercase")]
246    pub symbol: Ustr,
247    // UNIX microseconds timestamp provided by the exchange.
248    pub timestamp: u64,
249    // UNIX microseconds timestamp of message received.
250    pub local_timestamp: u64,
251    // The best ask amount as provided by exchange, empty if there aren't any asks.
252    pub ask_amount: Option<f64>,
253    // The best ask price as provided by exchange, empty if there aren't any asks.
254    pub ask_price: Option<f64>,
255    // The best bid price as provided by exchange, empty if there aren't any bids.
256    pub bid_price: Option<f64>,
257    // The best bid amount as provided by exchange, empty if there aren't any bids.
258    pub bid_amount: Option<f64>,
259}
260
261/// Represents a Tardis format trade record.
262#[derive(Debug, Clone, Serialize, Deserialize)]
263pub struct TardisTradeRecord {
264    /// The exchande ID.
265    pub exchange: Exchange,
266    /// The instrument symbol as provided by the exchange.
267    #[serde(deserialize_with = "deserialize_uppercase")]
268    pub symbol: Ustr,
269    // UNIX microseconds timestamp provided by the exchange.
270    pub timestamp: u64,
271    // UNIX microseconds timestamp of message received.
272    pub local_timestamp: u64,
273    /// The trade ID provided by the exchange. If empty, a new `UUIDv4` string is generated.
274    #[serde(deserialize_with = "deserialize_trade_id")]
275    pub id: String,
276    /// The liquidity taker (aggressor) side provided by the exchange.
277    pub side: String,
278    /// The trade price as provided by the exchange.
279    pub price: f64,
280    /// The trade amount as provided by the exchange.
281    pub amount: f64,
282}