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) -> anyhow::Result<()> {
57 anyhow::bail!("`handle_quote_tick` {IMPL_ERR} `{}`", self.name());
58 }
59
60 fn handle_trade(&mut self, trade: &TradeTick) {
61 panic!("`handle_trade_tick` {IMPL_ERR} `{}`", self.name());
62 }
63
64 fn handle_bar(&mut self, bar: &Bar) {
65 panic!("`handle_bar` {IMPL_ERR} `{}`", self.name());
66 }
67
68 fn reset(&mut self);
69}
70
71pub trait MovingAverage: Indicator {
72 fn value(&self) -> f64;
73 fn count(&self) -> usize;
74 fn update_raw(&mut self, value: f64);
75}
76
77impl Debug for dyn Indicator + Send {
78 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
79 write!(f, "Indicator {{ ... }}")
81 }
82}
83
84impl Debug for dyn MovingAverage + Send {
85 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
86 write!(f, "MovingAverage()")
88 }
89}