Skip to content

Commit 9f58cef

Browse files
committed
✨ added cum vol to info_bar
1 parent 296430f commit 9f58cef

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/candle_set.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub struct CandleSet {
1313
pub variation: f64,
1414
pub average: f64,
1515
pub last_price: f64,
16+
pub cumulative_volume: f64,
1617
}
1718

1819
impl CandleSet {
@@ -26,6 +27,7 @@ impl CandleSet {
2627
variation: 0.0,
2728
average: 0.0,
2829
last_price: 0.0,
30+
cumulative_volume: 0.0,
2931
};
3032

3133
cs.set_candles(candles);
@@ -44,6 +46,14 @@ impl CandleSet {
4446
self.compute_variation();
4547
self.compute_average();
4648
self.compute_last_price();
49+
self.compute_cumulative_volume();
50+
}
51+
52+
fn compute_cumulative_volume(&mut self) {
53+
self.cumulative_volume = self
54+
.candles
55+
.iter()
56+
.fold(0.0, |acc, candle| acc + candle.volume.unwrap_or_default());
4757
}
4858

4959
fn compute_last_price(&mut self) {

src/info_bar.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ impl InfoBar {
4343
};
4444

4545
output_str += &format!(
46-
"{:>width$} | Price: {price} | Highest: {high} | Lowest: {low} | Var.: {var} | Avg.: {avg} │",
46+
"{:>width$} | Price: {price} | Highest: {high} | Lowest: {low} | Var.: {var} | Avg.: {avg} │ Cum. Vol: {vol}",
4747
&self.name,
4848
width = YAxis::WIDTH as usize + 3,
4949
high = format!("{:.2}", main_set.max_price).green().bold(),
5050
low = format!("{:.2}", main_set.min_price).red().bold(),
5151
var = format!("{} {:>+.2}%", variation_output.0, main_set.variation).color(variation_output.1).bold(),
5252
avg = avg_format,
5353
price = format!("{:.2}", main_set.last_price).green().bold(),
54+
vol = format!("{:.0}", main_set.cumulative_volume).green().bold(),
5455
);
5556

5657
output_str

0 commit comments

Comments
 (0)