Skip to main content

Local-first agentic strategy lab CLI: chat, backtest, and paper-trade long/flat strategies on keyless Binance public data.

Project description

backtestchat

An open-source, local-first agentic strategy lab in your terminal. Chat with a LangGraph agent to fetch keyless Binance public market data, design and backtest long/flat crypto strategies, and run simulated paper trades. Charts render to self-contained plotly HTML that opens in your browser.

Paper-only by design. backtestchat simulates fills from closed bars. It never places real orders and never needs exchange API keys. Market data comes from the public, keyless Binance REST API. The only key you supply is your own model (BYOK) key, or a local Ollama endpoint.

backtestchat is a research and simulation tool and a portfolio/learning project. It is not financial advice and not a trading product. Do not use it to make investment decisions.

Quickstart

Requires Python 3.12+ and uv.

git clone https://github.com/barisarat/backtestchat
cd backtestchat
uv sync --extra openai              # deps + the OpenAI model provider

export BACKTESTCHAT_MODEL=openai:gpt-5.4-nano
export OPENAI_API_KEY=sk-...

uv run backtestchat chat                # talk to the agent
uv run backtestchat runs sync           # advance paper runs to the latest closed bar
uv run backtestchat runs list           # check paper run status

Two things to know:

  • The backtestchat command lives in the project venv, so either prefix every command with uv run, or activate the venv once with source .venv/bin/activate and call backtestchat directly.
  • Always sync with the extra for the provider you use. A plain uv sync removes extras, and backtestchat chat will fail until you uv sync --extra openai again.

Market data works with zero keys; only the chat agent needs a model key. Other providers (Anthropic, Ollama, ...) are covered under Model setup.

What it does

  • Chat with a tool-calling agent (LangGraph) that maps your plain-English requests onto market-data, backtest, and paper-trade actions.
  • Backtest ~11 single-signal long/flat strategies (SMA/EMA crossover, MACD, RSI, Bollinger, Donchian, ROC, stochastic, ATR channel, price-vs-SMA, buy & hold) with CAGR, Sharpe, max drawdown, win rate, and trade count.
  • Compare several strategies at once, ranked, on one chart.
  • Paper-trade a strategy with simulated fills. Runs advance by replaying closed bars - no daemon, no scheduler. Any command can trigger a cheap sync.
  • Charts are deterministic plotly HTML written to ./artifacts. The model never writes HTML; it only triggers the tools that build the charts.

Supported intervals: 15m, 1h, 4h, 1d. Symbols: any Binance spot pair (BTCUSDT, ETHUSDT, SOLUSDT, XRPUSDT, DOGEUSDT, ...).

Model setup (BYOK)

backtestchat talks to any provider via LangChain's init_chat_model, configured with a provider:model string in BACKTESTCHAT_MODEL (or model = "..." in ./backtestchat.toml). The default setup uses OpenAI:

uv sync --extra openai
export BACKTESTCHAT_MODEL=openai:gpt-5.4-nano
export OPENAI_API_KEY=sk-...

Any provider init_chat_model supports works the same way: install the matching extra (--extra anthropic, --extra ollama, ...) and set BACKTESTCHAT_MODEL to that provider's provider:model string plus its API key (Ollama runs locally and needs no key).

If no model is configured, backtestchat chat prints these instructions and exits. Check what is resolved with backtestchat config.

Usage

uv run backtestchat chat

Then talk to it naturally:

you > what's BTC trading at?
you > backtest an ma crossover 20/50 on BTCUSDT 1h over the last 3 months
you > compare that against buy and hold and rsi
you > save that strategy            # asks you to confirm in the terminal
you > start a paper run with 5000 usdt   # asks you to confirm
you > list my paper runs

Charts open automatically in your browser and are saved under ./artifacts. Saving a strategy and starting a paper run pause for a y/n confirmation (human-in-the-loop, implemented with LangGraph interrupts).

Commands

backtestchat chat [--new] [--thread ID]   # agent REPL (resumes the last thread by default)
backtestchat runs list [--status active]  # list paper runs (stored state)
backtestchat runs sync                    # advance all active runs to the latest closed bar
backtestchat show [last|FILE]             # open a rendered chart artifact
backtestchat config                       # print resolved configuration

How paper runs work

A paper run does not backdate: the first simulated fill happens on the first bar that closes after you create the run, so a fresh run shows "waiting for first tick" until then. Advancing a run replays every closed bar since its last processed bar, one signal evaluation per bar. Because the already-processed-bar guard is the only cadence control, backtestchat runs sync is safe to run anytime and is idempotent.

LangSmith tracing (optional)

Set the standard env vars and traces appear in your LangSmith project - no code or flags required:

export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY=...

Configuration

Resolved in order: environment variables > ./backtestchat.toml > defaults.

Key Env var Default
model BACKTESTCHAT_MODEL (unset; required for chat)
data dir BACKTESTCHAT_DATA_DIR ./data
artifacts dir BACKTESTCHAT_ARTIFACTS_DIR ./artifacts

./data holds the sqlite store (strategies, paper runs, trades) and the LangGraph checkpoint database. ./artifacts holds rendered chart HTML. Both are gitignored.

Development

uv sync --extra openai  # dev dependencies included; keep your provider extra
uv run pytest -q        # deterministic, no network, no model key

The engine, signals, broker window logic, and paper runner are pure and tested against fixture bars. Market-data and agent layers are tested with mocked HTTP and a scripted fake model, so the whole suite runs offline.

License

MIT - see LICENSE.

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

backtestchat-0.1.0.tar.gz (133.6 kB view details)

Uploaded Source

Built Distribution

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

backtestchat-0.1.0-py3-none-any.whl (49.0 kB view details)

Uploaded Python 3

File details

Details for the file backtestchat-0.1.0.tar.gz.

File metadata

  • Download URL: backtestchat-0.1.0.tar.gz
  • Upload date:
  • Size: 133.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for backtestchat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6cf5d4c42eb439b28f198de0d42a8028c6574e3577b2c2216b6c32ee48cf0f5e
MD5 d2ac9b1b1d5874fe9d63c34b9229d48a
BLAKE2b-256 7b2d588fec0724953fc4aa93da1659620e3566537f06c96a8fea5c7d278fa181

See more details on using hashes here.

Provenance

The following attestation bundles were made for backtestchat-0.1.0.tar.gz:

Publisher: publish.yml on barisarat/backtestchat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file backtestchat-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: backtestchat-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 49.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for backtestchat-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b07b4560f4205c418c53ce08d60760f21f2c9379fcd708ecfc1b764cdcc87156
MD5 44e42d7f5ba6d654baadf7d009f233b7
BLAKE2b-256 cc235e0b922b3b94a4944bc39d0fa9c6aedd1db8724b95ae47b13aceb7ff2a6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for backtestchat-0.1.0-py3-none-any.whl:

Publisher: publish.yml on barisarat/backtestchat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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