Trading infrastructure library with backtesting
Project description
tradedesk
Contributing: CONTRIBUTING.md
tradedesk is an event-driven trading framework for building, running, and evaluating systematic trading strategies across both backtesting and live broker environments.
It provides:
- Event-based strategy execution
- Unified backtest and live broker runtime model
- Market data aggregation and indicator framework
- Portfolio orchestration and risk management
- Trade recording, metrics, and reporting
The framework is designed so that strategies react to events --- not broker implementations --- enabling the same strategy code to run unchanged in both backtest and live environments.
Core Concepts
Event-Driven Architecture
All major subsystems communicate via events:
- Market data events (ticks, candles)
- Strategy events (signals)
- Execution events (order completions and broker fills)
- Portfolio events (position updates and lifecycle transitions)
- Recording events (trade lifecycle, equity, and reporting)
As a user, you primarily:
- Implement a strategy that reacts to candle updates
- Optionally subscribe to events for custom analytics or logging
Architecture Overview
For a concise public map of the system, see ARCHITECTURE.md. tradedesk is built around an event-driven core that wires together market data, strategy logic, portfolio management, execution adapters (IG for live trading, Dukascopy-backed backtests), and a recording layer for metrics and reports. The public interfaces expose reusable building blocks (marketdata, strategy, portfolio, recording) with clear data-flow guarantees across backtest and live paths.
Basic Strategy Structure
A strategy derives from the base strategy class and implements candle handling logic.
Typical flow:
- Market data arrives (tick or candle)
- Aggregation produces candles
- Strategy receives
on_candle_close - Strategy emits order requests
- Execution layer processes orders
- Portfolio updates positions
- Recording captures trade lifecycle
Running a Backtest
Backtesting uses the same event model as live trading.
High-level flow:
- Dukascopy cache data is loaded via
BacktestClient.from_dukascopy_cache(...) run_backtest(...)drives the event loop and recording pipeline- Strategy code executes unchanged
- Portfolio and recording operate identically to live mode
See docs/backtesting_guide.md for the current cache-backed workflow.
Live Trading (IG)
The IG execution module provides:
- REST client for order management
- Streaming price integration
- Position synchronization
- Retry and resilience handling
Your strategy remains unchanged --- only the execution configuration differs.
Orders placed through request_order(...) continue to flow through
OrderExecutionHandler in both backtest and live sessions. For clients such as
IG that do not publish their own position-open callbacks, tradedesk emits a
PositionOpenedEvent immediately after a confirmed opening fill. That keeps
recording subscribers and custom event consumers aligned across backtest,
DEMO, and LIVE runs without double-publishing for clients that already emit
their own lifecycle events.
IG Credentials
Live IG runs read credentials from environment variables:
IG_API_KEY(required)IG_USERNAME(required)IG_PASSWORD(required)IG_ENVIRONMENT(optional, defaults toDEMO, valid values areDEMOandLIVE)
Example:
IG_API_KEY=... \
IG_USERNAME=... \
IG_PASSWORD=... \
IG_ENVIRONMENT=DEMO \
python your_live_runner.py
tradedesk authenticates with IG and captures the short-lived session headers
(CST and X-SECURITY-TOKEN) from the login response automatically. You do not
configure those session tokens yourself.
Portfolio & Risk
The portfolio subsystem:
- Tracks positions
- Applies risk policies
- Reconciles fills
- Emits portfolio events
Risk controls such as spread limits and portfolio-level order gates can reject orders before broker submission.
Recording & Reporting
The recording subsystem:
- Tracks trades and equity curves
- Computes excursions and performance metrics
- Generates structured reports from position lifecycle events and fills
Users can subscribe to recording events for custom reporting pipelines.
Typical Project Structure
my_strategy/
strategy.py
run_backtest.py
config.py
Installation
Python 3.11+ is required.
Install the published package:
pip install tradedesk
For local development:
pip install -e '.[dev]'
Documentation
See the docs/ directory for:
- Backtesting guide
- Strategy guide
- Portfolio guide
- Indicator guide
- Aggregation guide
- Risk management guide
- Metrics guide
Public package entry points are grouped under:
tradedesk.marketdatatradedesk.executiontradedesk.execution.backtesttradedesk.portfoliotradedesk.recordingtradedesk.strategy
tradedesk is designed for clarity, determinism, and event-level transparency.
See Also
- docs/backtesting_guide.md
- docs/strategy_guide.md
- docs/indicator_guide.md
- docs/crash-recovery.md
Contributing
See CONTRIBUTING.md for guidelines on contributing to tradedesk.
License
Licensed under the Apache License, Version 2.0. See: https://www.apache.org/licenses/LICENSE-2.0
Copyright 2026 Radius Red Ltd. | Contact
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 tradedesk-0.12.0.tar.gz.
File metadata
- Download URL: tradedesk-0.12.0.tar.gz
- Upload date:
- Size: 462.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 |
9f91cc8bd22fe294a7c477249d75563a9ba76d7d37b88dc9560cc5c0c818d651
|
|
| MD5 |
436b9eac3c97ffdcf3afa1b6cd2217a8
|
|
| BLAKE2b-256 |
a8723bc05156cf2ea3d91a79cff60c748315163dfba55019adcfb01e4e8c2b0d
|
Provenance
The following attestation bundles were made for tradedesk-0.12.0.tar.gz:
Publisher:
publish.yml on radiusred/tradedesk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tradedesk-0.12.0.tar.gz -
Subject digest:
9f91cc8bd22fe294a7c477249d75563a9ba76d7d37b88dc9560cc5c0c818d651 - Sigstore transparency entry: 1357018983
- Sigstore integration time:
-
Permalink:
radiusred/tradedesk@edbe25e1851763b1782a902e66d98f6f57c5a19e -
Branch / Tag:
refs/tags/v0.12.0 - Owner: https://github.com/radiusred
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@edbe25e1851763b1782a902e66d98f6f57c5a19e -
Trigger Event:
release
-
Statement type:
File details
Details for the file tradedesk-0.12.0-py3-none-any.whl.
File metadata
- Download URL: tradedesk-0.12.0-py3-none-any.whl
- Upload date:
- Size: 128.6 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 |
6fdd32f43add9a54182db44a0c9a453f121147bad7e885c33256cac3e522edbe
|
|
| MD5 |
c0103d634c2ab8b51bee77b8b09eac51
|
|
| BLAKE2b-256 |
f7ad69f6ccb3fc4c9444d5fc880dc05ab4bb3464fa834051006ac57216b6d1a0
|
Provenance
The following attestation bundles were made for tradedesk-0.12.0-py3-none-any.whl:
Publisher:
publish.yml on radiusred/tradedesk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tradedesk-0.12.0-py3-none-any.whl -
Subject digest:
6fdd32f43add9a54182db44a0c9a453f121147bad7e885c33256cac3e522edbe - Sigstore transparency entry: 1357018997
- Sigstore integration time:
-
Permalink:
radiusred/tradedesk@edbe25e1851763b1782a902e66d98f6f57c5a19e -
Branch / Tag:
refs/tags/v0.12.0 - Owner: https://github.com/radiusred
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@edbe25e1851763b1782a902e66d98f6f57c5a19e -
Trigger Event:
release
-
Statement type: