Skip to content

lie-ba/projectx-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

projectx-api

PyPI - Version PyPI - Downloads

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.

About

Python SDK for the ProjectX Gateway API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%