Skip to main content

Module brain

Module brain 

Source
Expand description

The Brain trait — rustrade’s central abstraction.

A Brain is the strategic layer of a trading bot: it consumes market events and outputs Decisions. Everything else in rustrade (supervisor, exchange client, risk layer, execution) is plumbing around this one trait.

§Why a single trait?

Trading bots come in many flavours — indicator-based, ML-based, neuromorphic, hybrid. The common contract is: “given market state, tell me what to do.” Encoding that contract as one narrow trait means:

  • A rule-based SarBrain and a 10-million-parameter NeuromorphicBrain are interchangeable to the rest of the framework.
  • Backtesting and live trading share the same brain implementation.
  • You can run multiple brains in parallel (e.g. A/B or ensemble) by composing them in an outer Brain impl.

§What Brain does NOT do

A Brain does not:

  • Place orders directly — it returns a Decision; the execution layer decides whether to act.
  • Manage positions — on_position_change is informational only.
  • Do risk sizing — it may suggest size via SizeHint, but the risk layer has the final say.
  • Own the indicator state externally — that’s a brain-internal concern. Two different brains can maintain entirely different indicator stacks.

Structs§

BrainHealth
Reported health of a Brain. Surfaces to the supervisor’s health endpoint.
Decision
A brain’s decision on a single market event.

Enums§

SizeHint
How large the brain wants the next order to be. The risk layer can honour, scale down, or reject this hint.

Traits§

Brain
The strategic layer of a trading bot.