Skip to main content

A professional backtesting and live trading framework for algorithmic trading strategies with footprint analysis and market microstructure.

Project description

Tradetropy

Tradetropy

PyPI

A professional backtesting and live trading framework for algorithmic trading strategies, with first-class support for footprint analysis and market microstructure.

Write a strategy once and run it unchanged across backtest, live and replay - the engine differences are a transport detail behind the same Strategy API.

Features

  • Backtesting engine over candles or ticks with realistic order simulation.
  • Live trading over WebSockets (CCXT Pro) and MetaTrader 5.
  • Order flow and footprint: large trades, Deep Trades (L2/L3 absorption and sweeps), cumulative delta, COT, volume profile and liquidity overlays.
  • Indicator library: the classic studies plus market-structure tools, all through one declarative contract.
  • Optimization and pools, Monte Carlo robustness and interactive Bokeh plotting.
  • Data management with NumPy .npz / CSV IO built in (Parquet and HDF5 optional) and bundled sample datasets.

Installation

pip install tradetropy

The base install includes everything for backtesting, plotting and data IO. Broker integrations and Parquet are optional extras:

pip install tradetropy[mt5]       # MetaTrader 5
pip install tradetropy[ccxt]      # CCXT crypto exchanges (live + streaming)
pip install tradetropy[bybit]     # Bybit (pybit)
pip install tradetropy[parquet]   # Parquet IO (pyarrow)
pip install tradetropy[hdf5]      # HDF5 IO (PyTables; not available on Termux)
pip install tradetropy[all]       # all runtime extras

On desktop (Windows/macOS/Linux) every dependency installs as a prebuilt wheel, so no compiler is needed. Termux (Android) is the exception - the scientific stack builds from source there; see the Termux install guide.

Quickstart

Every loader in tradetropy.datasets returns ready-to-use data, so this runs with no data files or API keys:

from tradetropy import Strategy, BacktestEngine
from tradetropy.ta import SMA
from tradetropy.datasets import load_btcusd_1m


class SmaCross(Strategy):
    def init(self):
        self.btc = self.subscribe_ohlc('BTCUSD', '1m', window_size=200)
        self.fast = self.add_indicator(self.btc.close, SMA(10))
        self.slow = self.add_indicator(self.btc.close, SMA(30))

    def on_data(self):
        if self.fast[-1] > self.slow[-1]:
            if not self.sesh.positions('BTCUSD'):
                self.sesh.buy('BTCUSD', volume=1)
        else:
            for pos in self.sesh.positions('BTCUSD'):
                self.sesh.position_close(pos.ticket)


engine = BacktestEngine.by_klines(SmaCross(), data=(load_btcusd_1m(),))
engine.run()
print(engine.stats)

More runnable scripts are in examples/.

Documentation

Full documentation - user guide and API reference - is at https://michiTrader.github.io/tradetropy/.

To build the docs locally:

pip install tradetropy[docs]
mkdocs serve

Contributing

See CONTRIBUTING.md. Development setup:

git clone https://github.com/michiTrader/tradetropy.git
cd tradetropy
uv sync
uv run pytest

Risk disclaimer

Tradetropy is provided "AS IS", without warranty of any kind. Trading financial instruments involves risk of loss of capital - you may lose part or all of your funds. Always test first on a demo / testnet / paper account and verify that orders, positions and balances behave as expected before trading with real money. Broker and exchange APIs may change without notice and break a connector. The authors and contributors are not responsible for any losses, damages or execution failures arising from the use of this software. This is not financial, investment or legal advice, and you are responsible for complying with the laws of your jurisdiction and your broker/exchange terms of service.

The full disclaimer is available at runtime as tradetropy.LIVE_DISCLAIMER.

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

tradetropy-0.2.2.tar.gz (704.1 kB view details)

Uploaded Source

Built Distribution

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

tradetropy-0.2.2-py3-none-any.whl (766.6 kB view details)

Uploaded Python 3

File details

Details for the file tradetropy-0.2.2.tar.gz.

File metadata

  • Download URL: tradetropy-0.2.2.tar.gz
  • Upload date:
  • Size: 704.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tradetropy-0.2.2.tar.gz
Algorithm Hash digest
SHA256 44942a9a2eae60e5996b65fdb06c959671cb0f74a322bbc6270898c44b68dbfa
MD5 d574b4a7f4a6f0d0820eba9cc84af670
BLAKE2b-256 7ebf2c69ca7c011e1e14358e9e5d6d69790d8ae9c6a9f500e7fdd2c7d8ff7aee

See more details on using hashes here.

File details

Details for the file tradetropy-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: tradetropy-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 766.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tradetropy-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fec81cb68550efffb0a7356d224269398297543f782512d93487d5db1bb15e93
MD5 70485fcb47f1c7c2158c07a8cff43894
BLAKE2b-256 eaed4caa9227686fc22a04f9ee08e4c3c79b7a2cb59643023b7a6c90b47f4524

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