1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! # rustrade
//!
//! Open-source trading bot framework — the facade crate downstream
//! services depend on. Re-exports the core types, the supervisor, and the
//! risk primitives, and adds the [`Bot`] builder that wires them into a
//! single supervised runtime.
//!
//! # Quickstart
//!
//! ```rust,ignore
//! use std::sync::Arc;
//! use rustrade::{Bot, BotConfig};
//!
//! let bot = Bot::new(
//! BotConfig::builder().name("my-bot").symbol("BTCUSDT").build()?,
//! Arc::new(MyExchangeAdapter::new()),
//! vec![Arc::new(MyBrain::new())],
//! )?;
//! let handle = bot.handle();
//! // host can shutdown via handle.shutdown() at any time
//! bot.run_until_shutdown().await
//! ```
//!
//! # What this crate adds on top of the sub-crates
//!
//! - [`Bot`] / [`BotConfig`] / [`BotConfigBuilder`] — the embedding entry
//! point. Wraps a [`Supervisor`] and the framework-side services.
//! - [`BotHandle`] / [`BotHealth`] — cheap cloneable handle for host
//! services to query state and trigger shutdown without holding the
//! `Bot` itself.
//! - [`Bot::with_market_source`] / [`Bot::with_fill_source`] /
//! [`Bot::with_external_cancel`] — optional wirings for adapters and
//! host-driven shutdown.
//! - [`logging::init_tracing`] — opinionated default tracing subscriber.
//! Skippable; downstream services with their own subscriber don't use it.
//!
//! # Tokio runtime requirements
//!
//! `Bot::run_until_shutdown` must be awaited inside a **multi-thread
//! tokio runtime context**. Internally the supervisor calls
//! `tokio::spawn` for every service, and the framework expects the host's
//! shutdown to be cooperative (services watch a `CancellationToken`).
//! The simplest valid host is:
//!
//! ```rust,ignore
//! #[tokio::main(flavor = "multi_thread")]
//! async fn main() -> anyhow::Result<()> {
//! // ... build bot ...
//! bot.run_until_shutdown().await
//! }
//! ```
//!
//! Embedding into an existing runtime is supported — just spawn the bot
//! as a task and hold a [`BotHandle`] for control. See
//! `examples/embed-in-service/`.
//!
//! # Resource expectations
//!
//! - **Memory per active symbol:** a few hundred bytes for the position
//! cache entry plus the per-symbol `SymbolRisk` (a `SessionPnl` and a
//! `CircuitBreaker` whose ring buffer is bounded by `loss_limit`).
//! - **Channel buffers:** `market_bus_capacity` + `signal_bus_capacity`
//! slots per bus, each holding a clone of `MarketDataEvent` / `Signal`.
//! Backed by `tokio::sync::broadcast`, which has **drop-oldest**
//! semantics: slow subscribers see `RecvError::Lagged(n)` and miss
//! the oldest dropped events.
//! - **Expected shutdown time:** ≤ `shutdown_timeout` (default 30 s).
//! Well-behaved services drain in milliseconds; the timeout is the
//! worst-case ceiling, not the typical case.
//! - **Restart-after-crash latency:** bounded by the supervisor's
//! `rustrade_supervisor::BackoffConfig`. Defaults: 100 ms base delay,
//! 60 s cap, 10 retries within a 10-minute window before the circuit
//! breaker trips and the service terminates.
//!
//! # Module status
//!
//! | Module | Surface |
//! | ------------ | ---------------------------------------------------------- |
//! | `bot` | `Bot`, `BotConfig`, `BotConfigBuilder`, `RiskConfig` |
//! | `handle` | `BotHandle`, `BotHealth`, `record_trade_outcome` |
//! | `execution` | `ExecutionService` with full risk-gate pipeline |
//! | `services` | `MarketFeedService`, `FillRoutingService` |
//! | `logging` | `init_tracing` |
pub
pub
pub use ;
pub use ;
pub use JsonFileStore;
pub use ;
pub use ;
// Re-exports from sub-crates so downstream depends on `rustrade` only.
pub use ;
pub use ;
pub use ;