pub struct StrategyContext<'a> { /* private fields */ }Expand description
What a Strategy sees at a decision: the bars up to it and the open position. It places
and cancels working orders by id.
An order placed with the id of a working order replaces it, keeping its original place among orders reached at the same point. Working orders stay until they fill or are cancelled. A quantity must be positive and finite and a price finite; an order with any other is ignored.
Implementations§
Source§impl StrategyContext<'_>
impl StrategyContext<'_>
Sourcepub fn bars(&self) -> &[Bar]
pub fn bars(&self) -> &[Bar]
Chart bars through this decision, oldest first. Live tick decisions include the forming
bar; intrabar fill callbacks exclude the unfinished bar. See Self::is_forming_bar.
Sourcepub fn position(&self) -> f64
pub fn position(&self) -> f64
The open position: positive when long, negative when short, 0 when flat.
Sourcepub fn price(&self) -> f64
pub fn price(&self) -> f64
The latest close on a bar decision, or the execution price immediately after a fill.
Sourcepub fn equity(&self) -> f64
pub fn equity(&self) -> f64
Account equity marked at Self::price, after any fill commission.
Sourcepub fn is_after_fill(&self) -> bool
pub fn is_after_fill(&self) -> bool
Whether this is a recalculation immediately after a fill rather than a closed bar.
Sourcepub fn is_forming_bar(&self) -> bool
pub fn is_forming_bar(&self) -> bool
Whether the current decision belongs to a still-forming live bar. Fill callbacks
continue to exclude that bar from bars, even while this flag is true.
Sourcepub fn entry(
&mut self,
id: impl Into<String>,
side: OrderSide,
quantity: impl Into<Option<f64>>,
order_type: OrderType,
)
pub fn entry( &mut self, id: impl Into<String>, side: OrderSide, quantity: impl Into<Option<f64>>, order_type: OrderType, )
Places an entry of quantity on side. Against an open position on the other side it
closes that position first, then opens quantity on side; on the same side it adds.
Pass None to use the settings’ order size, calculated when the order fills.
Sourcepub fn exit(
&mut self,
id: impl Into<String>,
quantity: Option<f64>,
take_profit: Option<f64>,
stop_loss: Option<f64>,
)
pub fn exit( &mut self, id: impl Into<String>, quantity: Option<f64>, take_profit: Option<f64>, stop_loss: Option<f64>, )
Places an exit that reduces the open position by quantity, or closes it with None. It
fills at the take_profit limit or the stop_loss stop, whichever the price reaches
first, or at market without either. An exit only reduces the position open when it is
placed or, placed while flat, the position the next entry opens; once that position is
closed or reversed, the exit is cancelled.
Sourcepub fn exit_relative(
&mut self,
id: impl Into<String>,
side: OrderSide,
take_profit: f64,
stop_loss: f64,
)
pub fn exit_relative( &mut self, id: impl Into<String>, side: OrderSide, take_profit: f64, stop_loss: f64, )
Brackets entries on side at positive price distances from their average fill price.
The bracket can precede its entry and protects it on its execution bar, including gaps
and slippage. Adding an entry moves the bracket with the position’s average price.
It closes the whole position, then protects any queued entries on that side. Without
a queued entry it is cancelled when the position closes or reverses.
Auto Trait Implementations§
impl<'a> !UnwindSafe for StrategyContext<'a>
impl<'a> Freeze for StrategyContext<'a>
impl<'a> RefUnwindSafe for StrategyContext<'a>
impl<'a> Send for StrategyContext<'a>
impl<'a> Sync for StrategyContext<'a>
impl<'a> Unpin for StrategyContext<'a>
impl<'a> UnsafeUnpin for StrategyContext<'a>
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> 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