Skip to main content

bot_engine/
lib.rs

1//! Bot Engine: order manager, inventory ledger, event routing, and polling.
2//!
3//! This crate contains the runtime that:
4//! - Manages order state (in-memory source of truth)
5//! - Tracks inventory/balances with reservations
6//! - Routes events to strategies
7//! - Handles rate limiting and backoff
8//! - Manages exchange health state machine
9//! - Polling loop for fills and quotes (native only)
10//! - Trade syncing to upstream API for PnL tracking (native only)
11
12// Core modules (always available)
13pub mod config;
14pub mod context;
15pub mod engine;
16pub mod inventory;
17pub mod order_manager;
18pub mod performance_metrics;
19pub mod poll_guard;
20
21// Simulation layer: margin-aware accounting for paper/backtest (always available)
22pub mod simulation;
23
24// Testing and paper trading infrastructure (always available)
25pub mod testing;
26
27// Platform compatibility layer (WASM + native)
28pub mod compat;
29
30// Native-only modules (require tokio/reqwest)
31#[cfg(feature = "native")]
32pub mod account_syncer;
33#[cfg(feature = "native")]
34pub mod sync_traits;
35#[cfg(feature = "native")]
36pub mod trade_syncer;
37
38// Runner module (core is WASM-compatible, spawn functions are native-only)
39pub mod runner;
40
41// WASM API module (only available with wasm feature)
42#[cfg(feature = "wasm")]
43pub mod wasm_api;
44
45// Re-exports (core)
46pub use config::*;
47pub use context::*;
48pub use engine::*;
49pub use inventory::*;
50pub use order_manager::*;
51pub use performance_metrics::*;
52pub use poll_guard::*;
53
54// Re-exports (native-only)
55#[cfg(feature = "native")]
56pub use account_syncer::{
57    AccountSyncer, AccountSyncerConfig, ClearingHouseStateRequest,
58    PositionInfo as AccountPositionInfo, SyncError, SyncResponse as AccountSyncerResponse,
59    SyncResult as AccountSyncerResult,
60};
61#[cfg(feature = "native")]
62pub use sync_traits::{AccountSync, AccountSyncResult, TradeSync, TradeSyncResult};
63#[cfg(feature = "native")]
64pub use trade_syncer::{
65    SyncRequest as TradeSyncRequest, SyncResponse as TradeSyncerResponse,
66    SyncResult as TradeSyncerResult, SyncedInfo, TradeSyncer, TradeSyncerConfig, UpstreamTrade,
67};
68
69// Re-exports (runner - core types always available, spawn functions native-only)
70#[cfg(feature = "native")]
71pub use runner::{spawn_runner, spawn_runner_with_syncer};
72pub use runner::{BacktestResult, EngineRunner, PollResult, RunnerConfig, TradingStats};
73
74// Re-export testing utilities (always available)
75pub use testing::{FillSimulator, MockQuoteSource, PendingOrder, QuoteSource, SimulatedFill};
76#[cfg(feature = "native")]
77pub use testing::{MockAccountSyncer, MockTradeSyncer};
78pub use testing::{MockExchange, MockKnobs, OrderFailMode, PaperExchange}; // Re-export mock syncers (native-only, they depend on sync_traits)