Crates.io | botcore |
lib.rs | botcore |
version | 1.0.10 |
created_at | 2025-02-03 22:24:33.587928+00 |
updated_at | 2025-05-21 11:22:02.598741+00 |
description | Production-grade asynchronous bot engine with enterprise observability features |
homepage | |
repository | https://github.com/ss-sonic/botcore |
max_upload_size | |
id | 1541162 |
size | 119,504 |
A flexible and efficient bot engine framework for building event-driven bots in Rust.
botcore
is a production-grade, asynchronous engine for building robust event-driven bots in Rust. It offers enterprise-level observability features, a flexible architecture, and type-safe APIs that enable developers to efficiently create, test, and deploy trading bots, arbitrage systems, and other event-reactive applications.
🚀 High Performance
🔧 Modular Architecture
📊 Observability
🛠️ Developer Experience
🔄 Event Processing
Add botcore
to your project using cargo:
cargo add botcore --features metrics
The framework is built around three core components:
Event sources that feed data into your bot:
Processing logic that determines bot behavior:
Action handlers that effect changes:
use botcore::engine::Engine;
use botcore::types::{Collector, Strategy, Executor};
use botcore::Result;
use tracing::{error, info};
// 1. Define your types
#[derive(Debug, Clone)]
struct MyEvent {
data: String,
}
#[derive(Debug, Clone)]
struct MyAction {
command: String,
}
// 2. Implement a collector
#[async_trait]
impl Collector<MyEvent> for MyCollector {
async fn get_event_stream(&self) -> Result<CollectorStream<'_, MyEvent>> {
// Return your event stream
}
}
// 3. Implement a strategy
#[async_trait]
impl Strategy<MyEvent, MyAction> for MyStrategy {
async fn process_event(&mut self, event: MyEvent) -> Vec<MyAction> {
// Process events and return actions
}
}
// 4. Implement an executor
#[async_trait]
impl Executor<MyAction> for MyExecutor {
async fn execute(&self, action: MyAction) -> Result<()> {
// Execute actions
Ok(())
}
}
// 5. Run the engine
#[tokio::main]
async fn main() -> Result<()> {
let mut engine = Engine::new()
.with_event_channel_capacity(1024)
.with_action_channel_capacity(1024);
engine.add_collector(Box::new(MyCollector));
engine.add_strategy(Box::new(MyStrategy));
engine.add_executor(Box::new(MyExecutor));
match engine.run().await {
Ok(mut set) => {
while let Some(res) = set.join_next().await {
match res {
Ok(res) => {
info!("res: {:?}", res);
}
Err(e) => {
info!("error: {:?}", e);
}
}
}
}
Err(e) => {
error!("Engine run error: {:?}", e);
}
}
Ok(())
}
The examples/
directory contains working implementations:
block_trader.rs
: A bot that executes trades based on blockchain events
cargo run --example block_trader
botcore
automatically collects the following Prometheus metrics:
Metric | Type | Description |
---|---|---|
event_processing_latency |
Histogram | Time taken to process events |
action_execution_latency |
Histogram | Time taken to execute actions |
event_queue_size |
Gauge | Current number of pending events |
action_queue_size |
Gauge | Current number of pending actions |
error_count |
Counter | Total number of errors encountered |
events_processed_total |
Counter | Total number of events processed |
actions_executed_total |
Counter | Total number of actions executed |
The engine can be configured through builder methods:
let engine = Engine::new()
.with_event_channel_capacity(1024)
.with_action_channel_capacity(1024)
botcore
provides a comprehensive error type system:
Event Design
Strategy Implementation
Execution
We welcome contributions! Please see our Contributing Guide for details on:
This project is licensed under the MIT License - see the LICENSE file for details.