Official Python client for the Backtest360 API
Project description
backtest360
Official Python client for the Backtest360 API.
Run backtests, automate, integrate with your research or trading workflows. The SDK handles authentication, serialization, and error mapping so you can call a single method instead of building and parsing the raw HTTP requests yourself.
import matplotlib.pyplot as plt
import yfinance as yf
from backtest360 import Client, Strategy
df = yf.download("BTC-USD", period="1y", interval="1d",
auto_adjust=False, multi_level_index=False, progress=False)
df.columns = df.columns.str.lower()
result = Client(api_key="b360_...").backtest(Strategy.rsi_threshold_long(), df)
result.summary()
result.strategy_equity.plot(title="Equity curve")
plt.show()
Save this snippet as quickstart.py, drop in your API key, and run it with
python quickstart.py (install the extras if needed: pip install matplotlib yfinance).
Install
pip install backtest360
Requires Python 3.9+. The only runtime dependencies are httpx and pandas.
Need to install Python first? (Windows / macOS / Linux / WSL)
Windows (native)
- Install Python from python.org/downloads (check "Add to PATH"), or via winget:
winget install Python.Python.3.12
- Open PowerShell and verify:
python --version
- Install the SDK and yfinance for the quickstart:
pip install backtest360 yfinance
- Run a script:
python quickstart.py
Windows via WSL (recommended for quant work)
- Install WSL:
wsl --install
Restart, then open the Ubuntu terminal. - Install Python:
sudo apt update && sudo apt install python3 python3-pip -y
- Install the SDK:
pip3 install backtest360 yfinance
- Run a script:
python3 quickstart.py
macOS
# via Homebrew (recommended)
brew install python
# or download from python.org/downloads
Then:
pip3 install backtest360 yfinance
python3 quickstart.py
Linux
sudo apt install python3 python3-pip -y # Debian/Ubuntu
pip3 install backtest360 yfinance
python3 quickstart.py
Get an API key
Sign up at backtest360.com/api and copy your key.
Store it in the BACKTEST360_API_KEY environment variable or pass it directly:
client = Client(api_key="b360_...")
# or: export BACKTEST360_API_KEY=b360_...
client = Client()
The engine URL can be overridden with the optional BACKTEST360_ENGINE_URL
environment variable, read when the Client is constructed. An explicit
base_url= argument takes precedence over the environment variable, which in
turn takes precedence over the default:
export BACKTEST360_ENGINE_URL=https://api.backtest360.com
Features
- Synchronous client — straightforward to use in scripts, notebooks, and pipelines
- Hand-written wrapper over the public REST API — no generated code, no schema sync
- Built-in strategy templates (
Strategy.rsi_threshold_long(),Strategy.ma_crossover(), …) - Grouped-knob classes:
Execution,Costs,Risk,Sizing,MarketHours,Settings— set only what you need - Pre-computed signals path:
client.backtest_signals(series, df)for model-generated signals - Pandas-native — pass a DataFrame, get pandas Series back (
result.strategy_equity,result.returns) - Chart-annotation markers and data-quality report on every result (
result.markers,result.data_quality) - Engine introspection:
client.version()for version compatibility checks - Raw-API escape hatch for full control (
client.backtest_raw({...})) - Strict type hints +
py.typed— first-class IDE and mypy support - MIT licensed
Common patterns
Custom strategy
from backtest360 import Client, Strategy, Execution, Costs, Risk, Sizing, Settings
import yfinance as yf
df = yf.download("SPY", start="2020-01-01", end="2024-01-01", interval="1d",
auto_adjust=False, multi_level_index=False, progress=False)
df.columns = df.columns.str.lower()
strat = Strategy(
name="rsi_mean_reversion",
long_entry="(rsi_14 > 30) & (rsi_14 < 50)",
long_exit="rsi_14 >= 50",
indicators=[Strategy.indicator("rsi", ref="rsi_14", period=14)],
)
result = Client(api_key="b360_...").backtest(
strat, df,
execution=Execution(entry="open", exit="close", signal_frequency="daily"),
costs=Costs(slippage_bps=2.5, fee_pct=0.001),
risk=Risk(stop="atr", value=2.5, atr_period=14, max_drawdown=0.25),
sizing=Sizing(weight=1.0, vol_target=0.15, leverage_limit=2.0),
settings=Settings(risk_free_rate=0.04),
)
result.summary()
print("Max Drawdown:", result.stats.get("Max Drawdown", "n/a"))
for t in result.trades[:5]:
print(t["entry_date"], t["direction"], t["return_net"])
Indicator library (names, params, output columns): https://api.backtest360.com/docs
Strategy templates: see the
Strategy.<name>()classmethods (e.g.Strategy.rsi_threshold_long()).
Pre-computed signals
import pandas as pd
from backtest360 import Client
# Any signal series of {-1, 0, 1} — your ML model, custom indicator, etc.
signals = pd.Series(..., index=df.index)
result = Client(api_key="b360_...").backtest_signals(signals, df)
print(result.stats["Sharpe"])
Raw API escape hatch
For users who want exact control with the API docs open:
resp = Client(api_key="...").backtest_raw({
"strategy": {"condition_tree": {...}, "indicators": [...]},
"data_source": {"ohlcv": {...}},
"execution": {"signal_frequency": "daily"},
})
Latest signal
Ask the engine for the target position on the most-recent bar — the live-trading hook:
from backtest360 import Client, Strategy
signal = Client(api_key="b360_...").latest_signal(Strategy.rsi_threshold_long(), df)
position = {1: "LONG", 0: "FLAT", -1: "SHORT"}[signal["signal"]]
print(position, signal["long_entry_fired"])
Validate a strategy
Check a strategy against the engine's registry without running a backtest:
from backtest360 import Client, Strategy
v = Client(api_key="b360_...").validate_strategy(Strategy.rsi_threshold_long())
print(v["valid"], v.get("errors", []))
Discover indicators
from backtest360 import Client
client = Client(api_key="b360_...")
print([i["name"] for i in client.list_indicators()])
Error handling
from backtest360 import Backtest360Error
try:
result = client.backtest(strategy, df)
except Backtest360Error as e:
if e.status == 401:
print("Invalid or expired API key — renew at backtest360.com/api")
elif e.status in (429, 503):
# Rate limited or the engine is at capacity — retry with backoff.
# e.retry_after carries the Retry-After header (seconds) when set.
print(f"Busy — retry in {e.retry_after or 5:.0f}s")
elif e.status == 504:
print("Run exceeded the compute time limit — reduce the date range "
"or strategy complexity")
elif e.status == 422:
detail = e.body.get("detail") if isinstance(e.body, dict) else e.body
print("Strategy validation failed:", detail)
else:
raise # unexpected — let it propagate
On server errors (5xx), e.request_id carries the response's X-Request-ID —
quote it when reporting an issue. You can also pass your own correlation id to
any method: client.backtest(strategy, df, request_id="my-run-42").
Versioning
MAJOR.MINOR.PATCH. Pre-1.0 (0.x.y): the API may move between minor versions.
Pre-release suffixes: aN (alpha), bN (beta), rcN (release candidate).
See CHANGELOG.md for the release history.
Full documentation
- Engine API reference: https://api.backtest360.com/docs
- Runnable examples:
examples/ - Release history: CHANGELOG.md
Questions / feedback
Questions or feedback? hello@backtest360.com — we read everything. The SDK is in active development, so help shape it.
Bug reports and feature requests: open an issue on GitHub.
License
MIT — see 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 backtest360-0.4.0.tar.gz.
File metadata
- Download URL: backtest360-0.4.0.tar.gz
- Upload date:
- Size: 25.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
902e715232b1468cdb2ba6963f9e440dd99161641df2750f06fbc8b0acea4516
|
|
| MD5 |
e03da21ab613c6e8599bf8aedd6ebf1c
|
|
| BLAKE2b-256 |
1f3eb60eb91649e75023ddd681bc8f8d70be14b8c408ed2dc3e7539971cb3ce8
|
Provenance
The following attestation bundles were made for backtest360-0.4.0.tar.gz:
Publisher:
release.yml on Backtest360/backtest360
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
backtest360-0.4.0.tar.gz -
Subject digest:
902e715232b1468cdb2ba6963f9e440dd99161641df2750f06fbc8b0acea4516 - Sigstore transparency entry: 1850095477
- Sigstore integration time:
-
Permalink:
Backtest360/backtest360@1b68dfd0e2bf2ae0e199dab8c12b29cfb6582027 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/Backtest360
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1b68dfd0e2bf2ae0e199dab8c12b29cfb6582027 -
Trigger Event:
push
-
Statement type:
File details
Details for the file backtest360-0.4.0-py3-none-any.whl.
File metadata
- Download URL: backtest360-0.4.0-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7d3aecfc32a2d280223f56eff73f6b216f1f935c7ac20d618ef9d5a388d0bfc
|
|
| MD5 |
77fccc120aaabb61f8d04e593f42b2b9
|
|
| BLAKE2b-256 |
a58419f74d23c2665087d23de717a2903c3bbbc54e1b29664985f4407e46eb2a
|
Provenance
The following attestation bundles were made for backtest360-0.4.0-py3-none-any.whl:
Publisher:
release.yml on Backtest360/backtest360
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
backtest360-0.4.0-py3-none-any.whl -
Subject digest:
c7d3aecfc32a2d280223f56eff73f6b216f1f935c7ac20d618ef9d5a388d0bfc - Sigstore transparency entry: 1850095627
- Sigstore integration time:
-
Permalink:
Backtest360/backtest360@1b68dfd0e2bf2ae0e199dab8c12b29cfb6582027 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/Backtest360
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1b68dfd0e2bf2ae0e199dab8c12b29cfb6582027 -
Trigger Event:
push
-
Statement type: