Skip to main content

A Python SDK for the QFEX Taker API

Project description

qfex-py

A modern, high-performance Python SDK for the QFEX Taker API.

Python Version License

Features

  • AsyncIO: Fully asynchronous design using asyncio and websockets for low-latency trading.
  • Type Safe: Comprehensive type hints and Enums (Side, OrderType, etc.) for robust code.
  • Easy Configuration: Simple configuration object for switching between Prod/UAT and managing keys.
  • Strategy Pattern: Clean TakerStrategy base class to separate your trading logic from connection management.
  • Resilience: Automatic reconnection, exponential backoff, and heartbeat management.
  • Modern Python: Built for Python 3.10+ with Context Manager support.

Installation

Install via pip (once published) or directly from source:

pip install qfex

Or from source:

git clone https://github.com/qfex/qfex-py.git
cd qfex-py
pip install .

Quick Start

Here is a minimal example of a strategy that logs the Best Bid/Offer (BBO) and Order Fills.

import asyncio
import logging
from qfex import QFEXTakerClient, QFEXConfig, TakerStrategy, BBO, Side

class MyStrategy(TakerStrategy):
    async def on_bbo(self, bbo: BBO) -> None:
        print(f"BBO Update: {bbo.symbol} {bbo.bid_qty} @ {bbo.bid_px}")

    async def on_fill(self, fill: dict) -> None:
        print(f"Fill: {fill}")

async def main():
    # 1. Configure
    cfg = QFEXConfig(
        is_prod=False,  # Set to True for Production
        symbol_list=["AAPL-USD"],
        public_key="YOUR_PUBLIC_KEY",
        secret_key="YOUR_SECRET_KEY",
    )

    # 2. Initialize Strategy & Client
    # Note: Strategy is initialized with a placeholder client initially
    client = QFEXTakerClient(cfg, strategy=None) # type: ignore
    strategy = MyStrategy(client)
    client.strategy = strategy

    # 3. Run
    print("Starting client...")
    await client.run()

if __name__ == "__main__":
    asyncio.run(main())

Advanced Usage

Sending Orders

You can send orders easily from within your strategy callbacks or any other async function:

await client.send_ioc_limit(
    symbol="AAPL-USD",
    side=Side.BUY,
    quantity=Decimal("0.1"),
    price=Decimal("50000.00")
)

Async Context Manager

For integration with other async applications (like FastAPI, or multi-exchange bots), use the client as a context manager. This runs the websocket loops in the background without blocking your main thread.

async def main():
    cfg = ... 
    client = QFEXTakerClient(cfg, strategy=...)
    
    async with client:
        # Client is now connected and processing events
        print("Client is running in background")
        
        # Do other work...
        await asyncio.sleep(60)
        
    # Client automatically disconnects here

Development

Requirements

  • Python 3.10+
  • websockets

Running Tests (Type Checking)

mypy src/qfex

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qfex-0.1.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qfex-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file qfex-0.1.0.tar.gz.

File metadata

  • Download URL: qfex-0.1.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.14

File hashes

Hashes for qfex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9be563266c041b4afa7a7a2c6d19a43eefdc55f21468e30311ee570b6b34b4c5
MD5 55a1c7e07bce7bbbe5a6f7d6f90fa3b9
BLAKE2b-256 21b697648e8bcfacc8010b33bba598724f94c01cf17a5913d0d166378714b8d9

See more details on using hashes here.

File details

Details for the file qfex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: qfex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.14

File hashes

Hashes for qfex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e50bfe96918e605a1ae159ef68b6f50a6be8cb02998b42f18486496f0d6af4c
MD5 8a26d72825d6833b20171c9e78ec3bdb
BLAKE2b-256 0ff6376151eace712b691c4b700572477e36b1fd9fd77ed9eb9c0517f27a1b8b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page