Skip to main content

nautilus_binance/spot/sbe/generated/
account_trades_response_codec.rs

1pub use decoder::AccountTradesResponseDecoder;
2pub use encoder::AccountTradesResponseEncoder;
3
4use super::*;
5pub use super::{SBE_SCHEMA_ID, SBE_SCHEMA_VERSION, SBE_SEMANTIC_VERSION};
6
7pub const SBE_BLOCK_LENGTH: u16 = 0;
8pub const SBE_TEMPLATE_ID: u16 = 401;
9
10pub mod encoder {
11    use message_header_codec::*;
12
13    use super::*;
14
15    #[derive(Debug, Default)]
16    pub struct AccountTradesResponseEncoder<'a> {
17        buf: WriteBuf<'a>,
18        initial_offset: usize,
19        offset: usize,
20        limit: usize,
21    }
22
23    impl<'a> Writer<'a> for AccountTradesResponseEncoder<'a> {
24        #[inline]
25        fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
26            &mut self.buf
27        }
28    }
29
30    impl<'a> Encoder<'a> for AccountTradesResponseEncoder<'a> {
31        #[inline]
32        fn get_limit(&self) -> usize {
33            self.limit
34        }
35
36        #[inline]
37        fn set_limit(&mut self, limit: usize) {
38            self.limit = limit;
39        }
40    }
41
42    impl<'a> AccountTradesResponseEncoder<'a> {
43        pub fn wrap(mut self, buf: WriteBuf<'a>, offset: usize) -> Self {
44            let limit = offset + SBE_BLOCK_LENGTH as usize;
45            self.buf = buf;
46            self.initial_offset = offset;
47            self.offset = offset;
48            self.limit = limit;
49            self
50        }
51
52        #[inline]
53        pub fn encoded_length(&self) -> usize {
54            self.limit - self.offset
55        }
56
57        pub fn header(self, offset: usize) -> MessageHeaderEncoder<Self> {
58            let mut header = MessageHeaderEncoder::default().wrap(self, offset);
59            header.block_length(SBE_BLOCK_LENGTH);
60            header.template_id(SBE_TEMPLATE_ID);
61            header.schema_id(SBE_SCHEMA_ID);
62            header.version(SBE_SCHEMA_VERSION);
63            header
64        }
65
66        /// GROUP ENCODER (id=100)
67        #[inline]
68        pub fn trades_encoder(
69            self,
70            count: u32,
71            trades_encoder: TradesEncoder<Self>,
72        ) -> TradesEncoder<Self> {
73            trades_encoder.wrap(self, count)
74        }
75    }
76
77    #[derive(Debug, Default)]
78    pub struct TradesEncoder<P> {
79        parent: Option<P>,
80        count: u32,
81        index: usize,
82        offset: usize,
83        initial_limit: usize,
84    }
85
86    impl<'a, P> Writer<'a> for TradesEncoder<P>
87    where
88        P: Writer<'a> + Default,
89    {
90        #[inline]
91        fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
92            if let Some(parent) = self.parent.as_mut() {
93                parent.get_buf_mut()
94            } else {
95                panic!("parent was None")
96            }
97        }
98    }
99
100    impl<'a, P> Encoder<'a> for TradesEncoder<P>
101    where
102        P: Encoder<'a> + Default,
103    {
104        #[inline]
105        fn get_limit(&self) -> usize {
106            self.parent.as_ref().expect("parent missing").get_limit()
107        }
108
109        #[inline]
110        fn set_limit(&mut self, limit: usize) {
111            self.parent
112                .as_mut()
113                .expect("parent missing")
114                .set_limit(limit);
115        }
116    }
117
118    impl<'a, P> TradesEncoder<P>
119    where
120        P: Encoder<'a> + Default,
121    {
122        #[inline]
123        pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
124            let initial_limit = parent.get_limit();
125            parent.set_limit(initial_limit + 6);
126            parent
127                .get_buf_mut()
128                .put_u16_at(initial_limit, Self::block_length());
129            parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
130            self.parent = Some(parent);
131            self.count = count;
132            self.index = usize::MAX;
133            self.offset = usize::MAX;
134            self.initial_limit = initial_limit;
135            self
136        }
137
138        #[inline]
139        pub fn block_length() -> u16 {
140            70
141        }
142
143        #[inline]
144        pub fn parent(&mut self) -> SbeResult<P> {
145            self.parent.take().ok_or(SbeErr::ParentNotSet)
146        }
147
148        /// will return Some(current index) when successful otherwise None
149        #[inline]
150        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
151            let index = self.index.wrapping_add(1);
152            if index >= self.count as usize {
153                return Ok(None);
154            }
155
156            if let Some(parent) = self.parent.as_mut() {
157                self.offset = parent.get_limit();
158                parent.set_limit(self.offset + Self::block_length() as usize);
159                self.index = index;
160                Ok(Some(index))
161            } else {
162                Err(SbeErr::ParentNotSet)
163            }
164        }
165
166        /// primitive field 'priceExponent'
167        /// - min value: -127
168        /// - max value: 127
169        /// - null value: -128_i8
170        /// - characterEncoding: null
171        /// - semanticType: null
172        /// - encodedOffset: 0
173        /// - encodedLength: 1
174        /// - version: 0
175        #[inline]
176        pub fn price_exponent(&mut self, value: i8) {
177            let offset = self.offset;
178            self.get_buf_mut().put_i8_at(offset, value);
179        }
180
181        /// primitive field 'qtyExponent'
182        /// - min value: -127
183        /// - max value: 127
184        /// - null value: -128_i8
185        /// - characterEncoding: null
186        /// - semanticType: null
187        /// - encodedOffset: 1
188        /// - encodedLength: 1
189        /// - version: 0
190        #[inline]
191        pub fn qty_exponent(&mut self, value: i8) {
192            let offset = self.offset + 1;
193            self.get_buf_mut().put_i8_at(offset, value);
194        }
195
196        /// primitive field 'commissionExponent'
197        /// - min value: -127
198        /// - max value: 127
199        /// - null value: -128_i8
200        /// - characterEncoding: null
201        /// - semanticType: null
202        /// - encodedOffset: 2
203        /// - encodedLength: 1
204        /// - version: 0
205        #[inline]
206        pub fn commission_exponent(&mut self, value: i8) {
207            let offset = self.offset + 2;
208            self.get_buf_mut().put_i8_at(offset, value);
209        }
210
211        /// primitive field 'id'
212        /// - min value: -9223372036854775807
213        /// - max value: 9223372036854775807
214        /// - null value: -9223372036854775808_i64
215        /// - characterEncoding: null
216        /// - semanticType: null
217        /// - encodedOffset: 3
218        /// - encodedLength: 8
219        /// - version: 0
220        #[inline]
221        pub fn id(&mut self, value: i64) {
222            let offset = self.offset + 3;
223            self.get_buf_mut().put_i64_at(offset, value);
224        }
225
226        /// primitive field 'orderId'
227        /// - min value: -9223372036854775807
228        /// - max value: 9223372036854775807
229        /// - null value: -9223372036854775808_i64
230        /// - characterEncoding: null
231        /// - semanticType: null
232        /// - encodedOffset: 11
233        /// - encodedLength: 8
234        /// - version: 0
235        #[inline]
236        pub fn order_id(&mut self, value: i64) {
237            let offset = self.offset + 11;
238            self.get_buf_mut().put_i64_at(offset, value);
239        }
240
241        /// primitive field 'orderListId'
242        /// - min value: -9223372036854775807
243        /// - max value: 9223372036854775807
244        /// - null value: -9223372036854775808_i64
245        /// - characterEncoding: null
246        /// - semanticType: null
247        /// - encodedOffset: 19
248        /// - encodedLength: 8
249        /// - version: 0
250        #[inline]
251        pub fn order_list_id(&mut self, value: i64) {
252            let offset = self.offset + 19;
253            self.get_buf_mut().put_i64_at(offset, value);
254        }
255
256        /// primitive field 'price'
257        /// - min value: -9223372036854775807
258        /// - max value: 9223372036854775807
259        /// - null value: -9223372036854775808_i64
260        /// - characterEncoding: null
261        /// - semanticType: null
262        /// - encodedOffset: 27
263        /// - encodedLength: 8
264        /// - version: 0
265        #[inline]
266        pub fn price(&mut self, value: i64) {
267            let offset = self.offset + 27;
268            self.get_buf_mut().put_i64_at(offset, value);
269        }
270
271        /// primitive field 'qty'
272        /// - min value: -9223372036854775807
273        /// - max value: 9223372036854775807
274        /// - null value: -9223372036854775808_i64
275        /// - characterEncoding: null
276        /// - semanticType: null
277        /// - encodedOffset: 35
278        /// - encodedLength: 8
279        /// - version: 0
280        #[inline]
281        pub fn qty(&mut self, value: i64) {
282            let offset = self.offset + 35;
283            self.get_buf_mut().put_i64_at(offset, value);
284        }
285
286        /// primitive field 'quoteQty'
287        /// - min value: -9223372036854775807
288        /// - max value: 9223372036854775807
289        /// - null value: -9223372036854775808_i64
290        /// - characterEncoding: null
291        /// - semanticType: null
292        /// - encodedOffset: 43
293        /// - encodedLength: 8
294        /// - version: 0
295        #[inline]
296        pub fn quote_qty(&mut self, value: i64) {
297            let offset = self.offset + 43;
298            self.get_buf_mut().put_i64_at(offset, value);
299        }
300
301        /// primitive field 'commission'
302        /// - min value: -9223372036854775807
303        /// - max value: 9223372036854775807
304        /// - null value: -9223372036854775808_i64
305        /// - characterEncoding: null
306        /// - semanticType: null
307        /// - encodedOffset: 51
308        /// - encodedLength: 8
309        /// - version: 0
310        #[inline]
311        pub fn commission(&mut self, value: i64) {
312            let offset = self.offset + 51;
313            self.get_buf_mut().put_i64_at(offset, value);
314        }
315
316        /// primitive field 'time'
317        /// - min value: -9223372036854775807
318        /// - max value: 9223372036854775807
319        /// - null value: -9223372036854775808_i64
320        /// - characterEncoding: null
321        /// - semanticType: null
322        /// - encodedOffset: 59
323        /// - encodedLength: 8
324        /// - version: 0
325        #[inline]
326        pub fn time(&mut self, value: i64) {
327            let offset = self.offset + 59;
328            self.get_buf_mut().put_i64_at(offset, value);
329        }
330
331        /// REQUIRED enum
332        #[inline]
333        pub fn is_buyer(&mut self, value: bool_enum::BoolEnum) {
334            let offset = self.offset + 67;
335            self.get_buf_mut().put_u8_at(offset, value as u8)
336        }
337
338        /// REQUIRED enum
339        #[inline]
340        pub fn is_maker(&mut self, value: bool_enum::BoolEnum) {
341            let offset = self.offset + 68;
342            self.get_buf_mut().put_u8_at(offset, value as u8)
343        }
344
345        /// REQUIRED enum
346        #[inline]
347        pub fn is_best_match(&mut self, value: bool_enum::BoolEnum) {
348            let offset = self.offset + 69;
349            self.get_buf_mut().put_u8_at(offset, value as u8)
350        }
351
352        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
353        #[inline]
354        pub fn symbol(&mut self, value: &str) {
355            let limit = self.get_limit();
356            let data_length = value.len();
357            self.set_limit(limit + 1 + data_length);
358            self.get_buf_mut().put_u8_at(limit, data_length as u8);
359            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
360        }
361
362        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
363        #[inline]
364        pub fn commission_asset(&mut self, value: &str) {
365            let limit = self.get_limit();
366            let data_length = value.len();
367            self.set_limit(limit + 1 + data_length);
368            self.get_buf_mut().put_u8_at(limit, data_length as u8);
369            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
370        }
371    }
372} // end encoder
373
374pub mod decoder {
375    use message_header_codec::*;
376
377    use super::*;
378
379    #[derive(Clone, Copy, Debug, Default)]
380    pub struct AccountTradesResponseDecoder<'a> {
381        buf: ReadBuf<'a>,
382        initial_offset: usize,
383        offset: usize,
384        limit: usize,
385        pub acting_block_length: u16,
386        pub acting_version: u16,
387    }
388
389    impl ActingVersion for AccountTradesResponseDecoder<'_> {
390        #[inline]
391        fn acting_version(&self) -> u16 {
392            self.acting_version
393        }
394    }
395
396    impl<'a> Reader<'a> for AccountTradesResponseDecoder<'a> {
397        #[inline]
398        fn get_buf(&self) -> &ReadBuf<'a> {
399            &self.buf
400        }
401    }
402
403    impl<'a> Decoder<'a> for AccountTradesResponseDecoder<'a> {
404        #[inline]
405        fn get_limit(&self) -> usize {
406            self.limit
407        }
408
409        #[inline]
410        fn set_limit(&mut self, limit: usize) {
411            self.limit = limit;
412        }
413    }
414
415    impl<'a> AccountTradesResponseDecoder<'a> {
416        pub fn wrap(
417            mut self,
418            buf: ReadBuf<'a>,
419            offset: usize,
420            acting_block_length: u16,
421            acting_version: u16,
422        ) -> Self {
423            let limit = offset + acting_block_length as usize;
424            self.buf = buf;
425            self.initial_offset = offset;
426            self.offset = offset;
427            self.limit = limit;
428            self.acting_block_length = acting_block_length;
429            self.acting_version = acting_version;
430            self
431        }
432
433        #[inline]
434        pub fn encoded_length(&self) -> usize {
435            self.limit - self.offset
436        }
437
438        pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
439            debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
440            let acting_block_length = header.block_length();
441            let acting_version = header.version();
442
443            self.wrap(
444                header.parent().unwrap(),
445                offset + message_header_codec::ENCODED_LENGTH,
446                acting_block_length,
447                acting_version,
448            )
449        }
450
451        /// GROUP DECODER (id=100)
452        #[inline]
453        pub fn trades_decoder(self) -> TradesDecoder<Self> {
454            TradesDecoder::default().wrap(self)
455        }
456    }
457
458    #[derive(Debug, Default)]
459    pub struct TradesDecoder<P> {
460        parent: Option<P>,
461        block_length: u16,
462        count: u32,
463        index: usize,
464        offset: usize,
465    }
466
467    impl<'a, P> ActingVersion for TradesDecoder<P>
468    where
469        P: Reader<'a> + ActingVersion + Default,
470    {
471        #[inline]
472        fn acting_version(&self) -> u16 {
473            self.parent.as_ref().unwrap().acting_version()
474        }
475    }
476
477    impl<'a, P> Reader<'a> for TradesDecoder<P>
478    where
479        P: Reader<'a> + Default,
480    {
481        #[inline]
482        fn get_buf(&self) -> &ReadBuf<'a> {
483            self.parent.as_ref().expect("parent missing").get_buf()
484        }
485    }
486
487    impl<'a, P> Decoder<'a> for TradesDecoder<P>
488    where
489        P: Decoder<'a> + ActingVersion + Default,
490    {
491        #[inline]
492        fn get_limit(&self) -> usize {
493            self.parent.as_ref().expect("parent missing").get_limit()
494        }
495
496        #[inline]
497        fn set_limit(&mut self, limit: usize) {
498            self.parent
499                .as_mut()
500                .expect("parent missing")
501                .set_limit(limit);
502        }
503    }
504
505    impl<'a, P> TradesDecoder<P>
506    where
507        P: Decoder<'a> + ActingVersion + Default,
508    {
509        pub fn wrap(mut self, mut parent: P) -> Self {
510            let initial_offset = parent.get_limit();
511            let block_length = parent.get_buf().get_u16_at(initial_offset);
512            let count = parent.get_buf().get_u32_at(initial_offset + 2);
513            parent.set_limit(initial_offset + 6);
514            self.parent = Some(parent);
515            self.block_length = block_length;
516            self.count = count;
517            self.index = usize::MAX;
518            self.offset = 0;
519            self
520        }
521
522        /// group token - Token{signal=BEGIN_GROUP, name='trades', referencedName='null', description='null', packageName='null', id=100, version=0, deprecated=0, encodedLength=70, offset=0, componentTokenCount=69, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}}
523        #[inline]
524        pub fn parent(&mut self) -> SbeResult<P> {
525            self.parent.take().ok_or(SbeErr::ParentNotSet)
526        }
527
528        #[inline]
529        pub fn acting_version(&mut self) -> u16 {
530            self.parent.as_ref().unwrap().acting_version()
531        }
532
533        #[inline]
534        pub fn count(&self) -> u32 {
535            self.count
536        }
537
538        /// will return Some(current index) when successful otherwise None
539        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
540            let index = self.index.wrapping_add(1);
541            if index >= self.count as usize {
542                return Ok(None);
543            }
544
545            if let Some(parent) = self.parent.as_mut() {
546                self.offset = parent.get_limit();
547                parent.set_limit(self.offset + self.block_length as usize);
548                self.index = index;
549                Ok(Some(index))
550            } else {
551                Err(SbeErr::ParentNotSet)
552            }
553        }
554
555        /// primitive field - 'REQUIRED'
556        #[inline]
557        pub fn price_exponent(&self) -> i8 {
558            self.get_buf().get_i8_at(self.offset)
559        }
560
561        /// primitive field - 'REQUIRED'
562        #[inline]
563        pub fn qty_exponent(&self) -> i8 {
564            self.get_buf().get_i8_at(self.offset + 1)
565        }
566
567        /// primitive field - 'REQUIRED'
568        #[inline]
569        pub fn commission_exponent(&self) -> i8 {
570            self.get_buf().get_i8_at(self.offset + 2)
571        }
572
573        /// primitive field - 'REQUIRED'
574        #[inline]
575        pub fn id(&self) -> i64 {
576            self.get_buf().get_i64_at(self.offset + 3)
577        }
578
579        /// primitive field - 'REQUIRED'
580        #[inline]
581        pub fn order_id(&self) -> i64 {
582            self.get_buf().get_i64_at(self.offset + 11)
583        }
584
585        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
586        #[inline]
587        pub fn order_list_id(&self) -> Option<i64> {
588            let value = self.get_buf().get_i64_at(self.offset + 19);
589            if value == -9223372036854775808_i64 {
590                None
591            } else {
592                Some(value)
593            }
594        }
595
596        /// primitive field - 'REQUIRED'
597        #[inline]
598        pub fn price(&self) -> i64 {
599            self.get_buf().get_i64_at(self.offset + 27)
600        }
601
602        /// primitive field - 'REQUIRED'
603        #[inline]
604        pub fn qty(&self) -> i64 {
605            self.get_buf().get_i64_at(self.offset + 35)
606        }
607
608        /// primitive field - 'REQUIRED'
609        #[inline]
610        pub fn quote_qty(&self) -> i64 {
611            self.get_buf().get_i64_at(self.offset + 43)
612        }
613
614        /// primitive field - 'REQUIRED'
615        #[inline]
616        pub fn commission(&self) -> i64 {
617            self.get_buf().get_i64_at(self.offset + 51)
618        }
619
620        /// primitive field - 'REQUIRED'
621        #[inline]
622        pub fn time(&self) -> i64 {
623            self.get_buf().get_i64_at(self.offset + 59)
624        }
625
626        /// REQUIRED enum
627        #[inline]
628        pub fn is_buyer(&self) -> bool_enum::BoolEnum {
629            self.get_buf().get_u8_at(self.offset + 67).into()
630        }
631
632        /// REQUIRED enum
633        #[inline]
634        pub fn is_maker(&self) -> bool_enum::BoolEnum {
635            self.get_buf().get_u8_at(self.offset + 68).into()
636        }
637
638        /// REQUIRED enum
639        #[inline]
640        pub fn is_best_match(&self) -> bool_enum::BoolEnum {
641            self.get_buf().get_u8_at(self.offset + 69).into()
642        }
643
644        /// VAR_DATA DECODER - character encoding: 'UTF-8'
645        #[inline]
646        pub fn symbol_decoder(&mut self) -> (usize, usize) {
647            let offset = self.parent.as_ref().expect("parent missing").get_limit();
648            let data_length = self.get_buf().get_u8_at(offset) as usize;
649            self.parent
650                .as_mut()
651                .unwrap()
652                .set_limit(offset + 1 + data_length);
653            (offset + 1, data_length)
654        }
655
656        #[inline]
657        pub fn symbol_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
658            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
659            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
660        }
661
662        /// VAR_DATA DECODER - character encoding: 'UTF-8'
663        #[inline]
664        pub fn commission_asset_decoder(&mut self) -> (usize, usize) {
665            let offset = self.parent.as_ref().expect("parent missing").get_limit();
666            let data_length = self.get_buf().get_u8_at(offset) as usize;
667            self.parent
668                .as_mut()
669                .unwrap()
670                .set_limit(offset + 1 + data_length);
671            (offset + 1, data_length)
672        }
673
674        #[inline]
675        pub fn commission_asset_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
676            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
677            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
678        }
679    }
680} // end decoder