Skip to content

Repository files navigation

MCT Trading Bot

CI linting: pylint codecov pre-commit Docker pull Discord chat

MCT (stands for ML-Crypto-Trading) is a high-performance trading engine that features a Dynamic Expression Engine allowing users to define position sizing and risk management logic using familiar, spreadsheet-like functions.

Tip

Financial Logic Without the Code. If you can write an Excel-style formula, you can define trading logic in MCT. The engine provides access to real-time market data, balances, and technical indicators (RSI, EMA, SMA) directly in your configuration.

Caveat Utilitor! For educational and research purposes only.


Community

Join our Discord community to discuss strategies, report issues, and collaborate with other traders:

Discord Banner


Core Features

  • 🧠 AI Agent & LangGraph Workflows: Interactive multi-agent assistant with specialized subgraphs for configuration tuning, on-demand backtesting, trading performance analytics, and a proactive Trading Oracle.
  • πŸ“ Dynamic Expression Engine: Define position sizing and custom strategy logic using spreadsheet formulas (rsi, sma, ema, balance, equity, pnl, etc.).
  • 🀝 BFT Consensus Engine: Flexible multi-strategy quorum voting supporting 1-of-1 single strategy, 1-of-2 independent triggers, and 2-of-2 strict consensus.
  • πŸ“Š High-Fidelity Backtesting: Multi-asset independent clock simulation with realistic execution frictions (slippage, latency, fees), drift detection, and tick replay.
  • 🌐 REST API & Real-Time WebSockets: FastAPI server providing order analytics, monthly heatmaps, latency metrics, configuration proposals, and live log streaming (/api/v1/logs/ws).
  • πŸ“ˆ Runtime Observability & Metrics: Built-in collectors for CPU/memory usage, WebSocket health, order lifecycle timings, and exchange telemetry.
  • πŸ“œ Configuration Version Control (VCS): Git-like history tracking, audit trail, and rollback for runtime configuration changes.

Quick Start

The easiest way to run the bot is using Docker or standard Python.

Prerequisites

  • Docker & Docker Compose (or Python 3.11+)
  • PostgreSQL: A running instance (local or remote) to store trading history.

1. Configuration

Create your asset configuration and environment variables.

trading-config.yaml

assets:
  - name: "Bitcoin (Crypto.com)"
    base_ticker_symbol: "BTC"
    quote_ticker_symbol: "USD"
    exchange: "CRYPTO_DOT_COM"
    min_quantity: 0.00005
    quote_decimals: 2
    quantity_decimals: 5
    candles_timeframe: "MIN1"
    schedule: 1
    strategies:
      - name: "HammerAccumulationStrategy"
        type: "STATIC"
        class_name: "HammerAccumulationStrategy"
        action: "BUY"
      - name: "RsiOversoldBuy"
        type: "DYNAMIC"
        action: "BUY"
        expression: "rsi(14) < 20"
      - name: "RsiOverboughtSell"
        type: "DYNAMIC"
        action: "SELL"
    consensus:
      buy: 1.3
      sell: 0.5
dynamic_quantity: "max(min_qty, (balance * 0.02) / close)"

Consensus Configurations

MCT uses a Byzantine Fault Tolerant (BFT) voting system where trade actions execute when consensus quorum is satisfied:

$$\text{True Count} \ge \text{Factor} \times (\text{Total} - \text{True Count})$$

You can configure consensus per asset depending on your trading strategy:

  • Single Strategy (1-of-1 Consensus): Configure 1 strategy with consensus.buy: 1.0 and consensus.sell: 1.0. The trade triggers whenever that single strategy votes True.

    strategies:
      - name: "RsiOversoldBuy"
        type: "DYNAMIC"
        action: "BUY"
        expression: "rsi(14) < 30"
    consensus:
      buy: 1.0
      sell: 1.0
  • Multi Strategy (1-of-2 Consensus β€” Trade on Each Strategy): Configure 2 strategies with consensus.buy: 0.5 (or any factor $\le 1.0$). If either strategy signals a trade (1 of 2), quorum is met ($1 \ge 0.5 \times 1$).

    strategies:
      - name: "RsiOversoldBuy"
        type: "DYNAMIC"
        action: "BUY"
        expression: "rsi(14) < 30"
      - name: "BreakoutBuy"
        type: "DYNAMIC"
        action: "BUY"
        expression: "close > sma(50) and volume > 100"
    consensus:
      buy: 0.5
      sell: 0.5
  • Multi Strategy (2-of-2 Consensus β€” Trade on Quorum / Agreement): Configure 2 strategies with consensus.buy: 1.3 (or any factor $&gt; 1.0$). A trade triggers only when both strategies agree ($2 \ge 1.3 \times 0$, but $1 &lt; 1.3 \times 1$).

    strategies:
      - name: "RsiOversoldBuy"
        type: "DYNAMIC"
        action: "BUY"
        expression: "rsi(14) < 30"
      - name: "HammerAccumulationStrategy"
        type: "STATIC"
        class_name: "HammerAccumulationStrategy"
        action: "BUY"
    consensus:
      buy: 1.3
      sell: 0.5

.env

APP_ENV=production
CRYPTO_DOT_COM__API_KEY=your_api_key
CRYPTO_DOT_COM__SECRET_KEY=your_secret_key
DATABASE_CONNECTION_HOST=localhost:5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_password
POSTGRES_DATABASE=trading_bot

2. Run Modes

πŸ“Š Backtesting (Historical Data & Replay)

Test your strategies against historical CSV or recorded audit data with realistic execution frictions (slippage, latency, fees):

docker run -v $PWD:/workspace toniton/ml-crypto-trading \
  --assets-conf=/workspace/trading-config.yaml \
  --backtest-mode=true \
  --backtest-source=/workspace/history/ \
  --backtest-latency-ms=500.0 \
  --backtest-slippage-ticks=2 \
  --backtest-fee-rate=0.001

πŸ§ͺ Simulated Trading (Paper Trading)

Run the bot with live market streams while intercepting and executing orders in memory:

docker run --env-file .env -v $PWD:/workspace toniton/ml-crypto-trading \
  --assets-conf=/workspace/trading-config.yaml \
  --simulated=true

πŸš€ Live Trading (Real Exchange)

Execute live orders on the configured exchange:

docker run --env-file .env -v $PWD:/workspace toniton/ml-crypto-trading \
  --assets-conf=/workspace/trading-config.yaml

🌐 REST API & AI Agent Server

Start the integrated FastAPI and AI Agent server for interactive chat, log streaming, and metric APIs:

docker run --env-file .env -p 8000:8000 -v $PWD:/workspace toniton/ml-crypto-trading \
  --assets-conf=/workspace/trading-config.yaml \
  --server=true \
  --api-port=8000

Documentation

For comprehensive information, please explore the documentation in the docs/ directory:


License

This source code is available on GitHub under the GNU Lesser General Public License v3.0.

Copyright

Copyright Β© 2026 Toni Akinjiola

All rights reserved except as expressly provided under the applicable license.

About

This is a free and open-source cryptocurrency trading bot written in Python.

Topics

Resources

Stars

4 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages