flowsurface_data/chart/kline/
bar.rs1use super::footprint::{ClusterKind, KlineTrades};
2use super::poc::NPoc;
3use crate::aggr::time::DataPoint;
4use exchange::{
5 Kline, Trade, UnixMs,
6 unit::price::{Price, PriceStep},
7 unit::qty::Qty,
8};
9
10#[derive(Clone)]
11pub struct KlineDataPoint {
12 pub kline: Kline,
13 pub footprint: KlineTrades,
14}
15
16impl KlineDataPoint {
17 pub fn max_cluster_qty(&self, cluster_kind: ClusterKind, highest: Price, lowest: Price) -> Qty {
18 self.footprint
19 .max_cluster_qty(cluster_kind, highest, lowest)
20 }
21
22 pub fn add_trade(&mut self, trade: &Trade, step: PriceStep) {
23 self.footprint.add_trade_to_nearest_bin(trade, step);
24 }
25
26 pub fn poc_price(&self) -> Option<Price> {
27 self.footprint.poc_price()
28 }
29
30 pub fn set_poc_status(&mut self, status: NPoc) {
31 self.footprint.set_poc_status(status);
32 }
33
34 pub fn clear_trades(&mut self) {
35 self.footprint.clear();
36 }
37
38 pub fn calculate_poc(&mut self) {
39 self.footprint.calculate_poc();
40 }
41
42 pub fn last_trade_time(&self) -> Option<UnixMs> {
43 self.footprint.last_trade_t()
44 }
45
46 pub fn first_trade_time(&self) -> Option<UnixMs> {
47 self.footprint.first_trade_t()
48 }
49
50 pub fn is_directional(&self) -> bool {
52 !self.footprint.trades.is_empty() || self.kline.volume.is_directional()
53 }
54}
55
56impl DataPoint for KlineDataPoint {
57 fn add_trade(&mut self, trade: &Trade, step: PriceStep) {
58 self.add_trade(trade, step);
59 }
60
61 fn clear_trades(&mut self) {
62 self.clear_trades();
63 }
64}