Real-time cryptocurrency arbitrage detection system across multiple Iranian exchanges
Stream-Coin is a high-performance, asynchronous cryptocurrency market data aggregator built with Rust. It connects to multiple Iranian cryptocurrency exchanges, streams real-time price data into Kafka, and enables instant arbitrage opportunity detection through stream processing.
Stream-Coin solves the challenge of identifying price discrepancies across multiple cryptocurrency exchanges in real-time. By leveraging event streaming and async processing, the system can detect arbitrage opportunities within milliseconds.
- Asynchronous Architecture: Built on Tokio for non-blocking, concurrent operations
- Multi-Exchange Support: Integrates with 8+ Iranian cryptocurrency exchanges
- Real-time Streaming: Kafka-based event streaming for low-latency data processing
- Persistent Storage: MySQL database with SeaORM for reliable data persistence
- High-Performance Caching: Redis integration for fast data access
- Clean Architecture: Domain-driven design with clear separation of concerns
- API-First Design: RESTful API with Actix-web and comprehensive Swagger documentation
┌─────────────────┐
│ Exchanges │
│ (WebSocket/ │
│ REST APIs) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Stream-Coin │
│ (Rust App) │
│ │
│ ┌───────────┐ │
│ │ Actix │ │ ◄── REST API
│ │ Web │ │
│ └───────────┘ │
│ │
│ ┌───────────┐ │
│ │ Tokio │ │ ◄── Async Runtime
│ │ Runtime │ │
│ └───────────┘ │
└────────┬────────┘
│
├──────────────┐
▼ ▼
┌─────────────┐ ┌─────────────┐
│ Kafka │ │ Redis │
│ (Streams) │ │ (Cache) │
└─────────────┘ └─────────────┘
│
▼
┌─────────────────┐
│ MySQL │
│ (SeaORM) │
└─────────────────┘
| Component | Technology |
|---|---|
| Language | Rust 🦀 |
| Async Runtime | Tokio |
| Web Framework | Actix-web |
| Message Broker | Apache Kafka |
| Cache | Redis |
| Database | MySQL |
| ORM | SeaORM |
| Container Runtime | Docker / Nerdctl |
-
Clone the repository
git clone https://github.com/yourusername/stream-coin.git cd stream-coin -
Set up infrastructure
Using Docker:
sudo docker compose up -d
Using Nerdctl (containerd):
sudo nerdctl compose -f ./docker-compose.yml up -d
-
Configure environment
cp .env.example .env # Edit .env with your configuration -
Run database migrations
cargo run --bin migrate
-
Start the application
cargo run --bin stream-coin
Once the application is running, access the interactive API documentation:
- Swagger UI: http://localhost:8080/swagger-ui/
- Kafka UI: http://localhost:8083/ui/
- Redis Insight: http://localhost:8082/
Enable debug logging in your code:
use log::debug;
debug!("Payload: {}", payload);Run with RUST_LOG environment variable:
RUST_LOG=debug cargo run --bin stream-coinStream-Coin currently integrates with the following Iranian cryptocurrency exchanges:
| Exchange | API Documentation | Status |
|---|---|---|
| Wallex | docs | ✅ Active |
| Bitpin | docs | ✅ Active |
| Aban Tether | docs | ✅ Active |
| Ramzinex | docs | ✅ Active |
| Exir | docs | ✅ Active |
| Nobitex | docs | ✅ Active |
| Tetherland | docs | ✅ Active |
| Tabdeal | docs | ✅ Active |
| Bit24 | docs | ✅ Active |
Three independent, separately buildable projects in one Cargo workspace — each can be split into its own repository later with no code changes:
stream-coin/
├── Cargo.toml # workspace manifest: members = ["engine", "cli"]
├── engine/ # the arbitrage engine server (binary: stream-coin)
│ ├── bin/http.rs
│ └── src/
│ ├── exchange/ # ExchangeAdapter implementations (Tabdeal, ...)
│ ├── price/ # Price domain entity
│ ├── ticker/ # TickerRepository port
│ ├── kafka/ # MessagePublisher port + Kafka producer
│ ├── infrastructure/# Redis cache, WebSocket client trait
│ └── presentation/ # actix-web handlers, routers, DTOs, WS feed
├── cli/ # the `sc` control-plane CLI, no engine dependency
│ └── src/ # auth, client, config, ticker subcommands
├── ui/ # separate Cargo workspace: Dioxus SPA (web/mobile)
└── docker-compose.yml # local infra: Redis, Kafka, Flink, proxy
See ARCHITECTURE.md for the full system diagram and data flow.
# Run all tests
cargo test
# Run specific test suite
cargo test --test integration_tests
# Run with output
cargo test -- --nocapture# Format code
cargo fmt
# Run linter
cargo clippy
# Check for issues
cargo check# Optimized release build
cargo build --release
# Run release binary
./target/release/stream-coin- Update readme
- Create output variable standardization
- Fix Redis Insight configuration
- Add Postman API collection
- Complete Swagger documentation for all endpoints
- WebSocket support for real-time client updates
- Machine learning-based opportunity prediction
- Multi-region deployment support
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Rust naming conventions
- Write comprehensive tests
- Document public APIs
- Keep functions focused and small
- Use meaningful variable names
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.