pub struct Decision {
pub signal: SignalType,
pub confidence: f64,
pub size_hint: SizeHint,
pub stop_price: Option<Price>,
pub take_profit_price: Option<Price>,
pub order_kind: OrderKind,
pub limit_price: Option<Price>,
pub metadata: Value,
}Expand description
A brain’s decision on a single market event.
signal is always present; the other fields are hints and metadata that
the execution and risk layers may or may not use.
§Example
use rustrade_core::{Decision, Price, SizeHint};
// The four constructor shapes the framework uses internally.
let _hold = Decision::hold();
let _close = Decision::close();
let _buy = Decision::buy(0.8);
let _sell = Decision::sell(0.6);
// Chain stop / take-profit / size hints / metadata.
let decision = Decision::buy(0.9)
.with_stop(Price(95.0))
.with_take_profit(Price(110.0))
.with_size_hint(SizeHint::MarginFraction(0.5))
.with_metadata(serde_json::json!({"reason": "ema-cross"}));
assert_eq!(decision.stop_price, Some(Price(95.0)));
assert_eq!(decision.take_profit_price, Some(Price(110.0)));§Entry order kind
By default an entry executes as a OrderKind::Market order. A brain
can request a resting or time-in-force variant via
Decision::with_limit_price (limit) or Decision::with_order_kind
(post-only / IOC / FOK). The execution layer gates non-trivial kinds on
the adapter’s Capability — an unsupported kind
blocks the order rather than silently downgrading it (which would change
fill / fee semantics). Close decisions always execute as reduce-only
market orders regardless of these fields.
Fields§
§signal: SignalTypeWhat the brain decided to do (Buy / Sell / Hold / Close).
confidence: f64Confidence in [0.0, 1.0].
size_hint: SizeHintOptional suggested size.
stop_price: Option<Price>Optional suggested stop-loss price.
take_profit_price: Option<Price>Optional suggested take-profit price.
order_kind: OrderKindHow the entry order should execute. Defaults to
OrderKind::Market. Ignored for Close decisions.
limit_price: Option<Price>Limit price for non-market entries. Used by
OrderKind::Limit / OrderKind::PostOnly / OrderKind::Ioc
/ OrderKind::Fok; if absent for those kinds the execution layer
falls back to the triggering event’s price and logs a warning.
metadata: ValueFree-form brain metadata, used for logging and post-trade analysis.
Implementations§
Source§impl Decision
impl Decision
Sourcepub fn buy(confidence: f64) -> Decision
pub fn buy(confidence: f64) -> Decision
Convenience: open or flip a long with the given confidence.
Sourcepub fn sell(confidence: f64) -> Decision
pub fn sell(confidence: f64) -> Decision
Convenience: open or flip a short with the given confidence.
Sourcepub fn with_take_profit(self, price: Price) -> Decision
pub fn with_take_profit(self, price: Price) -> Decision
Suggest a take-profit price.
Sourcepub fn with_size_hint(self, hint: SizeHint) -> Decision
pub fn with_size_hint(self, hint: SizeHint) -> Decision
Override the default size hint.
Sourcepub fn with_limit_price(self, price: Price) -> Decision
pub fn with_limit_price(self, price: Price) -> Decision
Request a resting limit entry at price (sets
Decision::order_kind to OrderKind::Limit).
Sourcepub fn with_order_kind(self, kind: OrderKind) -> Decision
pub fn with_order_kind(self, kind: OrderKind) -> Decision
Set the entry order kind explicitly — e.g. OrderKind::PostOnly,
OrderKind::Ioc, OrderKind::Fok. For any non-market kind also
set a limit via Self::with_limit_price (or the execution layer
falls back to the event price).
Sourcepub fn with_metadata(self, metadata: Value) -> Decision
pub fn with_metadata(self, metadata: Value) -> Decision
Attach free-form metadata for logging / post-hoc analysis.