nautilus_indicators/
indicator.rs1use std::fmt::Debug;
19
20use nautilus_model::{
21 data::{Bar, OrderBookDelta, OrderBookDeltas, OrderBookDepth10, QuoteTick, TradeTick},
22 orderbook::OrderBook,
23};
24
25const IMPL_ERR: &str = "is not implemented for";
26
27#[allow(unused_variables)]
28pub trait Indicator {
29 fn name(&self) -> String;
30
31 fn has_inputs(&self) -> bool;
32
33 fn initialized(&self) -> bool;
34
35 fn handle_delta(&mut self, delta: &OrderBookDelta) {
36 panic!("`handle_delta` {IMPL_ERR} `{}`", self.name());
37 }
38
39 fn handle_deltas(&mut self, deltas: &OrderBookDeltas) {
40 panic!("`handle_deltas` {IMPL_ERR} `{}`", self.name());
41 }
42
43 fn handle_depth(&mut self, depth: &OrderBookDepth10) {
44 panic!("`handle_depth` {IMPL_ERR} `{}`", self.name());
45 }
46
47 fn handle_book(&mut self, book: &OrderBook) {
48 panic!("`handle_book_mbo` {IMPL_ERR} `{}`", self.name());
49 }
50
51 fn handle_quote(&mut self, quote: &QuoteTick) {
52 panic!("`handle_quote_tick` {IMPL_ERR} `{}`", self.name());
53 }
54
55 fn handle_trade(&mut self, trade: &TradeTick) {
56 panic!("`handle_trade_tick` {IMPL_ERR} `{}`", self.name());
57 }
58
59 fn handle_bar(&mut self, bar: &Bar) {
60 panic!("`handle_bar` {IMPL_ERR} `{}`", self.name());
61 }
62
63 fn reset(&mut self);
64}
65
66pub trait MovingAverage: Indicator {
67 fn value(&self) -> f64;
68 fn count(&self) -> usize;
69 fn update_raw(&mut self, value: f64);
70}
71
72impl Debug for dyn Indicator + Send {
73 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
74 write!(f, "Indicator {{ ... }}")
76 }
77}
78
79impl Debug for dyn MovingAverage + Send {
80 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
81 write!(f, "MovingAverage()")
83 }
84}