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