A backtesting simulator based on ccxt for cryptocurrency trading strategies
Project description
CCXT Backtesting Exchange
CCXT Backtesting Exchange is a Python simulation package designed for backtesting trading strategies while mirroring CCXT’s unified API calls. This allows traders and developers to test strategies in a controlled environment before deploying them in live markets.
For more details on CCXT, visit the official documentation: CCXT Docs.
Installation
To install the package, run the following command:
pip install ccxt_backtesting_exchange
Usage
Initialize the backtester as shown below.
Backtester Setup
import ccxt
from datetime import datetime, timedelta
from ccxt_backtesting_exchange import Backtester, Clock
start_date = datetime(2024, 3, 10, 23, 30)
end_date = datetime(2024, 3, 10, 23, 59)
clock = Clock(
start_time=start_date,
end_time=end_date,
interval=timedelta(minutes=1), # Simulation interval, same as OHLC interval
)
backtester = Backtester(
balances={"BTC": 1.0, "ETH": 5.0, "SOL": 10.0, "USDT": 10000.0}, # Starting balance
clock=clock,
fee=0.001, # Transaction fee if applicable
)
Load Backtest Data
Download OHLC dataset from any preferred source and load it into the CCXT backtester. Once the data feed is added, the backtester is ready for use.
backtester.add_data_feed(
"SOL/USDT", "1m", "./data/test-sol-data.json"
)
Consume Backtesting APIs
The backtester supports various CCXT-like API calls for interacting with the simulated trading environment.
Fetch Balance
backtester.fetch_balance()
Deposit Funds
backtester.deposit("BTC", amount=0.5)
Withdraw Funds
backtester.withdraw("ETH", amount=2.0)
Create Order
Order types can be either 'limit' or 'market', and sides can be 'buy' or 'sell'.
backtester.create_order("SOL/USDT", type="limit", side="buy", amount=1.0, price=200.0)
Cancel Order
backtester.cancel_order(id=1, symbol="SOL/USDT")
Other Available Methods
The backtester supports additional trading-related methods:
backtester.fetch_orders()
backtester.fetch_order(order_id)
backtester.fetch_open_orders()
backtester.fetch_closed_orders()
backtester.fetch_my_trades()
backtester.fetch_ticker("SOL/USDT")
backtester.fetch_tickers()
backtester.fetch_ohlcv("SOL/USDT", timeframe="1m")
Development
Contributions are welcome! If you’d like to improve the project, please open an issue first to discuss your changes.
Project Setup
Clone the repository and install dependencies using Poetry:
git clone https://github.com/deelabot/ccxt_backtesting_exchange
cd ccxt_backtesting_exchange
poetry install
Running Tests
Ensure that all tests pass before submitting a pull request:
poetry run pytest
Linting
Maintain code quality by running:
poetry run flake8
License
This project is licensed under the MIT License. See the LICENSE file for details. [Yet to determine the project license]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ccxt_backtesting_exchange-0.1.0.tar.gz.
File metadata
- Download URL: ccxt_backtesting_exchange-0.1.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a7f49582368971a6eccd6c25799dcf1d4df9a967276cf194ce8a1b6fcfea1b6
|
|
| MD5 |
0f3501b632cfc330382d2c4abb2da324
|
|
| BLAKE2b-256 |
f72feb0e436a4362e7abf85269f0d7c11babc4e499d1158689d2b9ae0d2e15fd
|
File details
Details for the file ccxt_backtesting_exchange-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ccxt_backtesting_exchange-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
397ecd5e1ea8db55c61fb2928ef719ed3c3905656e8d072b03c349c14794d772
|
|
| MD5 |
ddbcef874f44e40da082f6149d7ac141
|
|
| BLAKE2b-256 |
0a6bdafb242b505e0935862bd422eaae965454a3bd28e208225ce811bf7fe1eb
|