Skip to content

Commit 1cbffd4

Browse files
Fix test failures in auth tests and market hub tests
1 parent af43f81 commit 1cbffd4

46 files changed

Lines changed: 5749 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.flake8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
max-line-length = 100
3+
exclude = .git,__pycache__,build,dist
4+
ignore = E203, W503
5+
# E203: whitespace before ':' (black/pep8 disagree)
6+
# W503: line break before binary operator (black/pep8 disagree)

.github/workflows/tests.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Python Tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.8", "3.9", "3.10", "3.11"]
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
python -m pip install .[test]
28+
29+
- name: Run tests with pytest
30+
run: |
31+
pytest --cov=projectx_sdk
32+
33+
- name: Upload coverage to Codecov
34+
uses: codecov/codecov-action@v3
35+
with:
36+
file: ./coverage.xml
37+
fail_ci_if_error: false
38+
39+
lint:
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- uses: actions/checkout@v3
44+
- name: Set up Python
45+
uses: actions/setup-python@v4
46+
with:
47+
python-version: "3.10"
48+
49+
- name: Install dependencies
50+
run: |
51+
python -m pip install --upgrade pip
52+
python -m pip install black flake8 isort mypy
53+
54+
- name: Lint with flake8
55+
run: |
56+
flake8 projectx_sdk tests
57+
58+
- name: Check formatting with black
59+
run: |
60+
black --check projectx_sdk tests
61+
62+
- name: Check imports with isort
63+
run: |
64+
isort --check-only --profile black projectx_sdk tests
65+
66+
- name: Type check with mypy
67+
run: |
68+
mypy projectx_sdk
69+
70+
build:
71+
needs: [test, lint]
72+
runs-on: ubuntu-latest
73+
74+
steps:
75+
- uses: actions/checkout@v3
76+
- name: Set up Python
77+
uses: actions/setup-python@v4
78+
with:
79+
python-version: "3.10"
80+
81+
- name: Install dependencies
82+
run: |
83+
python -m pip install --upgrade pip
84+
python -m pip install build twine
85+
86+
- name: Build package
87+
run: |
88+
python -m build
89+
90+
- name: Check distribution
91+
run: |
92+
twine check dist/*

.pre-commit-config.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-toml
10+
11+
- repo: https://github.com/psf/black
12+
rev: 23.3.0
13+
hooks:
14+
- id: black
15+
16+
- repo: https://github.com/pycqa/isort
17+
rev: 5.12.0
18+
hooks:
19+
- id: isort
20+
args: ["--profile", "black"]
21+
22+
- repo: https://github.com/pycqa/flake8
23+
rev: 6.0.0
24+
hooks:
25+
- id: flake8
26+
additional_dependencies: [flake8-docstrings]
27+
28+
- repo: https://github.com/pre-commit/mirrors-mypy
29+
rev: v1.3.0
30+
hooks:
31+
- id: mypy
32+
additional_dependencies:
33+
- types-requests
34+
- types-python-dateutil

README.md

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# ProjectX Gateway API SDK for Python (Unofficial)
2+
3+
A Python client library for the ProjectX Gateway API, enabling proprietary trading firms and evaluation providers to interact with ProjectX's trading platform programmatically.
4+
5+
> **DISCLAIMER:** This is an **unofficial** SDK. The author(s) of this package are not affiliated with or endorsed by ProjectX. This is a community-developed tool to interact with their public API.
6+
7+
[![Python Tests](https://github.com/ChristianJStarr/projectx-sdk-python/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/ChristianJStarr/projectx-sdk-python/actions/workflows/tests.yml)
8+
[![PyPI version](https://badge.fury.io/py/projectx-sdk.svg)](https://badge.fury.io/py/projectx-sdk)
9+
[![Python Version](https://img.shields.io/pypi/pyversions/projectx-sdk.svg)](https://pypi.org/project/projectx-sdk/)
10+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
11+
12+
## Features
13+
14+
- Complete coverage of ProjectX Gateway API endpoints
15+
- Support for real-time WebSocket updates via SignalR
16+
- Pythonic interface with proper error handling
17+
- Support for all ProjectX environments
18+
19+
## Installation
20+
21+
```bash
22+
pip install projectx-sdk
23+
```
24+
25+
For development, you can install with additional tools:
26+
27+
```bash
28+
pip install projectx-sdk[dev]
29+
```
30+
31+
## Quick Start
32+
33+
```python
34+
from projectx_sdk import ProjectXClient, OrderType, OrderSide
35+
36+
# Initialize with API key
37+
client = ProjectXClient(
38+
username="your_username",
39+
api_key="your_api_key",
40+
environment="topstepx" # Or another supported environment
41+
)
42+
43+
# Get all active accounts
44+
accounts = client.accounts.search(only_active_accounts=True)
45+
account_id = accounts[0].id if accounts else None
46+
47+
if account_id:
48+
# Search for contracts
49+
contracts = client.contracts.search(search_text="NQ", live=False)
50+
51+
if contracts:
52+
contract_id = contracts[0].id
53+
54+
# Place a market order
55+
order = client.orders.place(
56+
account_id=account_id,
57+
contract_id=contract_id,
58+
type=OrderType.MARKET,
59+
side=OrderSide.BUY,
60+
size=1
61+
)
62+
63+
print(f"Order placed with ID: {order['orderId']}")
64+
65+
# Set up real-time order updates
66+
def on_order_update(order_data):
67+
print(f"Order update: {order_data}")
68+
69+
client.realtime.user.subscribe_orders(account_id, callback=on_order_update)
70+
client.realtime.start()
71+
```
72+
73+
## Environment Support
74+
75+
The SDK supports all ProjectX environments:
76+
77+
| Platform | SDK Key | Tested |
78+
|----------|---------|--------|
79+
| Alpha Ticks | `alphaticks` ||
80+
| Blue Guardian | `blueguardian` ||
81+
| Blusky | `blusky` ||
82+
| E8X | `e8x` ||
83+
| Funding Futures | `fundingfutures` ||
84+
| The Futures Desk | `futuresdesk` ||
85+
| Futures Elite | `futureselite` ||
86+
| FXIFY Futures | `fxifyfutures` ||
87+
| GoatFunded | `goatfunded` ||
88+
| TickTickTrader | `tickticktrader` ||
89+
| TopOneFutures | `toponefutures` ||
90+
| TopstepX | `topstepx` ||
91+
| TX3Funding | `tx3funding` ||
92+
93+
> Note: ✅ = Tested and confirmed working, ❓ = Not officially tested yet
94+
95+
## API Components
96+
97+
The SDK is organized into several components:
98+
99+
- **Client**: The main entry point that provides access to all API functionality
100+
- **Authentication**: Handles authentication and token management
101+
- **Endpoints**: Service modules for each API endpoint (accounts, contracts, orders, etc.)
102+
- **Models**: Data classes for API entities (account, contract, order, etc.)
103+
- **Real-time**: WebSocket functionality for real-time updates
104+
105+
## Development
106+
107+
### Setup
108+
109+
1. Clone the repository:
110+
```bash
111+
git clone https://github.com/ChristianJStarr/projectx-sdk-python.git
112+
cd projectx-sdk-python
113+
```
114+
115+
2. Create a virtual environment:
116+
```bash
117+
python -m venv venv
118+
source venv/bin/activate # On Windows: venv\Scripts\activate
119+
```
120+
121+
3. Install dependencies:
122+
```bash
123+
pip install -e ".[dev]"
124+
```
125+
126+
4. Set up pre-commit hooks:
127+
```bash
128+
pre-commit install
129+
```
130+
131+
### Running Tests
132+
133+
Run the entire test suite:
134+
135+
```bash
136+
pytest
137+
```
138+
139+
Run with coverage:
140+
141+
```bash
142+
pytest --cov=projectx_sdk
143+
```
144+
145+
Run specific test files:
146+
147+
```bash
148+
pytest tests/test_client.py
149+
```
150+
151+
### Code Quality Tools
152+
153+
- **Black**: Code formatter
154+
```bash
155+
black projectx_sdk tests
156+
```
157+
158+
- **isort**: Import sorter
159+
```bash
160+
isort projectx_sdk tests
161+
```
162+
163+
- **Flake8**: Linter
164+
```bash
165+
flake8 projectx_sdk tests
166+
```
167+
168+
- **mypy**: Type checker
169+
```bash
170+
mypy projectx_sdk
171+
```
172+
173+
## Building and Publishing
174+
175+
Build the package:
176+
177+
```bash
178+
python -m build
179+
```
180+
181+
Check the distribution:
182+
183+
```bash
184+
twine check dist/*
185+
```
186+
187+
Upload to PyPI:
188+
189+
```bash
190+
twine upload dist/*
191+
```
192+
193+
## Contributing
194+
195+
Contributions are welcome! Please feel free to submit a Pull Request.
196+
197+
1. Fork the repository
198+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
199+
3. Run the tests to ensure they pass
200+
4. Commit your changes (`git commit -m 'Add some amazing feature'`)
201+
5. Push to the branch (`git push origin feature/amazing-feature`)
202+
6. Open a Pull Request
203+
204+
Please remember that this is an unofficial SDK and not affiliated with ProjectX.
205+
206+
## Documentation
207+
208+
For detailed information about the ProjectX API that this unofficial SDK interacts with, please visit the [ProjectX API Documentation](https://gateway.docs.projectx.com/docs/intro).
209+
210+
## License
211+
212+
This project is licensed under the MIT License - see the LICENSE file for details.

0 commit comments

Comments
 (0)