Python API Client for interacting with the ProjectX trading API
Project description
projectx-api
projectx-api is an async Python SDK for the ProjectX Gateway API. It allows programmatic access to accounts, orders, positions, market data, and more.
📦 Installation
pip install projectx-api
🚀 Features
- ✅ Async HTTP client powered by httpx
- ✅ Supports all endpoints described in the documentation
- ✅ Supports both API key and application-based authentication
- ✅ Automatic session revalidation (24h token auto-refresh)
- 🚧 WebSocket support (Realtime Updates) coming soon
🔧 Usage Example
import asyncio
from projectx_api import ProjectXClient, Environment, LoginKeyCredentials, OrderSide, OrderType
async def main():
client = ProjectXClient(Environment.TOPSTEP_X)
await client.login(
LoginKeyCredentials(userName="test", apiKey="test")
)
accounts = await client.search_for_account()
print("Accounts:", accounts)
accountId = accounts[0]["id"]
orders = await client.search_for_open_orders(accountId=accountId)
print("Open orders:", orders)
positions = await client.search_for_positions(accountId=accountId)
print("Positions:", positions)
contracts = await client.search_for_contracts(searchText="NQ", live=True)
print("Contracts:", contracts)
contractId = contracts[0]["id"]
result = await client.place_order(
accountId=accountId,
contractId=contractId,
type=OrderType.LIMIT,
side=OrderSide.BUY,
size=1,
limitPrice=2000,
)
print("Place Order", result)
orderId = result["orderId"]
result = await client.cancel_order(accountId=accountId, orderId=orderId)
print("Cancel Order", result)
await client.logout()
asyncio.run(main())
🌍 Supported Environments
You can see the supported environments here
📄 License
This project is licensed under the MIT License. See LICENSE for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file projectx_api-0.1.0.tar.gz.
File metadata
- Download URL: projectx_api-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92be9755c74539c77775401c5312cb2e37c86e9e951e1397632a21dd4abe0dae
|
|
| MD5 |
1aa04532d3a0d5603cb6fd662803f433
|
|
| BLAKE2b-256 |
a44e9d9ac30f6a89a20ab36a92a61e698f03b58db89f1e114c979db6b6ab4fe0
|
File details
Details for the file projectx_api-0.1.0-py3-none-any.whl.
File metadata
- Download URL: projectx_api-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ca59aa2e8d75bf0677b578b4e192d8d1b71a03eb88c659c8b475687abd01ba0
|
|
| MD5 |
dd31c5e6533ec218ce6da6c799dacfb2
|
|
| BLAKE2b-256 |
e70017509e4a91a603763b9265b3d4aced3ae87f0847e9bb2a91ced4caabbbe4
|