Skip to main content

CTP client v6.3.19

Project description

CTP期货 API Python Wrapper

Build Status Build status Codacy Badge pypi status pyversion implementation Downloads

CTP Website

Version: v6.6.1 P1(v6.6.1 20210407)

Platform: Linux 64bit, Windows 64bit

Python Requirement: x86-64

Especially Support PyPy3-3.6 Linux 64bit

Inspire By lovelylain


Before you install ctpwrapper package, you need to make sure you have already install cython package.

>>>pip install cython --upgrade
>>>pip install ctpwrapper --upgrade

Donate [捐助]

⚠️⚠️ notice ⚠️⚠️

sometimes quote the market futures data, but there is no trading data from the API stream, better just add time.sleep(2) func call after Init() method invoked, this could help to solve no data response issue.


sample code samples

issues this is a temporary solution for the UnicodeDecodeError issue.

 Traceback (most recent call last):
   File "ctpwrapper/TraderApi.pyx", line 1402, in ctpwrapper.TraderApi.TraderSpi_OnRspQrySettlementInfo
   File "/root/python/futures/", line 149, in OnRspQrySettlementInfo
   File "/root/python/futures/.venv/lib/python3.9/site-packages/ctpwrapper/", line 28, in __getattribute__
     return value.decode("gbk")
 UnicodeDecodeError: 'gbk' codec can't decode byte 0xd2 in position 499: incomplete multibyte sequence
error_message = ""

def OnRspQryTradingAccount(self, pTradingAccount, pRspInfo, nRequestID, bIsLast):
    print("nRequestID:", nRequestID)
    print("bIsLast:", bIsLast)
    print("pRspInfo:", pRspInfo)
    print("pTradingAccount:", pTradingAccount)
    # need to check is last message from the server.
    global error_message
    if not bIsLast:
       if isinstance(error_message,bytes):


CTP documentation can be found in the docs


If you have any question about the ctpwrapper API, contact

Project details

Download files

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

Files for ctpwrapper, version
Filename, size File type Python version Upload date Hashes
Filename, size ctpwrapper- (8.2 MB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page