Skip to main content

CPZ — Python SDK for Strategy Lab, Risk, Backtesting, and Execution (multi-broker)

Project description

🚀 CPZ AI — Python SDK

CPZ Lab - Advanced Trading & Risk Management Platform

CPZ Lab

CI Coverage Python

Install

pip install cpz-ai
# dev
pip install -e .[dev]

60-second Quickstart (Sync)

import cpz
from cpz.execution.models import OrderSubmitRequest
from cpz.execution.enums import OrderSide, OrderType, TimeInForce

client = cpz.clients.sync.CPZClient()
client.execution.use_broker("alpaca", env="paper")

order = client.execution.submit_order(OrderSubmitRequest(
    symbol="AAPL",
    side=OrderSide.BUY,
    qty=10,
    type=OrderType.MARKET,
    time_in_force=TimeInForce.DAY,
))
print(order.id, order.status)

Execution Architecture

CPZClient.execution  -->  BrokerRouter  -->  AlpacaAdapter
                              |               ^
                              +---- future brokers (IBKR, Tradier, ...)

Configuration (.env)

Key Description Example Required
CPZ_ENV SDK environment dev No
CPZ_LOG_LEVEL Log level INFO No
CPZ_REQUEST_TIMEOUT_SECONDS Default request timeout 30 No
ALPACA_ENV Alpaca environment paper Yes (if using Alpaca)
ALPACA_API_KEY_ID Alpaca API key AK... Yes (if using Alpaca)
ALPACA_API_SECRET_KEY Alpaca API secret ... Yes (if using Alpaca)

Usage

Selecting a broker

client.execution.use_broker("alpaca", env="paper")

Submit / cancel / replace order (sync)

from cpz.execution.models import OrderSubmitRequest, OrderReplaceRequest
from cpz.execution.enums import OrderSide, OrderType, TimeInForce

req = OrderSubmitRequest(symbol="AAPL", side=OrderSide.BUY, qty=1,
                         type=OrderType.MARKET, time_in_force=TimeInForce.DAY)
order = client.execution.submit_order(req)
client.execution.cancel_order(order.id)
client.execution.replace_order(order.id, OrderReplaceRequest(qty=2))

Async + Streaming

import asyncio
from cpz.clients.async_ import AsyncCPZClient

async def main():
    client = AsyncCPZClient()
    await client.execution.use_broker("alpaca", env="paper")
    async for q in client.execution.stream_quotes(["AAPL", "MSFT"]):
        print(q.symbol, q.bid, q.ask)
        break

asyncio.run(main())

Get account / positions

acct = client.execution.get_account()
positions = client.execution.get_positions()

CLI

cpz-ai broker list
cpz-ai broker use alpaca --env paper
cpz-ai order submit --symbol AAPL --side buy --qty 10 --type market --tif day
cpz-ai order get --id <id>
cpz-ai positions
cpz-ai stream quotes --symbols AAPL,MSFT

Error handling

Catch cpz.common.errors.CPZBrokerError. Broker errors are mapped to CPZ errors.

Logging & Redaction

Structured JSON logging via structlog, with redaction of Authorization, ALPACA_API_SECRET_KEY, and similar. Configure level via CPZ_LOG_LEVEL.

Testing & Quality

  • make test (coverage goal ≥ 85%)
  • mypy --strict

Contributing

Style: ruff/black/isort, pre-commit, branch naming. See CONTRIBUTING.md.

Versioning & Release

Bump version in pyproject.toml, build, and publish to PyPI.

Roadmap

Next brokers: IBKR, Tradier, …

Security

See SECURITY.md. No LICENSE file is included intentionally.

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

cpz_ai-0.1.2.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

cpz_ai-0.1.2-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file cpz_ai-0.1.2.tar.gz.

File metadata

  • Download URL: cpz_ai-0.1.2.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for cpz_ai-0.1.2.tar.gz
Algorithm Hash digest
SHA256 845ca93ea78d957477e534c6c65a8b953150d91a55bf13e48d405a8d41ee86f5
MD5 e0306fd19e78fd505c0849e6761ee38f
BLAKE2b-256 65a0dde89d26575dd18e09a21f2012c9117ee57752f54dde30b62da0db5c9e01

See more details on using hashes here.

File details

Details for the file cpz_ai-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: cpz_ai-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for cpz_ai-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7cde8df5c36ed128511cc30823851dbc2a9546c207dbcdae81e72f71d0975e0a
MD5 56027f6a81ad1fc86773e2f0f602ff02
BLAKE2b-256 0fbeca20d401f3b5f8265dca4f8d8e54e3cb14e091c0a51a56f92ecfa111a24b

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