Skip to content

enavid/stream-coin

Repository files navigation

Stream-Coin

Real-time cryptocurrency arbitrage detection system across multiple Iranian exchanges

Rust Kafka Redis MySQL

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.


Overview

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.

Key Features

  • 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

Architecture

┌─────────────────┐
│   Exchanges     │
│  (WebSocket/    │
│   REST APIs)    │
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│  Stream-Coin    │
│   (Rust App)    │
│                 │
│  ┌───────────┐  │
│  │  Actix    │  │ ◄── REST API
│  │   Web     │  │
│  └───────────┘  │
│                 │
│  ┌───────────┐  │
│  │  Tokio    │  │ ◄── Async Runtime
│  │  Runtime  │  │
│  └───────────┘  │
└────────┬────────┘
         │
         ├──────────────┐
         ▼              ▼
┌─────────────┐  ┌─────────────┐
│   Kafka     │  │   Redis     │
│  (Streams)  │  │  (Cache)    │
└─────────────┘  └─────────────┘
         │
         ▼
┌─────────────────┐
│     MySQL       │
│  (SeaORM)       │
└─────────────────┘

Technology Stack

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

Quick Start

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/stream-coin.git
    cd stream-coin
  2. Set up infrastructure

    Using Docker:

    sudo docker compose up -d

    Using Nerdctl (containerd):

    sudo nerdctl compose -f ./docker-compose.yml up -d
  3. Configure environment

    cp .env.example .env
    # Edit .env with your configuration
  4. Run database migrations

    cargo run --bin migrate
  5. Start the application

    cargo run --bin stream-coin

Usage

API Documentation

Once the application is running, access the interactive API documentation:

Management Interfaces

Debugging

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-coin

🔌 Supported Exchanges

Stream-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

🏗️ Project Structure

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.


🧪 Development

Running Tests

# Run all tests
cargo test

# Run specific test suite
cargo test --test integration_tests

# Run with output
cargo test -- --nocapture

Code Quality

# Format code
cargo fmt

# Run linter
cargo clippy

# Check for issues
cargo check

Building for Production

# Optimized release build
cargo build --release

# Run release binary
./target/release/stream-coin

Roadmap

Current Tasks

  • Update readme
  • Create output variable standardization
  • Fix Redis Insight configuration
  • Add Postman API collection
  • Complete Swagger documentation for all endpoints

Future Enhancements

  • WebSocket support for real-time client updates
  • Machine learning-based opportunity prediction
  • Multi-region deployment support

Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

  • Follow Rust naming conventions
  • Write comprehensive tests
  • Document public APIs
  • Keep functions focused and small
  • Use meaningful variable names

License

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.

About

Rust-based project connecting to multiple exchanges, fetching live market data, and streaming it into Kafka. Enables real-time stream processing to detect instant price differences of coins across exchanges.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors