pub struct BotConfig {
pub name: String,
pub symbols: Vec<Symbol>,
pub shutdown_timeout: Duration,
pub install_signal_handler: bool,
pub market_bus_capacity: usize,
pub signal_bus_capacity: usize,
pub close_positions_on_shutdown: bool,
pub risk: RiskConfig,
pub per_symbol_risk: HashMap<Symbol, RiskConfig>,
pub per_class_risk: HashMap<AssetClass, RiskConfig>,
pub portfolio: PortfolioRiskConfig,
pub bracket_failure_policy: BracketFailurePolicy,
}Expand description
Configuration for a Bot.
Construct via BotConfig::builder. The builder validates every
field on BotConfigBuilder::build and returns Error::Config on
any violation — the framework never panics on bad config. Bot::new
does a final brain-count check on top.
§Example
use std::time::Duration;
use rustrade::BotConfig;
let config = BotConfig::builder()
.name("market-maker")
.symbols(["BTCUSDT", "ETHUSDT"])
.shutdown_timeout(Duration::from_secs(5))
.without_signal_handler() // tests + embedded use
.build()
.unwrap();
assert_eq!(config.name, "market-maker");
assert_eq!(config.symbols.len(), 2);Fields§
§name: StringHuman-readable name used in logs, tracing spans, and supervisor service identification.
symbols: Vec<Symbol>Symbols this bot trades. Every symbol gets a pre-seeded entry in the risk-state map and the position cache. Must be non-empty — the position cache and risk-state map would otherwise be empty, which is a silent footgun.
shutdown_timeout: DurationMaximum time to wait for services to drain on shutdown. Must be
> 0; the supervisor’s drain logic needs a non-zero deadline.
install_signal_handler: boolWhether the supervisor installs its own Ctrl-C / SIGTERM handler.
Disable when the host service drives shutdown via BotHandle::shutdown.
market_bus_capacity: usizeCapacity of the in-process market-data broadcast bus. Backed by
tokio::sync::broadcast, which has drop-oldest semantics: a
slow subscriber that falls behind by more than capacity events
sees RecvError::Lagged(n) and the oldest dropped events are
gone. Size this to absorb the worst-case latency between
publish and slowest subscriber’s recv.
signal_bus_capacity: usizeCapacity of the in-process signal broadcast bus. Same drop-oldest
semantics as market_bus_capacity. Typically smaller — signals
are emitted ~once per non-Hold decision, far less frequent than
market events.
close_positions_on_shutdown: boolOn shutdown, attempt to close any open position for each symbol
before exit, using ExchangeClient::close_position. Best-effort:
failures are logged but do not propagate.
risk: RiskConfigRisk-layer defaults applied to every configured symbol that has no
entry in Self::per_symbol_risk.
per_symbol_risk: HashMap<Symbol, RiskConfig>Per-symbol risk overrides. A symbol present here uses its own
RiskConfig (session-PnL cap, circuit breaker, and sizing) instead
of Self::risk — e.g. a tighter drawdown cap on a volatile alt, or
a larger size on a flagship symbol. Symbols absent here use the
default. Resolve with Self::resolve_risk.
per_class_risk: HashMap<AssetClass, RiskConfig>Per-AssetClass risk overrides. A symbol whose
InstrumentSpec reports a class present
here uses that class’s RiskConfig — unless a per-symbol override
also exists, which wins. Lets one bot apply crypto-perp / spot / FX /
futures rules side by side. See RiskConfig::preset_for for starting
presets and Self::resolve_risk for the precedence.
portfolio: PortfolioRiskConfigAccount-wide risk applied across all symbols: a daily-loss halt,
a max-concurrent-positions cap, and a gross-exposure cap. Complements
the per-symbol RiskConfig gates. Defaults to all-off (opt-in), so
a bot that doesn’t set it behaves exactly as before.
bracket_failure_policy: BracketFailurePolicyWhat to do when a bracket entry fills but its protective stop-loss
leg fails to place. Defaults to BracketFailurePolicy::CloseEntry:
the unprotected entry is closed with a reduce-only market order.
Implementations§
Source§impl BotConfig
impl BotConfig
Sourcepub fn builder() -> BotConfigBuilder
pub fn builder() -> BotConfigBuilder
Begin building a config with sensible defaults.
Sourcepub fn risk_for(&self, symbol: &Symbol) -> &RiskConfig
pub fn risk_for(&self, symbol: &Symbol) -> &RiskConfig
The effective RiskConfig for symbol, ignoring asset class: its
per-symbol override if set, else the bot-wide default (Self::risk).
Prefer Self::resolve_risk, which also honours per-class overrides.
Sourcepub fn resolve_risk(
&self,
symbol: &Symbol,
asset_class: AssetClass,
) -> &RiskConfig
pub fn resolve_risk( &self, symbol: &Symbol, asset_class: AssetClass, ) -> &RiskConfig
The effective RiskConfig for symbol of the given asset_class,
applying the precedence per-symbol → per-class → default. The
framework resolves asset_class from
ExchangeClient::instrument_spec at startup, so a multi-asset bot
gets the right rules per symbol without listing every one.