This release is a pre-release and may not be stable for production use.
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" |
1m – 1d |
"Stocks" |
"AAPL", "TSLA" |
1m – 1d |
"Crypto" |
"BTC-USD", "ETH-USD" |
1m – 1d |
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.
Metadata
Release files for algochains 1.0b4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| algochains-1.0b4.tar.gz | 246.8 kB | Without provenance | Details for algochains-1.0b4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| algochains-1.0b4-py3-none-any.whl | Python 3 | none | any | Details for algochains-1.0b4-py3-none-any.whl |
Total release size: 508.5 kB
Release files / algochains-1.0b4.tar.gz
| Download URL | algochains-1.0b4.tar.gz |
|---|---|
| Size | 246.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cdf1c884309eab18ebd427b2d47b8b0a7c78ad774ac0fc90ed5f6b9cb751b671
|
|
BLAKE2b-256 checksum How to use checksums |
f9d40b1c68c8928a1f7bd905ca3de5299b98ea44d7fb3fdb40574049b22ad5bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / algochains-1.0b4-py3-none-any.whl
| Download URL | algochains-1.0b4-py3-none-any.whl |
|---|---|
| Size | 261.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
703086cad44d3d7cadb2fb36a230ebc8aac561468491c598c12ece8bd407516c
|
|
BLAKE2b-256 checksum How to use checksums |
2f39aa529c65a0effdbb44318ee70baac17371d70e7dfbab69b4202c24ec6bca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for algochains 1.0b4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.