# CTP期货 API Python Wrapper
[![build action](https://github.com/nooperpudd/ctpwrapper/actions/workflows/build.yaml/badge.svg?branch=master)](https://github.com/nooperpudd/ctpwrapper/actions/workflows/build.yaml)
[![Build status](https://ci.appveyor.com/api/projects/status/gvvtcqsjo9nsw0ct/branch/master?svg=true)](https://ci.appveyor.com/project/nooperpudd/ctpwrapper)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/9ed5d0e55ed84dfeba30a7630ab5c160)](https://www.codacy.com/app/nooperpudd/ctpwrapper?utm_source=github.com&utm_medium=referral&utm_content=nooperpudd/ctpwrapper&utm_campaign=Badge_Grade)
[![pypi](https://img.shields.io/pypi/v/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper)
[![status](https://img.shields.io/pypi/status/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper)
[![pyversion](https://img.shields.io/pypi/pyversions/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper)
[![implementation](https://img.shields.io/pypi/implementation/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper)
[![Downloads](https://pepy.tech/badge/ctpwrapper)](https://pepy.tech/project/ctpwrapper)
[CTP Website](http://www.sfit.com.cn/5_2_DocumentDown_1.htm)
Version: v6.7.0
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](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
```
```python
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](doc/ctp/)
# Contact
If you have any question about the ctpwrapper API, contact 365504029@qq.com
Raw data
{
"_id": null,
"home_page": "https://github.com/nooperpudd/ctpwrapper",
"name": "ctpwrapper",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "CTP,Future,SHFE,Shanghai Future Exchange",
"author": "Winton Wang",
"author_email": "365504029@qq.com",
"download_url": "https://files.pythonhosted.org/packages/6c/cf/d3005c67ebbc2d076c91366e90c0519097f9ca09b6a94e9c416e2b00760b/ctpwrapper-6.7.0.tar.gz",
"platform": "win32",
"description": "# CTP\u671f\u8d27 API Python Wrapper \n\n[![build action](https://github.com/nooperpudd/ctpwrapper/actions/workflows/build.yaml/badge.svg?branch=master)](https://github.com/nooperpudd/ctpwrapper/actions/workflows/build.yaml)\n[![Build status](https://ci.appveyor.com/api/projects/status/gvvtcqsjo9nsw0ct/branch/master?svg=true)](https://ci.appveyor.com/project/nooperpudd/ctpwrapper)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/9ed5d0e55ed84dfeba30a7630ab5c160)](https://www.codacy.com/app/nooperpudd/ctpwrapper?utm_source=github.com&utm_medium=referral&utm_content=nooperpudd/ctpwrapper&utm_campaign=Badge_Grade)\n[![pypi](https://img.shields.io/pypi/v/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper)\n[![status](https://img.shields.io/pypi/status/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper)\n[![pyversion](https://img.shields.io/pypi/pyversions/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper)\n[![implementation](https://img.shields.io/pypi/implementation/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper)\n[![Downloads](https://pepy.tech/badge/ctpwrapper)](https://pepy.tech/project/ctpwrapper)\n\n[CTP Website](http://www.sfit.com.cn/5_2_DocumentDown_1.htm)\n\nVersion: v6.7.0\n\nPlatform: Linux 64bit, Windows 64bit\n\nPython Requirement: x86-64\n\n**Especially Support PyPy3-3.6 Linux 64bit**\n\nInspire By lovelylain \n\n# Install\n\nBefore you install ctpwrapper package, you need to make sure you have \nalready install cython package.\n\n >>>pip install cython --upgrade\n >>>pip install ctpwrapper --upgrade\n\n\n# Donate [\u6350\u52a9]\n\n <img src=\"images/alipay.png\" width=\"250\" height=\"250\"><img src=\"images/wechat.jpg\" width=\"250\" height=\"250\">\n\n## \u26a0\ufe0f\u26a0\ufe0f notice \u26a0\ufe0f\u26a0\ufe0f\n sometimes quote the market futures data, but there is no trading data from the API stream,\n better just add `time.sleep(2)` func call after `Init()` method invoked, this could help to solve no data response issue.\n \n## Demo\nsample code [samples](samples/)\n\n## issues\n https://github.com/nooperpudd/ctpwrapper/issues/62\n this is a temporary solution for the UnicodeDecodeError issue.\n ```\n Traceback (most recent call last):\n File \"ctpwrapper/TraderApi.pyx\", line 1402, in ctpwrapper.TraderApi.TraderSpi_OnRspQrySettlementInfo\n File \"/root/python/futures/trader_main.py\", line 149, in OnRspQrySettlementInfo\n print(pSettlementInfo.Content)\n File \"/root/python/futures/.venv/lib/python3.9/site-packages/ctpwrapper/base.py\", line 28, in __getattribute__\n return value.decode(\"gbk\")\n UnicodeDecodeError: 'gbk' codec can't decode byte 0xd2 in position 499: incomplete multibyte sequence\n ```\n ```python\n\nerror_message = \"\"\n\ndef OnRspQryTradingAccount(self, pTradingAccount, pRspInfo, nRequestID, bIsLast):\n print(\"OnRspQryTradingAccount\")\n print(\"nRequestID:\", nRequestID)\n print(\"bIsLast:\", bIsLast)\n print(\"pRspInfo:\", pRspInfo)\n print(\"pTradingAccount:\", pTradingAccount)\n # need to check is last message from the server.\n global error_message\n if not bIsLast:\n error_message+=pRspInfo.ErrorMsg\n else:\n error_message+=pRspInfo.ErrorMsg\n if isinstance(error_message,bytes):\n error_message.decode(\"gbk\")\n ```\n\n# Documentation\n CTP documentation can be found in the [docs](doc/ctp/)\n\n# Contact\n\nIf you have any question about the ctpwrapper API, contact 365504029@qq.com\n\n\n\n \n",
"bugtrack_url": null,
"license": "LGPLv3",
"summary": "CTP client v6.6.5",
"version": "6.7.0",
"project_urls": {
"Homepage": "https://github.com/nooperpudd/ctpwrapper"
},
"split_keywords": [
"ctp",
"future",
"shfe",
"shanghai future exchange"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6ccfd3005c67ebbc2d076c91366e90c0519097f9ca09b6a94e9c416e2b00760b",
"md5": "3e18bc2b8de33f6164ed7958b6fcc4dd",
"sha256": "360e25f6f1a0241ac90cf53a36a1c8b38e3d8da5ea103f64c68403576927e5ec"
},
"downloads": -1,
"filename": "ctpwrapper-6.7.0.tar.gz",
"has_sig": false,
"md5_digest": "3e18bc2b8de33f6164ed7958b6fcc4dd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 8173469,
"upload_time": "2023-07-05T03:51:01",
"upload_time_iso_8601": "2023-07-05T03:51:01.330836Z",
"url": "https://files.pythonhosted.org/packages/6c/cf/d3005c67ebbc2d076c91366e90c0519097f9ca09b6a94e9c416e2b00760b/ctpwrapper-6.7.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-05 03:51:01",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nooperpudd",
"github_project": "ctpwrapper",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"appveyor": true,
"requirements": [],
"lcname": "ctpwrapper"
}