Programmatic Strategy Python SDK
An Unoffical Python SDK for the Composer trading platform API. Build, backtest, and deploy automated trading strategies (called "symphonies") programmatically.
Features
- Complete API Coverage: All endpoints from the Composer API
- Type-Safe Models: Full Pydantic models for all requests and responses
- Programmatic Symphony Building: Build trading strategies using Python code
- Backtesting: Test strategies before deploying
- Portfolio Management: View holdings, stats, and history
- Direct Trading: Place orders directly
- Market Data: Access options chains and contract data
Installation
pip install composer-trade-py
Quick Start
Building a Symphony
Create automated trading strategies programmatically:
from composer.models.common.symphony import Asset, WeightCashEqual
from dotenv import load_dotenv
load_dotenv()
# Initialize client
client = ComposerClient(
api_key=os.getenv("COMPOSER_API_KEY"),
api_secret=os.getenv("COMPOSER_API_SECRET"),
)
# Build a simple strategy
symphony = SymphonyDefinition(
name="Buy and Hold AAPL",
description="Simple buy and hold strategy",
rebalance="daily",
children=[
WeightCashEqual(
children=[Asset(ticker="AAPL", name="Apple Inc")]
)
]
)
# Create it in your account
result = client.user_symphony.create_symphony(
name="Buy and Hold AAPL",
color="#FF6B6B",
hashtag="#AAPL",
symphony=symphony
)
print(f"Created symphony: {result.symphony_id}")
Backtesting
Test your strategies before deploying:
from composer.models.backtest import BacktestParams
from composer.models.common import SymphonyDefinition
# Run a backtest
result = client.user_symphony.backtest_symphony(
symphony_id="your-symphony-id",
params=BacktestParams(
capital=10000.0,
start_date="2020-01-01",
end_date="2024-01-01",
benchmark_tickers=["SPY"]
)
)
print(f"Sharpe Ratio: {result.stats.sharpe_ratio}")
print(f"Cumulative Return: {result.stats.cumulative_return}")
Or run a backtest with a custom symphony definition:
from composer.models.backtest import BacktestParams
from composer.models.common import SymphonyDefinition
result = client.backtest.run(
BacktestParams(
capital=10000.0,
start_date="2020-01-01",
end_date="2024-01-01",
benchmark_tickers=["SPY"],
symphony=symphony
)
)
print(f"Sharpe Ratio: {result.stats.sharpe_ratio}")
print(f"Cumulative Return: {result.stats.cumulative_return}")
Common Building Blocks
You can also checkout the composer-trade-common package for how to import and use commonly used blocks in your symphonies.
Documentation
For SDK Documentation:, visit the the docs here:
For direct API documentation, visit the various Composer API Docs:
Development
We recommend using uv for development.
To set up the development environment:
# Install dependencies
uv sync --group dev
# Install the pre-commit hook
pre-commit install
If you are working on docs, install the docs group:
uv sync --group docs
The pre-commit hook runs ruff format, ruff check, and basedpyright before each commit to ensure code quality.
Metadata
Release files for composer-trade-py 0.5.1
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 |
|---|---|---|---|---|
| composer_trade_py-0.5.1.tar.gz | 136.8 kB | Without provenance | Details for composer_trade_py-0.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| composer_trade_py-0.5.1-py3-none-any.whl | Python 3 | none | any | Details for composer_trade_py-0.5.1-py3-none-any.whl |
Total release size: 218.0 kB
Release files / composer_trade_py-0.5.1.tar.gz
| Download URL | composer_trade_py-0.5.1.tar.gz |
|---|---|
| Size | 136.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0c8571b7a3541a0991f843e71c739028df66698c1d06b0faf6a38460fc4a8519
|
|
BLAKE2b-256 checksum How to use checksums |
5b51d54b58ba1d6906faf6fb052fb958602164be0cff05e63de3375234cca71a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / composer_trade_py-0.5.1-py3-none-any.whl
| Download URL | composer_trade_py-0.5.1-py3-none-any.whl |
|---|---|
| Size | 81.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d48e582f807d4226fe8cd6067ee471dfa265d648b6d3bfc9cfadbcfa451ed7ca
|
|
BLAKE2b-256 checksum How to use checksums |
ab2e5ed3b4083babbdb1825d00f48274884525ae5fc7f8a7fe5b74e4776e1cbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for composer-trade-py 0.5.1
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.