botcore
A flexible and efficient bot engine framework for building event-driven bots in Rust.
Overview
botcore
is a high-performance, type-safe framework for building event-driven bots in Rust. It provides a modular architecture that makes it easy to create, test, and maintain bot applications that can react to various events in real-time.
Features
-
🚀 High Performance
- Built on top of Tokio for maximum concurrency
- Efficient event processing pipeline
- Configurable channel capacities for backpressure control
-
🔧 Modular Architecture
- Plug-and-play components
- Easy to extend and customize
- Clear separation of concerns
-
📊 Observability
- Built-in Prometheus metrics
- Performance monitoring
- Error tracking and reporting
-
🛠️ Developer Experience
- Type-safe API design
- Comprehensive documentation
- Example implementations
- Clear error messages
-
🔄 Event Processing
- Flexible event collection
- Customizable processing strategies
- Reliable action execution
- State management utilities
Installation
Add botcore
to your project using cargo:
Architecture
The framework is built around three core components:
1. Collectors
Event sources that feed data into your bot:
- Blockchain event listeners
- WebSocket API clients
- Database change streams
- Message queues
- File system watchers
2. Strategies
Processing logic that determines bot behavior:
- State management
- Decision making
- Event filtering
- Action generation
- Error handling
3. Executors
Action handlers that effect changes:
- Transaction submission
- API calls
- Database operations
- Notifications
- External system integration
Quick Start
use Engine;
use ;
use Result;
// 1. Define your types
// 2. Implement a collector
// 3. Implement a strategy
// 4. Implement an executor
// 5. Run the engine
async
Examples
The examples/
directory contains working implementations:
block_trader.rs
: A bot that executes trades based on blockchain events
Monitoring
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 |
Configuration
The engine can be configured through builder methods:
let engine = new
.with_event_channel_capacity
.with_action_channel_capacity
.with_metrics_enabled;
Error Handling
botcore
provides a comprehensive error type system:
- Clear error messages
- Error categorization
- Error context preservation
- Recovery strategies
Best Practices
-
Event Design
- Keep events small and focused
- Include necessary context
- Use appropriate serialization
-
Strategy Implementation
- Handle state carefully
- Implement proper error handling
- Keep processing logic modular
-
Execution
- Implement retries for transient failures
- Handle rate limiting
- Log important state changes
Contributing
We welcome contributions! Please see our Contributing Guide for details on:
- Code style
- Pull request process
- Development setup
- Testing requirements
License
This project is licensed under the MIT License - see the LICENSE file for details.