Skip to main content

Decision

Struct Decision 

Source
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: SignalType

What the brain decided to do (Buy / Sell / Hold / Close).

§confidence: f64

Confidence in [0.0, 1.0].

§size_hint: SizeHint

Optional suggested size.

§stop_price: Option<Price>

Optional suggested stop-loss price.

§take_profit_price: Option<Price>

Optional suggested take-profit price.

§order_kind: OrderKind

How 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: Value

Free-form brain metadata, used for logging and post-trade analysis.

Implementations§

Source§

impl Decision

Source

pub fn hold() -> Decision

Convenience: “no action”.

Source

pub fn buy(confidence: f64) -> Decision

Convenience: open or flip a long with the given confidence.

Source

pub fn sell(confidence: f64) -> Decision

Convenience: open or flip a short with the given confidence.

Source

pub fn close() -> Decision

Convenience: close the current position without reversing.

Source

pub fn with_stop(self, price: Price) -> Decision

Suggest a stop-loss price.

Source

pub fn with_take_profit(self, price: Price) -> Decision

Suggest a take-profit price.

Source

pub fn with_size_hint(self, hint: SizeHint) -> Decision

Override the default size hint.

Source

pub fn with_limit_price(self, price: Price) -> Decision

Request a resting limit entry at price (sets Decision::order_kind to OrderKind::Limit).

Source

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).

Source

pub fn with_metadata(self, metadata: Value) -> Decision

Attach free-form metadata for logging / post-hoc analysis.

Trait Implementations§

Source§

impl Clone for Decision

Source§

fn clone(&self) -> Decision

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 Decision

Source§

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

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

impl<'de> Deserialize<'de> for Decision

Source§

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

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

impl Serialize for Decision

Source§

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more