Skip to main content

StrategyEvent

Enum StrategyEvent 

pub enum StrategyEvent {
    Config {
        initial_capital: f64,
        commission_type: CommissionType,
        commission_value: f64,
        margin_long: f64,
        margin_short: f64,
        slippage: f64,
        pyramiding: u32,
        risk_free_rate: f64,
        process_orders_on_close: bool,
        calc_on_order_fills: bool,
        close_entries_rule: CloseEntriesRule,
    },
    OrderSubmitted {
        id: String,
        direction: Direction,
        order_type: OrderType,
        quantity: f64,
        comment: String,
    },
    OrderFilled {
        id: String,
        direction: Direction,
        price: f64,
        quantity: f64,
        commission: f64,
        comment: String,
    },
    OrderCancelled {
        id: String,
    },
    TradeOpened {
        entry_id: String,
        entry_comment: String,
        direction: Direction,
        entry_price: f64,
        quantity: f64,
        commission: f64,
        bar_index: usize,
        bar_time: i64,
    },
    TradeClosed {
Show 13 fields entry_id: String, exit_id: String, exit_comment: String, exit_price: f64, profit: f64, profit_percent: f64, max_runup: f64, max_runup_percent: f64, max_drawdown: f64, max_drawdown_percent: f64, commission: f64, bar_index: usize, bar_time: i64,
}, OpenTradeUpdated { entry_id: String, profit: f64, profit_percent: f64, max_runup: f64, max_runup_percent: f64, max_drawdown: f64, max_drawdown_percent: f64, }, EquitySnapshot { equity: f64, buy_hold_equity: f64, }, DailyReturn { date: i32, return_percent: f64, }, MarginCall { direction: Direction, position_size: f64, liquidation_price: f64, }, RiskFlatten { reason: String, }, }
Expand description

Events emitted by the strategy engine during execution.

These events can be consumed by a StrategyAccumulator to reconstruct a full StrategyReport.

Variants§

§

Config

Strategy configuration snapshot, emitted once on the first bar.

Fields

§initial_capital: f64

Starting cash.

§commission_type: CommissionType

Commission calculation mode.

§commission_value: f64

Commission amount.

§margin_long: f64

Long margin percentage.

§margin_short: f64

Short margin percentage.

§slippage: f64

Slippage in ticks.

§pyramiding: u32

Maximum entries in the same direction.

§risk_free_rate: f64

Annual risk-free rate for Sharpe / Sortino.

§process_orders_on_close: bool

Fill orders at bar close instead of next open.

§calc_on_order_fills: bool

Re-execute script on each order fill.

§close_entries_rule: CloseEntriesRule

Entry close rule.

§

OrderSubmitted

An order has been submitted.

Fields

§id: String

Order identifier.

§direction: Direction

Order direction.

§order_type: OrderType

Order type (market, limit, stop, stop-limit).

§quantity: f64

Order quantity.

§comment: String

User comment.

§

OrderFilled

An order has been filled.

Fields

§id: String

Order identifier.

§direction: Direction

Fill direction.

§price: f64

Fill price.

§quantity: f64

Fill quantity (unsigned).

§commission: f64

Commission charged.

§comment: String

User comment.

§

OrderCancelled

An order has been cancelled.

Fields

§id: String

Order identifier.

§

TradeOpened

A new position has been opened.

Fields

§entry_id: String

Entry order identifier.

§entry_comment: String

Entry order comment.

§direction: Direction

Trade direction.

§entry_price: f64

Entry fill price.

§quantity: f64

Position size.

§commission: f64

Commission charged at entry.

§bar_index: usize

Zero-based bar index of the entry fill.

§bar_time: i64

Bar time of the entry fill (milliseconds since Unix epoch).

§

TradeClosed

A position has been closed.

Fields

§entry_id: String

Entry order identifier (matches TradeOpened::entry_id).

§exit_id: String

Exit order identifier.

§exit_comment: String

Exit order comment.

§exit_price: f64

Exit fill price.

§profit: f64

Realized profit (after commission).

§profit_percent: f64

Realized profit as percentage.

§max_runup: f64

Maximum favorable excursion.

§max_runup_percent: f64

Maximum favorable excursion as percentage.

§max_drawdown: f64

Maximum adverse excursion.

§max_drawdown_percent: f64

Maximum adverse excursion as percentage.

§commission: f64

Total commission (entry + exit).

§bar_index: usize

Zero-based bar index of the exit fill.

§bar_time: i64

Bar time of the exit fill (milliseconds since Unix epoch).

§

OpenTradeUpdated

Per-bar update of an open trade’s unrealized P&L and excursions.

Static fields (direction, entry_price, quantity, commission) are available from the corresponding TradeOpened.

Fields

§entry_id: String

Entry order identifier (matches TradeOpened::entry_id).

§profit: f64

Current unrealized profit.

§profit_percent: f64

Current unrealized profit as percentage.

§max_runup: f64

Maximum favorable excursion so far.

§max_runup_percent: f64

Maximum favorable excursion as percentage.

§max_drawdown: f64

Maximum adverse excursion so far.

§max_drawdown_percent: f64

Maximum adverse excursion as percentage.

§

EquitySnapshot

Per-bar equity snapshot for curve reconstruction.

The drawdown curve can be derived by tracking peak equity: drawdown = peak_equity - equity.

Fields

§equity: f64

Total equity.

§buy_hold_equity: f64

Buy-and-hold equity.

§

DailyReturn

Daily return for Sharpe / Sortino calculation.

Fields

§date: i32

Date as YYYYMMDD integer.

§return_percent: f64

Net profit percentage as of this date.

§

MarginCall

Margin call event.

Fields

§direction: Direction

Position direction.

§position_size: f64

Position size at time of call.

§liquidation_price: f64

Liquidation price.

§

RiskFlatten

Risk-management forced liquidation.

Fields

§reason: String

Human-readable reason for the flatten.

Trait Implementations§

§

impl Clone for StrategyEvent

§

fn clone(&self) -> StrategyEvent

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for StrategyEvent

§

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

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for StrategyEvent

§

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

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

impl Serialize for StrategyEvent

§

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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
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> 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> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

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