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.

This software is provided "as is," without warranty of any kind, express or implied. It is intended for educational and informational purposes only and does not constitute financial, investment, or trading advice. Trading and investing involve significant risk, and you may incur capital losses. Never risk money you cannot afford to lose. By downloading, installing, or using this package, you agree that the authors, publishers, and contributors are not liable for any financial losses, damages, or technical issues resulting from its use. You use this software entirely at your own risk.

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.1

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.1
File Size Uploaded Provenance Actions
qfex2-1.0.1.tar.gz 98.2 kB Without provenance Details for qfex2-1.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 186.7 kB

Release files / qfex2-1.0.1.tar.gz

Download URL qfex2-1.0.1.tar.gz
Size 98.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6d29b7be70d3863e6261fbfca7358492e81c5a17d0d0ead532d01c607fcf8a2f
BLAKE2b-256 checksum
How to use checksums
5ef33fbf6eac99688a53c4e5e7abd79a84f8f88b066c2df1bb76e81ee9129a07
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.1-py3-none-any.whl

Download URL qfex2-1.0.1-py3-none-any.whl
Size 88.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
683cf6d0ab2793dc2d862de90f47e5c8cdc944e0ffeea161746e979e856f4e09
BLAKE2b-256 checksum
How to use checksums
565ba963bbdfead863805bfbdf6f5c5f39174b7a28dcfc1dad490e9b67804e5d
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.1

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.1 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