Skip to content

stonepy

A typed Python client for the StoneX / City Index CIAPI v2 trading API, with both synchronous and asynchronous clients generated from the upstream API catalog.

PyPI version Python versions CI

Why stonepy

  • Fully typed. Every request and response is a Pydantic model, so your editor autocompletes fields and mypy checks your calls.
  • Sync and async. Identical APIs on StoneXClient and AsyncStoneXClient.
  • Complete coverage. All 128 documented CIAPI endpoints are bound, using the v2 variant of every endpoint that has one.
  • Batteries included. Automatic session refresh, retry handling, rate-limit handling, and a clear exception hierarchy.

Install

pip install stonepy

Requires Python >= 3.11.

At a glance

from stonepy import ClientConfig, StoneXClient
from stonepy.models import ApiLogOnRequestDTO

config = ClientConfig(base_url="https://ciapi.cityindex.com/TradingAPI")

with StoneXClient(config) as client:
    session = client.session.log_on(
        ApiLogOnRequestDTO(
            UserName="username",
            Password="password",
            AppKey="app-key",
            AppVersion="stonepy",
            AppComments="",
        )
    )
    print(session.status_code)
from stonepy import AsyncStoneXClient, ClientConfig
from stonepy.models import ApiLogOnRequestDTO

config = ClientConfig(base_url="https://ciapi.cityindex.com/TradingAPI")

async with AsyncStoneXClient(config) as client:
    session = await client.session.log_on(
        ApiLogOnRequestDTO(
            UserName="username",
            Password="password",
            AppKey="app-key",
            AppVersion="stonepy",
            AppComments="",
        )
    )
    print(session.status_code)

Continue with the Quickstart, or jump to the API reference.

Disclaimer

stonepy is unofficial and is not affiliated with, endorsed by, or supported by StoneX, City Index, or GAIN Capital. Trading carries financial risk; validate all behaviour against the official API documentation before using it with a live account.