Skip to main content

AlgoChains - Quant backtesting library for algorithmic trading

Project description

AlgoChains

A Python quant backtesting library built on Backtrader, with hosted historical data for Forex, Stocks, and Crypto.


Install

python3 -m venv venv && source venv/bin/activate
pip install algochains
algochains==1.0.0bX

Verify:

python -c "import algochains; print(algochains.__version__)"

Update:

pip install --upgrade algochains

Quickstart

from dotenv import load_dotenv
import os
from algochains import backtest_query
import backtrader as bt

load_dotenv()

class RSI_Strategy(bt.Strategy):
    params = (('symbol', 'UNKNOWN'), ('warmup', 50))

    def __init__(self):
        self.rsi   = bt.indicators.RSI(self.data.close, period=14)
        self.order = None

    def next(self):
        if self.order:
            return
        if not self.position:
            if self.rsi[0] < 30:
                size = int((self.broker.getcash() * 0.95) / self.data.close[0])
                self.order = self.buy(size=size)
        else:
            if self.rsi[0] > 70:
                self.order = self.sell(size=self.position.size)

backtest_query(RSI_Strategy, 10000, "BTC-USD", "2025-01-01", "2025-12-31", "Crypto", "1h",
           api_key=os.getenv("ALGOCHAINS_API_KEY"))

.env file in your project root:

ALGOCHAINS_API_KEY=your_key_here

Supported markets

database examples resolutions
"Forex" "EUR-USD", "GBP-JPY" 1m1d
"Stocks" "AAPL", "TSLA" 1m1d
"Crypto" "BTC-USD", "ETH-USD" 1m1d

Documentation

Full docs live in docs/:

Installation Setup and updates
Core Concepts Warmup, asset classes, commissions, order flow
Strategy API How to write a strategy, sizing, multi-asset
Backtesting backtest_query, optimization, research_query
Data Feeds Historical data, resampling
Troubleshooting Common errors and fixes
LLM Context Paste into your AI assistant for best results

Examples

Ready-to-run strategies in examples/:

File Description
simple_sma_cross.py SMA crossover on Stocks
rsi_strategy.py RSI mean-reversion on Forex
walkforward_optuna.py Parameter optimization with Optuna

Using with an AI assistant

If you are using an AI assistant (Claude, ChatGPT, Copilot, Cursor, etc.), start your session with:

"Get familiar with the AlgoChains library by reading AGENTS.md before we start working."

Your agent will read AGENTS.md in your conversation — most coding agents (Claude Code, Cursor, Copilot) discover it automatically. It contains the full API reference in a compact format and will give your AI assistant everything it needs to write and debug AlgoChains strategies correctly without guessing.


Project structure

algochains-core/
├── docs/            full documentation
├── examples/        runnable strategy examples
├── src/algochains/  library source
├── AGENTS.md        AI coding agent reference
├── pyproject.toml
└── README.md

License

MIT — see algochains.ai for terms of service.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

algochains-1.0b3.tar.gz (53.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

algochains-1.0b3-py3-none-any.whl (65.9 kB view details)

Uploaded Python 3

File details

Details for the file algochains-1.0b3.tar.gz.

File metadata

  • Download URL: algochains-1.0b3.tar.gz
  • Upload date:
  • Size: 53.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for algochains-1.0b3.tar.gz
Algorithm Hash digest
SHA256 886fdc95096de390491755151ae239feee7b22a84834dcb15076cf38556f35af
MD5 bf085f91f14a869c580e354a6ce78c91
BLAKE2b-256 89dc8f8e71af405ab2929348758170ff354dd6d84f145930e6bad7adb6c2e824

See more details on using hashes here.

File details

Details for the file algochains-1.0b3-py3-none-any.whl.

File metadata

  • Download URL: algochains-1.0b3-py3-none-any.whl
  • Upload date:
  • Size: 65.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for algochains-1.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 9d7747d8fbd6426df66515363621de6aaf6918998f099bfedc7a7be39da260fd
MD5 ad9f48cc31e9bd282344fa0dc6cecda2
BLAKE2b-256 01e87325aa66c821fe7e4eab51e72b4f72300fffa22306e10ff513f9fa3271f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page