#[non_exhaustive]pub struct Alert {Show 14 fields
pub id: Option<AlertId>,
pub symbol: String,
pub name: String,
pub watchlist: Option<String>,
pub timeframe: Option<Timeframe>,
pub inputs: Option<Box<AlertInputs>>,
pub source: AlertSource,
pub additional_conditions: Vec<AlertRule>,
pub condition: AlertCondition,
pub frequency: AlertFrequency,
pub expires: Option<DateTime<Utc>>,
pub schedule: Option<Box<NotificationSchedule>>,
pub message: String,
pub status: AlertStatus,
}Expand description
An alert as the host stores and evaluates it. The library creates and edits alerts through
Alerts::save and shows the ones the host pushes. It evaluates
them only through the host’s service; AlertEngine (feature alert-engine) is one.
It is serialisable so that a server can store and evaluate the same type. Fields added later
will carry #[serde(default)], so alerts stored by an earlier version keep loading. A
condition, frequency or status added later does not load in an earlier version.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: Option<AlertId>None for an alert the user is creating; the host assigns the id.
symbol: StringThe symbol whose bars supply the sources, unless watchlist names the subject.
name: StringUser-facing name, independent of the notification message.
watchlist: Option<String>Host watchlist identifier. When present, evaluate independently on each member symbol.
timeframe: Option<Timeframe>The timeframe whose bars the alert is evaluated on. None for an alert that has not been
fixed to one yet; AlertEngine fixes it to the first timeframe it evaluates the alert on.
inputs: Option<Box<AlertInputs>>Independent creation inputs, retained through edits, copies and storage. Legacy alerts without these inputs cannot recover a study from a chart-local identifier.
source: AlertSourceValue tested by the first condition.
additional_conditions: Vec<AlertRule>Additional conditions, all required on the same bar as the first condition.
condition: AlertConditionWhen the alert fires.
frequency: AlertFrequencyWhether the alert fires once or on every occurrence.
expires: Option<DateTime<Utc>>The alert expires at this time; None never expires.
schedule: Option<Box<NotificationSchedule>>When the alert may trigger; None allows any time. Outside the schedule, evaluation keeps
observing values for crossings without firing or consuming an occurrence.
message: StringText the host shows or sends when the alert fires. Alert::expand_message fills in the
placeholders {{symbol}}, {{close}} and so on when it fires.
status: AlertStatusWhere the alert stands, as the host reports it.
Implementations§
Source§impl Alert
impl Alert
Sourcepub fn new(symbol: impl Into<String>, condition: AlertCondition) -> Self
pub fn new(symbol: impl Into<String>, condition: AlertCondition) -> Self
An active alert on symbol with no id, no expiry and no message. Frequency is Once
for bar conditions and EveryTime for strategy fills.
Source§impl Alert
impl Alert
Sourcepub fn sources(&self) -> impl Iterator<Item = &AlertSource>
pub fn sources(&self) -> impl Iterator<Item = &AlertSource>
Every input tested by the alert, including comparison outputs and additional rules.
Sourcepub fn expand_message(
&self,
symbol: &str,
timeframe: Timeframe,
bar: &Bar,
value: impl Fn(&AlertSource) -> Option<f64>,
) -> String
pub fn expand_message( &self, symbol: &str, timeframe: Timeframe, bar: &Bar, value: impl Fn(&AlertSource) -> Option<f64>, ) -> String
The message with its placeholders filled in from the trigger: {{symbol}} and
{{timeframe}} as given, {{time}} the open time of bar in RFC 3339, {{open}},
{{high}}, {{low}}, {{close}} and {{volume}} of bar, {{value}} the value of the
alert’s source and {{output_N}} the value of output N of the study the source names,
empty if the source is not a study. value gives the value of a source at the bar. A value
that is missing or not finite becomes empty text, a number is written in the shortest form
that reads back the same, and a placeholder the alert does not know stays as written.
use egui_charts::model::{Alert, AlertCondition, Bar, Timeframe};
let mut alert = Alert::new("AAPL", AlertCondition::Above(100.0));
alert.message = "{{symbol}} closed at {{close}} on {{timeframe}}".into();
let time = chrono::DateTime::from_timestamp(0, 0).unwrap();
let bar = Bar::new(time, 99.0, 102.0, 98.0, 101.5, 1000.0);
assert_eq!(
alert.expand_message("AAPL", Timeframe::Min5, &bar, |_| None),
"AAPL closed at 101.5 on 5min"
);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Alert
impl<'de> Deserialize<'de> for Alert
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Alert
Auto Trait Implementations§
impl Freeze for Alert
impl RefUnwindSafe for Alert
impl Send for Alert
impl Sync for Alert
impl Unpin for Alert
impl UnsafeUnpin for Alert
impl UnwindSafe for Alert
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more