Ctpwrapper
上海期货交易所CTP接口 Shanghai Future CTP Interface CTP Python API Wrapper
Install / Use
/learn @nooperpudd/CtpwrapperREADME
CTP期货 API Python Wrapper
Version: v6.7.9
Platform: Linux 64bit, Windows 64bit
Python Requirement: x86-64
Especially Support PyPy3-3.6 Linux 64bit
Inspire By lovelylain
Install
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 [捐助]
<img src="images/alipay.png" width="250" height="250"><img src="images/wechat.jpg" width="250" height="250">
⚠️⚠️ 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.
Demo
sample code samples
issues
https://github.com/nooperpudd/ctpwrapper/issues/62 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/trader_main.py", line 149, in OnRspQrySettlementInfo
print(pSettlementInfo.Content)
File "/root/python/futures/.venv/lib/python3.9/site-packages/ctpwrapper/base.py", 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("OnRspQryTradingAccount")
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:
error_message+=pRspInfo.ErrorMsg
else:
error_message+=pRspInfo.ErrorMsg
if isinstance(error_message,bytes):
error_message.decode("gbk")
Documentation
CTP documentation can be found in the docs
Contact
If you have any question about the ctpwrapper API, contact 365504029@qq.com
Related Skills
node-connect
350.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
