Thank you for considering contributing to the ProjectX Python SDK! This document provides guidelines and instructions to help you contribute effectively.
- Development Setup
- Code Style and Conventions
- Pull Request Process
- Testing Guidelines
- Documentation Requirements
- Architecture Guidelines
- Python 3.12 or higher
- UV package manager (recommended)
-
Clone the repository
git clone https://github.com/yourusername/project-x-py.git cd project-x-py -
Set up the development environment with UV (recommended)
# Install UV if you haven't already curl -sSf https://install.determinate.systems/uv | python3 - # Install development dependencies uv sync
-
Alternative setup with pip
pip install -e ".[dev]" -
Verify installation
uv run pytest -xvs tests/
This project follows strict code style guidelines to maintain consistency and quality:
- Use Python 3.12+ features and syntax
- Use modern typing features (e.g.,
int | Noneinstead ofOptional[int])
- We use Ruff for both formatting and linting
- Always run these commands before submitting code:
# Format code uv run ruff format . # Lint code (with safe auto-fix) uv run ruff check --fix .
- All code MUST include comprehensive type hints
- Use Python 3.10+ union syntax:
int | Noneinstead ofOptional[int] - Use
isinstance(x, (A | B))instead ofisinstance(x, (A, B)) - Use
dict[str, Any]instead ofDict[str, Any]
- This project uses an async-first architecture
- All I/O operations must be async
- Use
async/awaitconsistently - Use appropriate locking mechanisms for thread safety
- Use Polars exclusively for DataFrame operations
- Never include Pandas fallbacks or compatibility code
- Use vectorized operations where possible
- Validate DataFrame schemas before operations
- Wrap ProjectX API calls in try-catch blocks
- Log errors with context:
self.logger.error(f"Error in {method_name}: {e}") - Return meaningful error responses instead of raising exceptions
- Validate input parameters and API data
-
Create a feature branch from
maingit checkout -b feature/your-feature-name
-
Implement your changes following the code style guidelines
-
Add/update tests to cover your changes
-
Ensure all tests pass
uv run pytest -xvs tests/
-
Format and lint your code
uv run ruff format . uv run ruff check --fix .
-
Update documentation to reflect your changes
-
Submit a pull request with:
- Clear description of the changes
- Reference to any related issues
- Explanation of how to test the changes
-
Address review feedback until your PR is approved
All code contributions should include appropriate tests:
- Maintain or improve test coverage with each PR
- Write both unit and integration tests
- Follow the existing test pattern in the
tests/directory - Use descriptive test names (
test_should_validate_market_data) - Include tests for both success and failure scenarios
- Unit tests: Focus on testing individual functions/methods
- Integration tests: Test the interaction between components
- Comprehensive tests: Test full workflows and realistic scenarios
# Run all tests
uv run pytest
# Run specific test file
uv run pytest tests/test_async_client.py
# Run tests with coverage report
uv run pytest --cov=src/project_x_pyGood documentation is essential for this project:
- All public classes, methods, and functions MUST have docstrings
- Follow the established docstring format (Google style)
- Include Args and Returns sections in docstrings
- Document expected parameter types and return values
- Include examples for complex methods
- Update the README.md when adding new features
- Add examples to the
examples/directory for significant features - Keep the documentation synchronized with the code
- Add/update Sphinx documentation for public APIs
- Build and verify documentation changes:
cd docs uv run sphinx-build -b html . _build/html
The SDK uses a modular architecture where large components are split into multi-file packages:
-
Client Module (
client/): Core async client functionalityauth.py: Authentication and token managementhttp.py: HTTP client and request handlingcache.py: Caching for instruments and market datamarket_data.py: Market data operationstrading.py: Trading operationsbase.py: Base class combining mixins
-
Trading Modules:
order_manager/: Order lifecycle management (10 modules)position_manager/: Portfolio and risk management (12 modules)
-
Real-time Modules:
realtime/: WebSocket client functionality (8 modules)realtime_data_manager/: Real-time OHLCV data (9 modules)
-
Utilities (
utils/): Shared utilities (10 modules)- Trading calculations, portfolio analytics, pattern detection
- Market microstructure, formatting, environment handling
-
Indicators (
indicators/): 58+ technical indicators- Organized by category (momentum, overlap, volatility, etc.)
- Place new functionality in the appropriate existing module
- For large features, consider creating a new sub-module
- Maintain backward compatibility for all public APIs
- Follow the established mixin pattern for client extensions
- Implement time window filtering for analysis methods
- Filter data BEFORE processing to reduce memory usage
- Implement appropriate data cleanup for old entries
- Use appropriate data types (int vs float vs str)
- Consider memory management in all components
- Follow the established API patterns
- Use async context managers for resource management
- Implement proper error handling and validation
- Provide clear feedback on API errors
- Follow the ProjectX API documentation
- Use configuration objects for URL management
- Never hardcode platform URLs
- Handle all required/optional fields in API responses
- Support both TopStepX endpoints and custom endpoints
If you encounter any bugs or have feature requests:
- Check if the issue already exists in the GitHub issue tracker
- If not, create a new issue with:
- Detailed description of the issue
- Steps to reproduce
- Expected vs actual behavior
- Environment information (Python version, OS, etc.)
By contributing to this project, you agree that your contributions will be licensed under the project's MIT license.
If you have any questions or need help, please open an issue or contact the project maintainers.
Thank you for contributing to the ProjectX Python SDK!