project-x-py

ProjectX Python SDK

PyPI version Python versions License Documentation

project-x-py is a high-performance async Python SDK for the ProjectX Trading Platform Gateway API. This library enables developers to build sophisticated trading strategies and applications by providing comprehensive async access to futures trading operations, real-time market data, Level 2 orderbook analysis, and 64 named indicators (Polars implementations; not a full TA-Lib port).

!!! note “Version 4.4.2” Latest Release: TopstepX-only Gateway SDK (api.topstepx.com / rtc.topstepx.com) with native brackets, risk OCO and entry-order gating, stale-feed watchdog, OrderSubmissionUncertainError, and 64 named Polars indicators (not a full TA-Lib port). v4.4.2 polls fill status up to 6 times (1s apart) in place_bracket_order when the fill wait returns with 0 filled, so a lagging fill still gets stop/target legs (#179). v4.4.1 fixes orderbook get_statistics() under polars 2.0: trade-side counts use pl.len() because pl.count() no longer accepts zero arguments (#168). v4.4.0 makes Features an enum.StrEnum: str() and f-strings return the member value (for example "orderbook") instead of "Features.ORDERBOOK"; equality, .value, and JSON are unchanged (#155). v4.3.3 bumps runtime cachetools to 7.2.0 (>=7.1.7); TTLCache use is unchanged and typing matches cachetools 7 stubs (#150, #119). v4.3.2 skips the bounded-statistics counter sweep in RealtimeDataManager.cleanup() so teardown does not read counters that are about to be discarded (#98). v4.3.1 coalesces quote_update / market_depth forwards so an RTH-open flood cannot starve NEW_BAR (#143). v4.3.0 added aggregate_session_bars() and reconnect health fixes (#140, #141). See the v3 → v4 migration guide.

!!! note “Stable Production Release” This project maintains strict semantic versioning. v4.0.0 is a major release with documented breaking changes. Deprecation warnings are provided for at least 2 minor versions before removal.

!!! important “Client Library/SDK” This is a client library/SDK, not a trading strategy. It provides the tools and infrastructure to help developers create their own trading strategies that integrate with the ProjectX platform.

Quick Start

Install the package:

uv add project-x-py

Or with pip:

pip install project-x-py

Set up your credentials:

export PROJECT_X_API_KEY='your_api_key'  # pragma: allowlist secret
export PROJECT_X_USERNAME='your_username'

Start trading:

import asyncio
from project_x_py import TradingSuite
from project_x_py.indicators import RSI, SMA, MACD

async def main():
    # V3.5.4: Multi-instrument TradingSuite with chaos theory indicators
    suite = await TradingSuite.create(
        instruments=["MNQ", "ES", "MGC"],  # Multiple instruments
        timeframes=["1min", "5min"],
        features=["orderbook", "risk_manager"]
    )

    # Access specific instruments
    mnq_context = suite["MNQ"]
    es_context = suite["ES"]

    # Get market data with technical analysis
    mnq_data = await suite.client.get_bars('MNQ', days=30, interval=60)
    mnq_data = RSI(mnq_data, period=14)  # Add RSI
    mnq_data = SMA(mnq_data, period=20)  # Add moving average

    # Multi-instrument trading
    await mnq_context.orders.place_limit_order(
        contract_id=mnq_context.instrument_info.id,
        side=0, size=1, limit_price=21050.0
    )

    # Portfolio-level analytics
    for symbol, context in suite.items():
        price = await context.data.get_current_price()
        print(f"{symbol}: ${price:.2f}")

    await suite.disconnect()

# Run the async function
asyncio.run(main())

Key Features

🚀 Core Trading Features

📊 Market Data & Analysis

🔧 Developer Tools

⚡ Real-time Capabilities

🛡️ Enterprise Features (v3.3.4)

Architecture Overview

Core Components

TradingSuite - Multi-instrument trading environment with automatic initialization

# Single instrument (backward compatible)
suite = await TradingSuite.create(["MNQ"], features=["orderbook", "risk_manager"])

# Multiple instruments (v3.5.0 new capability)
suite = await TradingSuite.create(["MNQ", "ES", "MGC"], features=["orderbook", "risk_manager"])
mnq_context = suite["MNQ"]  # Access specific instrument

ProjectX Client - Main client for API interactions and authentication

Order Management

Position & Risk Management

Real-time Data Processing

Technical Analysis

Statistics & Monitoring (v3.3.0)

Documentation Structure

Getting Started

User Guide

API Reference

Examples

Development

Migration

Recent Changes

v3.5.7 - Order Placement Serialization Fix (2025-02-02)

v3.5.3 - Complete Documentation & Testing Improvements (2025-01-31)

v3.5.2 - TradingSuite with Enhanced Testing & Documentation (2025-01-31)

v3.5.1 - Critical Bug Fixes (2025-01-30)

v3.5.0 - Multi-Instrument TradingSuite (2025-01-25)

v3.4.0 - ETH vs RTH Trading Sessions (2025-08-28)

v3.3.6 - Major Quality Assurance Release (2025-08-28)

See the complete changelog for all version history.

License

MIT License - see LICENSE for details.