Skip to main content

Python SDK for Composer.Trade API

Project description

Composer Trade Python SDK

Twitter PyPI Reddit Community

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.

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

composer_trade_py-0.5.0.tar.gz (136.3 kB view details)

Uploaded Source

Built Distribution

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

composer_trade_py-0.5.0-py3-none-any.whl (81.2 kB view details)

Uploaded Python 3

File details

Details for the file composer_trade_py-0.5.0.tar.gz.

File metadata

  • Download URL: composer_trade_py-0.5.0.tar.gz
  • Upload date:
  • Size: 136.3 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for composer_trade_py-0.5.0.tar.gz
Algorithm Hash digest
SHA256 1ebb89d1419e5f10d3e52410f43ae77880c144a489525802fe7b0c9d26fd8573
MD5 602454ef45aabe830e6e8bc56139293f
BLAKE2b-256 82f1194936c02a91d2848c740363dc3d77c4189aa010b183502d246050854d51

See more details on using hashes here.

File details

Details for the file composer_trade_py-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: composer_trade_py-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 81.2 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for composer_trade_py-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 644e2bb6b9e04e619922db637ad331392b320712ee8dececa9a1abaa79d1bb14
MD5 cbb2bbc0b1ea9dd63615250710a5d7c0
BLAKE2b-256 0d33c61084beb9265764cd371695f34eb75d27d0099a64b8c6b1c1c576a12052

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