Skip to main content

qfex2

A Python SDK for the QFEX API. The examples/bot_supervisor.py is a pure market making bot that you can run out of the box or with customization. By default, it continuously quotes both a buy (bid) and a sell (ask) price for US500 around a mid-price, aiming to capture the bid–ask spread without taking a directional bet.

Python Version License

Disclaimers

This package is written by AI and backtested under my supervision. After two months of tinkering, I'm releasing it as version 1.0.0. The examples/bot_supervisor.py contains the settings I currently use, so if you just want to passively farming QFEX points on autopilot, you can just run:

caffeinate -i .venv/bin/python examples/bot_supervisor.py

Of course, you will need to create an account at QFEX first. You can do that with my referral https://qfex.com/@re83f92f to save 10%+ on trading fees.

Installation

Install via pip:

pip install qfex2

Or from source:

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

Quick Start

Create an account at QFEX and deposit $50~$200. (You can deposit more later after you feel comfortable with the bot.)

Get your QFEX API keys. See instruction.

Store your keys in env vars by adding the following lines to the right startup file (~/.zprofile, ~/.profile, ~/.zshrc, ~/.bashrc) for your shell:

export QFEX_PUBLIC_KEY="your_public_key"
export QFEX_SECRET_KEY="your_secret_key" 

Run pure market making bots:

caffeinate -i .venv/bin/python examples/bot_supervisor.py

examples/bot_supervisor.py runs one bot at a time on a daily schedule, with pauses around news releases, the US stock-market open and weekends. All of its times are in UTC by default (TIMEZONE = "UTC"). To use your own timezone, set TIMEZONE to an IANA name such as "Europe/London" and convert the schedule, blackouts, weekend pause and week start to it. The shipped schedule, sizes and blackout dates are the author's own settings for late 2026 — review and replace them before running with real money. (caffeinate keeps a Mac awake; on Linux just run python examples/bot_supervisor.py.)

Build Your Own Bots

The examples/ folder contains several other scripts, each implementing a simple strategy. These scripts are meant to demonstrate the features of the qfex2 package, and are not necessarily good trading strategies. You can use them as starting points to build your own bots.

Run simple maker stratey to place GTC Add Liquidity Orders:

python examples/simple_maker.py \
    --is-prod \
    --symbol CRCL-USD \
    --quantity 0.1 \
    --leverage 3 \
    --log-level INFO \
    --log-file logs/maker.log

Run simple taker stratey to place MARKET orders:

python examples/simple_taker_market.py \
    --is-prod \
    --symbol CRCL-USD \
    --side BUY \
    --quantity 0.1 \
    --leverage 3 \
    --log-level INFO \
    --log-file logs/taker.log

Run simple taker stratey to place IOC LIMIT orders:

python examples/simple_taker_limit_ioc.py \
    --is-prod \
    --symbol CRCL-USD \
    --side BUY \
    --price 62.45 \
    --quantity 0.1 \
    --leverage 5 \
    --log-level INFO \
    --log-file logs/taker.log

Run simple perpetual market making strategy:

python examples/perpetual_maker.py \
    --is-prod \
    --symbol GOLD-USD \
    --order-amount 0.03 \
    --bid-spread 0.0002 \
    --ask-spread 0.0002 \
    --underlier-weight 0 \
    --order-refresh-tolerance 0.00005 \
    --stop-loss-spread 0.0008 \
    --take-profit-spread 0.0008 \
    --bbo-stop-loss-confirm-streak 5 \
    --quote-pause-spread 0.002 \
    --quote-pause-spread-bad-ticks 1 \
    --quote-resume-spread 0.0012 \
    --leverage 5 \
    --log-level DEBUG \
    --log-file logs/mm.log
python examples/perpetual_maker.py \
    --is-prod \
    --symbol CL-USD \
    --order-amount 1 \
    --bid-spread 0.0004 \
    --ask-spread 0.0004 \
    --underlier-weight 0 \
    --order-refresh-tolerance 0.0001 \
    --stop-loss-spread 0.0015 \
    --take-profit-spread 0.0015 \
    --bbo-stop-loss-confirm-streak 5 \
    --quote-pause-spread 0.002 \
    --quote-pause-spread-bad-ticks 1 \
    --quote-resume-spread 0.0012 \
    --leverage 5 \
    --log-level DEBUG \
    --log-file logs/mm.log
python examples/perpetual_maker.py \
    --is-prod \
    --symbol US500-USD \
    --order-amount 0.02 \
    --bid-spread 0.00025 \
    --ask-spread 0.00025 \
    --underlier-weight 0 \
    --order-refresh-tolerance 0.00005 \
    --stop-loss-spread 0.0001 \
    --take-profit-spread 0.0001 \
    --bbo-stop-loss-confirm-streak 5 \
    --quote-pause-spread 0.002 \
    --quote-pause-spread-bad-ticks 1 \
    --quote-resume-spread 0.0012 \
    --leverage 5 \
    --log-level DEBUG \
    --log-file logs/mm.log

Hint: change INFO to DEBUG, WARNING, ERROR, CRITICAL for details.

Requirements

  • Python 3.12+
  • websockets
  • requests

License

MIT

Metadata

Release files for qfex2 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qfex2 1.0.0
File Size Uploaded Provenance Actions
qfex2-1.0.0.tar.gz 97.6 kB Without provenance Details for qfex2-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qfex2 1.0.0
File Interpreter ABI Platform Actions
qfex2-1.0.0-py3-none-any.whl Python 3 none any Details for qfex2-1.0.0-py3-none-any.whl

Total release size: 185.9 kB

Release files / qfex2-1.0.0.tar.gz

Download URL qfex2-1.0.0.tar.gz
Size 97.6 kB
Tags Source
SHA-256 checksum
How to use checksums
eee3e61e695d3abf43b4f128035404db511e55516777bb9cf3622b671ce94c76
BLAKE2b-256 checksum
How to use checksums
fc5f38ad956643f9bee883fa1d6c051fa2a12bc3b2aa80f5ab3f1f35b6e783c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release files / qfex2-1.0.0-py3-none-any.whl

Download URL qfex2-1.0.0-py3-none-any.whl
Size 88.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a367455104011447ee8d24245794e396f5f24405fa5dd3256ebbe3e85d0af3ff
BLAKE2b-256 checksum
How to use checksums
eb62cb55f1a4bc126ce289041551aa230d39511850676382e96a406f99f402dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Security for qfex2 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page