18
18
//! Defines the `BarAggregator` trait and core aggregation types (tick, volume, value, time),
19
19
//! along with the `BarBuilder` and `BarAggregatorCore` helpers for constructing bars.
20
20
21
- use std:: { any:: Any , cell:: RefCell , ops:: Add , rc:: Rc } ;
21
+ use std:: { any:: Any , cell:: RefCell , fmt :: Debug , ops:: Add , rc:: Rc } ;
22
22
23
23
use chrono:: TimeDelta ;
24
24
use nautilus_common:: {
@@ -42,7 +42,7 @@ use nautilus_model::{
42
42
/// Trait for aggregating incoming price and trade events into time-, tick-, volume-, or value-based bars.
43
43
///
44
44
/// Implementors receive updates and produce completed bars via handlers, with support for partial and batch updates.
45
- pub trait BarAggregator : Any {
45
+ pub trait BarAggregator : Any + Debug {
46
46
/// The [`BarType`] to be aggregated.
47
47
fn bar_type ( & self ) -> BarType ;
48
48
/// If the aggregator is running and will receive data from the message bus.
@@ -102,6 +102,7 @@ impl dyn BarAggregator {
102
102
}
103
103
104
104
/// Provides a generic bar builder for aggregation.
105
+ #[ derive( Debug ) ]
105
106
pub struct BarBuilder {
106
107
bar_type : BarType ,
107
108
price_precision : u8 ,
@@ -318,6 +319,18 @@ where
318
319
batch_mode : bool ,
319
320
}
320
321
322
+ impl < H : FnMut ( Bar ) > Debug for BarAggregatorCore < H > {
323
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
324
+ f. debug_struct ( stringify ! ( BarAggregatorCore ) )
325
+ . field ( "bar_type" , & self . bar_type )
326
+ . field ( "builder" , & self . builder )
327
+ . field ( "await_partial" , & self . await_partial )
328
+ . field ( "is_running" , & self . is_running )
329
+ . field ( "batch_mode" , & self . batch_mode )
330
+ . finish ( )
331
+ }
332
+ }
333
+
321
334
impl < H > BarAggregatorCore < H >
322
335
where
323
336
H : FnMut ( Bar ) ,
@@ -417,6 +430,15 @@ where
417
430
cum_value : f64 ,
418
431
}
419
432
433
+ impl < H : FnMut ( Bar ) > Debug for TickBarAggregator < H > {
434
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
435
+ f. debug_struct ( "TickBarAggregator" )
436
+ . field ( "core" , & self . core )
437
+ . field ( "cum_value" , & self . cum_value )
438
+ . finish ( )
439
+ }
440
+ }
441
+
420
442
impl < H > TickBarAggregator < H >
421
443
where
422
444
H : FnMut ( Bar ) ,
@@ -535,6 +557,14 @@ where
535
557
core : BarAggregatorCore < H > ,
536
558
}
537
559
560
+ impl < H : FnMut ( Bar ) > Debug for VolumeBarAggregator < H > {
561
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
562
+ f. debug_struct ( "VolumeBarAggregator" )
563
+ . field ( "core" , & self . core )
564
+ . finish ( )
565
+ }
566
+ }
567
+
538
568
impl < H > VolumeBarAggregator < H >
539
569
where
540
570
H : FnMut ( Bar ) ,
@@ -669,6 +699,15 @@ where
669
699
cum_value : f64 ,
670
700
}
671
701
702
+ impl < H : FnMut ( Bar ) > Debug for ValueBarAggregator < H > {
703
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
704
+ f. debug_struct ( "ValueBarAggregator" )
705
+ . field ( "core" , & self . core )
706
+ . field ( "cum_value" , & self . cum_value )
707
+ . finish ( )
708
+ }
709
+ }
710
+
672
711
impl < H > ValueBarAggregator < H >
673
712
where
674
713
H : FnMut ( Bar ) ,
@@ -826,7 +865,22 @@ where
826
865
skip_first_non_full_bar : bool ,
827
866
}
828
867
829
- #[ derive( Clone ) ]
868
+ impl < H : FnMut ( Bar ) > Debug for TimeBarAggregator < H > {
869
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
870
+ f. debug_struct ( stringify ! ( TimeBarAggregator ) )
871
+ . field ( "core" , & self . core )
872
+ . field ( "build_with_no_updates" , & self . build_with_no_updates )
873
+ . field ( "timestamp_on_close" , & self . timestamp_on_close )
874
+ . field ( "is_left_open" , & self . is_left_open )
875
+ . field ( "timer_name" , & self . timer_name )
876
+ . field ( "interval_ns" , & self . interval_ns )
877
+ . field ( "composite_bar_build_delay" , & self . composite_bar_build_delay )
878
+ . field ( "skip_first_non_full_bar" , & self . skip_first_non_full_bar )
879
+ . finish ( )
880
+ }
881
+ }
882
+
883
+ #[ derive( Clone , Debug ) ]
830
884
pub struct NewBarCallback < H : FnMut ( Bar ) > {
831
885
aggregator : Rc < RefCell < TimeBarAggregator < H > > > ,
832
886
}
0 commit comments