GitHub - btrccts/btrccts: Backtest and Run Cryptocurrency Trading Strategies

Β·

Overview

btrccts is a Python library designed to simplify backtesting and live execution of cryptocurrency trading strategies using CCXT. It provides a framework with a backtest exchange interface identical to CCXT, ensuring seamless transitions between testing and live environments.

Key Features

Installation

Recommended Methods

  1. PyPI Installation:

    pip install btrccts
  2. Manual Installation:

    git clone https://github.com/btrccts/btrccts.git
    cd btrccts
    pip install -e .

πŸ‘‰ For advanced installation options, visit our official documentation

Getting Started

Basic Usage Pattern

from btrccts import parse_params_and_execute_algorithm, AlgorithmBase

class MyStrategy(AlgorithmBase):
    @staticmethod
    def configure_argparser(argparser):
        argparser.add_argument('--pyramiding', default=1, type=int)
        
    def __init__(self, context, args):
        self._context = context
        self._args = args
        self._exchange = context.create_exchange('kraken', async_ccxt=True)
        
    async def next_iteration(self):
        print('Current time:', self._context.date())
        await self._exchange.load_markets()
        ohlcv = await self._exchange.fetch_ohlcv('BTC/USD', '1m')
        print(ohlcv)

result = parse_params_and_execution_algorithm(MyStrategy)

Core Functionality

Backtesting Parameters

ParameterDescriptionExample Value
--start-dateBacktest start date2023-01-01
--end-dateBacktest end date2023-01-31
--intervalStrategy execution interval1h
--exchangesExchanges to simulatebinance, kraken
--symbolsTrading pairsBTC/USD, ETH/USD

Live Trading Considerations

  1. Market Loading: Unlike backtesting, markets aren't automatically loaded in live mode
  2. Error Handling: Robust exception handling is crucial for uninterrupted operation
  3. Performance Impact: Network latency becomes a factor in live execution

Data Management

Directory Structure

data/
└── ohlcv/
    └── EXCHANGE/
        └── BASE_QUOTE.csv
config/
└── EXCHANGE.json

OHLCV File Format

,open,high,low,close,volume
2023-01-01 00:00:00+00:00,100,150,90,120,5000
2023-01-01 00:01:00+00:00,120,130,110,125,4000

Order Execution Logic

Backtesting Behavior

Order TypeExecution Rules
MarketImmediate execution with slightly worse than current price (no look-ahead bias)
LimitFilled when price reached (no partial fills in backtest)

Development Guide

Setup Development Environment

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e .

Running Tests

python -m unittest tests/unit/tests.py
python -m unittest tests/integration/tests.py

πŸ‘‰ For more development resources, check our GitHub repository

FAQ

What's the minimum Python version required?

btrccts requires Python 3.7 or higher due to its asynchronous features.

Can I use this for stocks or forex trading?

While technically possible, btrccts is optimized for cryptocurrency markets and CCXT integrations.

How accurate is the backtesting simulation?

The simulation uses OHLCV data and approximates order fills, but cannot account for all real-market conditions like slippage or partial fills.

What exchanges are supported?

All exchanges supported by CCXT can be used, though OHLCV data must be provided for backtesting.

Is there a way to visualize backtest results?

The library focuses on execution. You'll need additional tools like Matplotlib or Plotly for visualization.

Final Notes

This implementation includes all required elements: