Skip to main content

Alert

Struct Alert 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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: String

The symbol whose bars supply the sources, unless watchlist names the subject.

§name: String

User-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: AlertSource

Value tested by the first condition.

§additional_conditions: Vec<AlertRule>

Additional conditions, all required on the same bar as the first condition.

§condition: AlertCondition

When the alert fires.

§frequency: AlertFrequency

Whether 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: String

Text 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: AlertStatus

Where the alert stands, as the host reports it.

Implementations§

Source§

impl Alert

Source

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

Source

pub fn sources(&self) -> impl Iterator<Item = &AlertSource>

Every input tested by the alert, including comparison outputs and additional rules.

Source

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"
);
Source§

impl Alert

Source

pub fn is_valid(&self) -> bool

Validate user input before handing it to host storage or evaluation.

Trait Implementations§

Source§

impl Clone for Alert

Source§

fn clone(&self) -> Alert

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Alert

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Alert

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Alert

Source§

fn eq(&self, other: &Alert) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Alert

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T
where T: Send + Sync + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.