nautilus_binance/common/sbe/spot/
mod.rs

1//! Generated SBE codecs for Binance Spot API (schema 3:1).
2//!
3//! This code is auto-generated by Real Logic's SBE generator from Binance's
4//! official XML schema. Do not edit manually.
5
6#![forbid(unsafe_code)]
7#![allow(clippy::all)]
8#![allow(clippy::missing_panics_doc)]
9#![allow(clippy::return_self_not_must_use)]
10#![allow(clippy::semicolon_if_nothing_returned)]
11#![allow(clippy::use_self)]
12#![allow(missing_docs)]
13#![allow(non_camel_case_types)]
14#![allow(ambiguous_glob_reexports)]
15#![allow(unused_imports)]
16#![allow(dead_code)]
17
18use ::core::convert::TryInto;
19
20pub mod account_commission_response_codec;
21pub mod account_order_rate_limit_response_codec;
22pub mod account_response_codec;
23pub mod account_trades_response_codec;
24pub mod account_type;
25pub mod agg_trades_response_codec;
26pub mod allowed_self_trade_prevention_modes;
27pub mod average_price_response_codec;
28pub mod balance_update_event_codec;
29pub mod book_ticker_response_codec;
30pub mod book_ticker_symbol_response_codec;
31pub mod bool_enum;
32pub mod cancel_open_orders_response_codec;
33pub mod cancel_order_list_response_codec;
34pub mod cancel_order_response_codec;
35pub mod cancel_replace_order_response_codec;
36pub mod cancel_replace_status;
37pub mod contingency_type;
38pub mod depth_response_codec;
39pub mod error_response_codec;
40pub mod exchange_info_response_codec;
41pub mod exchange_max_num_algo_orders_filter_codec;
42pub mod exchange_max_num_iceberg_orders_filter_codec;
43pub mod exchange_max_num_order_lists_filter_codec;
44pub mod exchange_max_num_orders_filter_codec;
45pub mod execution_report_event_codec;
46pub mod execution_type;
47pub mod filter_type;
48pub mod floor;
49pub mod group_size_16_encoding_codec;
50pub mod group_size_encoding_codec;
51pub mod iceberg_parts_filter_codec;
52pub mod klines_response_codec;
53pub mod list_order_status;
54pub mod list_status_event_codec;
55pub mod list_status_type;
56pub mod lot_size_filter_codec;
57pub mod market_lot_size_filter_codec;
58pub mod match_type;
59pub mod max_asset_filter_codec;
60pub mod max_num_algo_orders_filter_codec;
61pub mod max_num_iceberg_orders_filter_codec;
62pub mod max_num_order_lists_filter_codec;
63pub mod max_num_orders_filter_codec;
64pub mod max_position_filter_codec;
65pub mod message_data_16_codec;
66pub mod message_data_8_codec;
67pub mod message_data_codec;
68pub mod message_header_codec;
69pub mod min_notional_filter_codec;
70pub mod new_order_ack_response_codec;
71pub mod new_order_full_response_codec;
72pub mod new_order_list_ack_response_codec;
73pub mod new_order_list_full_response_codec;
74pub mod new_order_list_result_response_codec;
75pub mod new_order_result_response_codec;
76pub mod notional_filter_codec;
77pub mod optional_message_data_16_codec;
78pub mod optional_message_data_codec;
79pub mod optional_var_string_8_codec;
80pub mod optional_var_string_codec;
81pub mod order_capacity;
82pub mod order_list_response_codec;
83pub mod order_lists_response_codec;
84pub mod order_response_codec;
85pub mod order_side;
86pub mod order_status;
87pub mod order_test_response_codec;
88pub mod order_test_with_commissions_response_codec;
89pub mod order_type;
90pub mod order_types;
91pub mod orders_response_codec;
92pub mod outbound_account_position_event_codec;
93pub mod peg_offset_type;
94pub mod peg_price_type;
95pub mod percent_price_by_side_filter_codec;
96pub mod percent_price_filter_codec;
97pub mod ping_response_codec;
98pub mod price_filter_codec;
99pub mod price_ticker_response_codec;
100pub mod price_ticker_symbol_response_codec;
101pub mod rate_limit_interval;
102pub mod rate_limit_type;
103pub mod self_trade_prevention_mode;
104pub mod server_time_response_codec;
105pub mod symbol_status;
106pub mod ticker_24_hf_ull_response_codec;
107pub mod ticker_24_hm_ini_response_codec;
108pub mod ticker_24_hs_ymbol_full_response_codec;
109pub mod ticker_24_hs_ymbol_mini_response_codec;
110pub mod ticker_full_response_codec;
111pub mod ticker_mini_response_codec;
112pub mod ticker_symbol_full_response_codec;
113pub mod ticker_symbol_mini_response_codec;
114pub mod time_in_force;
115pub mod tp_lus_sell_filter_codec;
116pub mod trades_response_codec;
117pub mod trailing_delta_filter_codec;
118pub mod var_string_8_codec;
119pub mod var_string_codec;
120pub mod web_socket_response_codec;
121pub mod web_socket_session_logon_response_codec;
122pub mod web_socket_session_logout_response_codec;
123pub mod web_socket_session_status_response_codec;
124pub mod web_socket_session_subscriptions_response_codec;
125
126pub const SBE_SCHEMA_ID: u16 = 3;
127pub const SBE_SCHEMA_VERSION: u16 = 1;
128pub const SBE_SEMANTIC_VERSION: &str = "5.2";
129
130pub type SbeResult<T> = core::result::Result<T, SbeErr>;
131
132#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
133pub enum SbeErr {
134    ParentNotSet,
135}
136impl core::fmt::Display for SbeErr {
137    #[inline]
138    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
139        write!(f, "{self:?}")
140    }
141}
142impl std::error::Error for SbeErr {}
143
144#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
145pub enum Either<L, R> {
146    Left(L),
147    Right(R),
148}
149
150pub trait Writer<'a>: Sized {
151    fn get_buf_mut(&mut self) -> &mut WriteBuf<'a>;
152}
153
154pub trait Encoder<'a>: Writer<'a> {
155    fn get_limit(&self) -> usize;
156    fn set_limit(&mut self, limit: usize);
157}
158
159pub trait ActingVersion {
160    fn acting_version(&self) -> u16;
161}
162
163pub trait Reader<'a>: Sized {
164    fn get_buf(&self) -> &ReadBuf<'a>;
165}
166
167pub trait Decoder<'a>: Reader<'a> {
168    fn get_limit(&self) -> usize;
169    fn set_limit(&mut self, limit: usize);
170}
171
172#[derive(Clone, Copy, Debug, Default)]
173pub struct ReadBuf<'a> {
174    data: &'a [u8],
175}
176impl<'a> Reader<'a> for ReadBuf<'a> {
177    #[inline]
178    fn get_buf(&self) -> &ReadBuf<'a> {
179        self
180    }
181}
182#[allow(dead_code)]
183impl<'a> ReadBuf<'a> {
184    #[inline]
185    pub fn new(data: &'a [u8]) -> Self {
186        Self { data }
187    }
188
189    #[inline]
190    pub(crate) fn get_bytes_at<const N: usize>(slice: &[u8], index: usize) -> [u8; N] {
191        slice[index..index + N]
192            .try_into()
193            .expect("slice with incorrect length")
194    }
195
196    #[inline]
197    pub fn get_u8_at(&self, index: usize) -> u8 {
198        self.data[index]
199    }
200
201    #[inline]
202    pub fn get_i8_at(&self, index: usize) -> i8 {
203        i8::from_le_bytes(Self::get_bytes_at(self.data, index))
204    }
205
206    #[inline]
207    pub fn get_i16_at(&self, index: usize) -> i16 {
208        i16::from_le_bytes(Self::get_bytes_at(self.data, index))
209    }
210
211    #[inline]
212    pub fn get_i32_at(&self, index: usize) -> i32 {
213        i32::from_le_bytes(Self::get_bytes_at(self.data, index))
214    }
215
216    #[inline]
217    pub fn get_i64_at(&self, index: usize) -> i64 {
218        i64::from_le_bytes(Self::get_bytes_at(self.data, index))
219    }
220
221    #[inline]
222    pub fn get_u16_at(&self, index: usize) -> u16 {
223        u16::from_le_bytes(Self::get_bytes_at(self.data, index))
224    }
225
226    #[inline]
227    pub fn get_u32_at(&self, index: usize) -> u32 {
228        u32::from_le_bytes(Self::get_bytes_at(self.data, index))
229    }
230
231    #[inline]
232    pub fn get_u64_at(&self, index: usize) -> u64 {
233        u64::from_le_bytes(Self::get_bytes_at(self.data, index))
234    }
235
236    #[inline]
237    pub fn get_f32_at(&self, index: usize) -> f32 {
238        f32::from_le_bytes(Self::get_bytes_at(self.data, index))
239    }
240
241    #[inline]
242    pub fn get_f64_at(&self, index: usize) -> f64 {
243        f64::from_le_bytes(Self::get_bytes_at(self.data, index))
244    }
245
246    #[inline]
247    pub fn get_slice_at(&self, index: usize, len: usize) -> &[u8] {
248        &self.data[index..index + len]
249    }
250}
251
252#[derive(Debug, Default)]
253pub struct WriteBuf<'a> {
254    data: &'a mut [u8],
255}
256impl<'a> WriteBuf<'a> {
257    pub fn new(data: &'a mut [u8]) -> Self {
258        Self { data }
259    }
260
261    #[inline]
262    pub fn put_bytes_at<const COUNT: usize>(&mut self, index: usize, bytes: &[u8; COUNT]) -> usize {
263        self.data[index..index + COUNT].copy_from_slice(bytes);
264        COUNT
265    }
266
267    #[inline]
268    pub fn put_u8_at(&mut self, index: usize, value: u8) {
269        self.data[index] = value;
270    }
271
272    #[inline]
273    pub fn put_i8_at(&mut self, index: usize, value: i8) {
274        self.put_bytes_at(index, &i8::to_le_bytes(value));
275    }
276
277    #[inline]
278    pub fn put_i16_at(&mut self, index: usize, value: i16) {
279        self.put_bytes_at(index, &i16::to_le_bytes(value));
280    }
281
282    #[inline]
283    pub fn put_i32_at(&mut self, index: usize, value: i32) {
284        self.put_bytes_at(index, &i32::to_le_bytes(value));
285    }
286
287    #[inline]
288    pub fn put_i64_at(&mut self, index: usize, value: i64) {
289        self.put_bytes_at(index, &i64::to_le_bytes(value));
290    }
291
292    #[inline]
293    pub fn put_u16_at(&mut self, index: usize, value: u16) {
294        self.put_bytes_at(index, &u16::to_le_bytes(value));
295    }
296
297    #[inline]
298    pub fn put_u32_at(&mut self, index: usize, value: u32) {
299        self.put_bytes_at(index, &u32::to_le_bytes(value));
300    }
301
302    #[inline]
303    pub fn put_u64_at(&mut self, index: usize, value: u64) {
304        self.put_bytes_at(index, &u64::to_le_bytes(value));
305    }
306
307    #[inline]
308    pub fn put_f32_at(&mut self, index: usize, value: f32) {
309        self.put_bytes_at(index, &f32::to_le_bytes(value));
310    }
311
312    #[inline]
313    pub fn put_f64_at(&mut self, index: usize, value: f64) {
314        self.put_bytes_at(index, &f64::to_le_bytes(value));
315    }
316
317    #[inline]
318    pub fn put_slice_at(&mut self, index: usize, src: &[u8]) -> usize {
319        let len = src.len();
320        let dest = self.data.split_at_mut(index).1.split_at_mut(len).0;
321        dest.clone_from_slice(src);
322        len
323    }
324}
325impl<'a> From<&'a mut WriteBuf<'a>> for &'a mut [u8] {
326    #[inline]
327    fn from(buf: &'a mut WriteBuf<'a>) -> &'a mut [u8] {
328        buf.data
329    }
330}