projectx-api is an async Python SDK for the ProjectX Gateway API. It allows programmatic access to accounts, orders, positions, market data, and more.
pip install projectx-api
- ✅ 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
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())You can see the supported environments here
This project is licensed under the MIT License. See LICENSE for details.