File tree Expand file tree Collapse file tree 6 files changed +65
-3
lines changed Expand file tree Collapse file tree 6 files changed +65
-3
lines changed Original file line number Diff line number Diff line change 1
1
[package ]
2
2
name = " trade_aggregation"
3
- version = " 12.0.1 "
3
+ version = " 12.0.2 "
4
4
authors = [
" MathisWellmann <[email protected] >" ]
5
5
edition = " 2021"
6
6
license-file = " LICENSE"
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ mod std_dev_sizes;
21
21
mod time_velocity;
22
22
mod trades;
23
23
mod volume;
24
+ mod volume_buys;
25
+ mod volume_sells;
24
26
mod weighted_price;
25
27
26
28
pub use average_price:: AveragePrice ;
@@ -43,6 +45,8 @@ pub use std_dev_sizes::StdDevSizes;
43
45
pub use time_velocity:: TimeVelocity ;
44
46
pub use trades:: Trades ;
45
47
pub use volume:: Volume ;
48
+ pub use volume_buys:: VolumeBuys ;
49
+ pub use volume_sells:: VolumeSells ;
46
50
pub use weighted_price:: WeightedPrice ;
47
51
48
52
#[ cfg( test) ]
Original file line number Diff line number Diff line change 1
1
use crate :: { CandleComponent , CandleComponentUpdate , TakerTrade } ;
2
2
3
- /// This 'CandleComponent' keeps track of the cumulative volume
3
+ /// This 'CandleComponent' keeps track of the cumulative volume of trades.
4
4
#[ derive( Debug , Default , Clone ) ]
5
5
#[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
6
6
pub struct Volume {
Original file line number Diff line number Diff line change
1
+ use crate :: { CandleComponent , CandleComponentUpdate , TakerTrade } ;
2
+
3
+ /// This 'CandleComponent' keeps track of the cumulative buy volume of trades.
4
+ #[ derive( Debug , Default , Clone ) ]
5
+ #[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
6
+ pub struct VolumeBuys {
7
+ buy_volume : f64 ,
8
+ }
9
+
10
+ impl CandleComponent < f64 > for VolumeBuys {
11
+ #[ inline( always) ]
12
+ fn value ( & self ) -> f64 {
13
+ self . buy_volume
14
+ }
15
+
16
+ #[ inline( always) ]
17
+ fn reset ( & mut self ) {
18
+ self . buy_volume = 0.0 ;
19
+ }
20
+ }
21
+
22
+ impl < T : TakerTrade > CandleComponentUpdate < T > for VolumeBuys {
23
+ #[ inline( always) ]
24
+ fn update ( & mut self , trade : & T ) {
25
+ if trade. size ( ) . is_sign_positive ( ) {
26
+ self . buy_volume += trade. size ( ) . abs ( )
27
+ }
28
+ }
29
+ }
Original file line number Diff line number Diff line change
1
+ use crate :: { CandleComponent , CandleComponentUpdate , TakerTrade } ;
2
+
3
+ /// This 'CandleComponent' keeps track of the cumulative volume of trades.
4
+ #[ derive( Debug , Default , Clone ) ]
5
+ #[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
6
+ pub struct VolumeSells {
7
+ sell_volume : f64 ,
8
+ }
9
+
10
+ impl CandleComponent < f64 > for VolumeSells {
11
+ #[ inline( always) ]
12
+ fn value ( & self ) -> f64 {
13
+ self . sell_volume
14
+ }
15
+
16
+ #[ inline( always) ]
17
+ fn reset ( & mut self ) {
18
+ self . sell_volume = 0.0 ;
19
+ }
20
+ }
21
+
22
+ impl < T : TakerTrade > CandleComponentUpdate < T > for VolumeSells {
23
+ #[ inline( always) ]
24
+ fn update ( & mut self , trade : & T ) {
25
+ if trade. size ( ) . is_sign_negative ( ) {
26
+ self . sell_volume += trade. size ( ) . abs ( )
27
+ }
28
+ }
29
+ }
Original file line number Diff line number Diff line change @@ -62,6 +62,6 @@ pub trait TakerTrade {
62
62
63
63
/// Number of shares or contracts in this trade.
64
64
/// A negative value indicates
65
- /// that the trade was executed on the bid (market sell order) .
65
+ /// that the trade was a sell order, taking liquidity from the bid .
66
66
fn size ( & self ) -> f64 ;
67
67
}
You can’t perform that action at this time.
0 commit comments