# VeighNa框架的CTP底层接口
<p align="center">
<img src ="https://vnpy.oss-cn-shanghai.aliyuncs.com/vnpy-logo.png"/>
</p>
<p align="center">
<img src ="https://img.shields.io/badge/version-6.7.2.1-blueviolet.svg"/>
<img src ="https://img.shields.io/badge/platform-windows|linux|macos-yellow.svg"/>
<img src ="https://img.shields.io/badge/python-3.10|3.11|3.12-blue.svg" />
<img src ="https://img.shields.io/github/license/vnpy/vnpy.svg?color=orange"/>
</p>
## 说明
基于CTP期货版的6.7.2接口封装开发,接口中自带的是【穿透式实盘环境】的dll文件。
## 安装
安装环境推荐基于3.9.0版本以上的【[**VeighNa Studio**](https://www.vnpy.com)】。
直接使用pip命令:
```
pip install vnpy_ctp
```
或者下载源代码后,解压后在cmd中运行:
```
pip install .
```
使用源代码安装时需要进行C++编译,因此在执行上述命令之前请确保已经安装了【Visual Studio(Windows)】、【GCC(Linux)】、【XCode(Mac)】编译器。
## 使用
以脚本方式启动(script/run.py):
```
from vnpy.event import EventEngine
from vnpy.trader.engine import MainEngine
from vnpy.trader.ui import MainWindow, create_qapp
from vnpy_ctp import CtpGateway
def main():
"""主入口函数"""
qapp = create_qapp()
event_engine = EventEngine()
main_engine = MainEngine(event_engine)
main_engine.add_gateway(CtpGateway)
main_window = MainWindow(main_engine, event_engine)
main_window.showMaximized()
qapp.exec()
if __name__ == "__main__":
main()
```
## Mac系统支持
由于6.7.2版本CTP的Mac系统API项目结构发生了较大变化,改为了使用framework目录的结构,因此无法再直接从PyPI下载预编译好的wheel二进制包进行安装。
用户需要克隆(或下载)本仓库的源代码到本地后自行编译安装,具体命令如下:
```
git clone https://github.com/vnpy/vnpy_ctp.git
cd vnpy_ctp
pip3 install -e .
```
相关注意事项如下:
源码编译需要依赖XCode开发工具中的C++编译器,请务必先安装好。
编译过程中,会指定克隆到本地的源码目录中的framework文件夹路径,为API运行时动态库的加载路径。因此后续运行时,*该源码目录不能删除,也不能移动位置,否则会导致动态库加载找不到的报错*。
由于当前新版本Mac系统的安全机制,编译完成后需要在【访达】中找到下述两个动态库文件,分别手动打开一次后添加到操作系统信任名单,才能在启动Python时成功加载:
* vnpy_ctp/api/libs/thostmduserapi_se.framework/Versions/A/thostmduserapi_se
* vnpy_ctp/api/libs/thosttraderapi_se.framework/Versions/A/thosttraderapi_se
以上两个文件由于本身是二进制格式,并不能正常打开,但不影响添加到系统信任名单。
Raw data
{
"_id": null,
"home_page": "https://www.vnpy.com",
"name": "vnpy-ctp",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "quant, quantitative, investment, trading, algotrading, ctp",
"author": "Xiaoyou Chen",
"author_email": "xiaoyou.chen@mail.vnpy.com",
"download_url": "https://files.pythonhosted.org/packages/df/3a/4d43efe7816a3d5fb945db89025a954ff0efc40bb276189c023c39bda91d/vnpy_ctp-6.7.2.1.tar.gz",
"platform": null,
"description": "# VeighNa\u6846\u67b6\u7684CTP\u5e95\u5c42\u63a5\u53e3\r\n\r\n<p align=\"center\">\r\n <img src =\"https://vnpy.oss-cn-shanghai.aliyuncs.com/vnpy-logo.png\"/>\r\n</p>\r\n\r\n<p align=\"center\">\r\n <img src =\"https://img.shields.io/badge/version-6.7.2.1-blueviolet.svg\"/>\r\n <img src =\"https://img.shields.io/badge/platform-windows|linux|macos-yellow.svg\"/>\r\n <img src =\"https://img.shields.io/badge/python-3.10|3.11|3.12-blue.svg\" />\r\n <img src =\"https://img.shields.io/github/license/vnpy/vnpy.svg?color=orange\"/>\r\n</p>\r\n\r\n## \u8bf4\u660e\r\n\r\n\u57fa\u4e8eCTP\u671f\u8d27\u7248\u76846.7.2\u63a5\u53e3\u5c01\u88c5\u5f00\u53d1\uff0c\u63a5\u53e3\u4e2d\u81ea\u5e26\u7684\u662f\u3010\u7a7f\u900f\u5f0f\u5b9e\u76d8\u73af\u5883\u3011\u7684dll\u6587\u4ef6\u3002\r\n\r\n## \u5b89\u88c5\r\n\r\n\u5b89\u88c5\u73af\u5883\u63a8\u8350\u57fa\u4e8e3.9.0\u7248\u672c\u4ee5\u4e0a\u7684\u3010[**VeighNa Studio**](https://www.vnpy.com)\u3011\u3002\r\n\r\n\u76f4\u63a5\u4f7f\u7528pip\u547d\u4ee4\uff1a\r\n\r\n```\r\npip install vnpy_ctp\r\n```\r\n\r\n\r\n\u6216\u8005\u4e0b\u8f7d\u6e90\u4ee3\u7801\u540e\uff0c\u89e3\u538b\u540e\u5728cmd\u4e2d\u8fd0\u884c\uff1a\r\n\r\n```\r\npip install .\r\n```\r\n\r\n\u4f7f\u7528\u6e90\u4ee3\u7801\u5b89\u88c5\u65f6\u9700\u8981\u8fdb\u884cC++\u7f16\u8bd1\uff0c\u56e0\u6b64\u5728\u6267\u884c\u4e0a\u8ff0\u547d\u4ee4\u4e4b\u524d\u8bf7\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86\u3010Visual Studio\uff08Windows\uff09\u3011\u3001\u3010GCC\uff08Linux\uff09\u3011\u3001\u3010XCode\uff08Mac\uff09\u3011\u7f16\u8bd1\u5668\u3002\r\n\r\n## \u4f7f\u7528\r\n\r\n\u4ee5\u811a\u672c\u65b9\u5f0f\u542f\u52a8\uff08script/run.py\uff09\uff1a\r\n\r\n```\r\nfrom vnpy.event import EventEngine\r\nfrom vnpy.trader.engine import MainEngine\r\nfrom vnpy.trader.ui import MainWindow, create_qapp\r\n\r\nfrom vnpy_ctp import CtpGateway\r\n\r\n\r\ndef main():\r\n \"\"\"\u4e3b\u5165\u53e3\u51fd\u6570\"\"\"\r\n qapp = create_qapp()\r\n\r\n event_engine = EventEngine()\r\n main_engine = MainEngine(event_engine)\r\n main_engine.add_gateway(CtpGateway)\r\n \r\n main_window = MainWindow(main_engine, event_engine)\r\n main_window.showMaximized()\r\n\r\n qapp.exec()\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n```\r\n\r\n## Mac\u7cfb\u7edf\u652f\u6301\r\n\r\n\u7531\u4e8e6.7.2\u7248\u672cCTP\u7684Mac\u7cfb\u7edfAPI\u9879\u76ee\u7ed3\u6784\u53d1\u751f\u4e86\u8f83\u5927\u53d8\u5316\uff0c\u6539\u4e3a\u4e86\u4f7f\u7528framework\u76ee\u5f55\u7684\u7ed3\u6784\uff0c\u56e0\u6b64\u65e0\u6cd5\u518d\u76f4\u63a5\u4ecePyPI\u4e0b\u8f7d\u9884\u7f16\u8bd1\u597d\u7684wheel\u4e8c\u8fdb\u5236\u5305\u8fdb\u884c\u5b89\u88c5\u3002\r\n\r\n\u7528\u6237\u9700\u8981\u514b\u9686\uff08\u6216\u4e0b\u8f7d\uff09\u672c\u4ed3\u5e93\u7684\u6e90\u4ee3\u7801\u5230\u672c\u5730\u540e\u81ea\u884c\u7f16\u8bd1\u5b89\u88c5\uff0c\u5177\u4f53\u547d\u4ee4\u5982\u4e0b\uff1a\r\n\r\n```\r\ngit clone https://github.com/vnpy/vnpy_ctp.git\r\n\r\ncd vnpy_ctp\r\n\r\npip3 install -e .\r\n```\r\n\r\n\u76f8\u5173\u6ce8\u610f\u4e8b\u9879\u5982\u4e0b\uff1a\r\n\r\n\u6e90\u7801\u7f16\u8bd1\u9700\u8981\u4f9d\u8d56XCode\u5f00\u53d1\u5de5\u5177\u4e2d\u7684C++\u7f16\u8bd1\u5668\uff0c\u8bf7\u52a1\u5fc5\u5148\u5b89\u88c5\u597d\u3002\r\n\r\n\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u6307\u5b9a\u514b\u9686\u5230\u672c\u5730\u7684\u6e90\u7801\u76ee\u5f55\u4e2d\u7684framework\u6587\u4ef6\u5939\u8def\u5f84\uff0c\u4e3aAPI\u8fd0\u884c\u65f6\u52a8\u6001\u5e93\u7684\u52a0\u8f7d\u8def\u5f84\u3002\u56e0\u6b64\u540e\u7eed\u8fd0\u884c\u65f6\uff0c*\u8be5\u6e90\u7801\u76ee\u5f55\u4e0d\u80fd\u5220\u9664\uff0c\u4e5f\u4e0d\u80fd\u79fb\u52a8\u4f4d\u7f6e\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4\u52a8\u6001\u5e93\u52a0\u8f7d\u627e\u4e0d\u5230\u7684\u62a5\u9519*\u3002\r\n\r\n\u7531\u4e8e\u5f53\u524d\u65b0\u7248\u672cMac\u7cfb\u7edf\u7684\u5b89\u5168\u673a\u5236\uff0c\u7f16\u8bd1\u5b8c\u6210\u540e\u9700\u8981\u5728\u3010\u8bbf\u8fbe\u3011\u4e2d\u627e\u5230\u4e0b\u8ff0\u4e24\u4e2a\u52a8\u6001\u5e93\u6587\u4ef6\uff0c\u5206\u522b\u624b\u52a8\u6253\u5f00\u4e00\u6b21\u540e\u6dfb\u52a0\u5230\u64cd\u4f5c\u7cfb\u7edf\u4fe1\u4efb\u540d\u5355\uff0c\u624d\u80fd\u5728\u542f\u52a8Python\u65f6\u6210\u529f\u52a0\u8f7d\uff1a\r\n\r\n* vnpy_ctp/api/libs/thostmduserapi_se.framework/Versions/A/thostmduserapi_se\r\n* vnpy_ctp/api/libs/thosttraderapi_se.framework/Versions/A/thosttraderapi_se\r\n\r\n\u4ee5\u4e0a\u4e24\u4e2a\u6587\u4ef6\u7531\u4e8e\u672c\u8eab\u662f\u4e8c\u8fdb\u5236\u683c\u5f0f\uff0c\u5e76\u4e0d\u80fd\u6b63\u5e38\u6253\u5f00\uff0c\u4f46\u4e0d\u5f71\u54cd\u6dfb\u52a0\u5230\u7cfb\u7edf\u4fe1\u4efb\u540d\u5355\u3002\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "CTP gateway for vn.py quant trading framework.",
"version": "6.7.2.1",
"project_urls": {
"Homepage": "https://www.vnpy.com"
},
"split_keywords": [
"quant",
" quantitative",
" investment",
" trading",
" algotrading",
" ctp"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ade83495eaa8dce36f4f226a5385ab5ccfb8d6ab0f5f9051c1d713cdfc770d35",
"md5": "f0cf1a343c14bdbef04bde16d33c7101",
"sha256": "876d4f5e6180b7c9cc89d8618916567957a35c98da5b170404125dd384c3fe41"
},
"downloads": -1,
"filename": "vnpy_ctp-6.7.2.1-cp310-cp310-win_amd64.whl",
"has_sig": false,
"md5_digest": "f0cf1a343c14bdbef04bde16d33c7101",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": ">=3.10",
"size": 13802055,
"upload_time": "2024-12-25T14:47:40",
"upload_time_iso_8601": "2024-12-25T14:47:40.956384Z",
"url": "https://files.pythonhosted.org/packages/ad/e8/3495eaa8dce36f4f226a5385ab5ccfb8d6ab0f5f9051c1d713cdfc770d35/vnpy_ctp-6.7.2.1-cp310-cp310-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "df3a4d43efe7816a3d5fb945db89025a954ff0efc40bb276189c023c39bda91d",
"md5": "873ca0b371908e9c0218d2ccbaea0740",
"sha256": "833a3c575f998769c00d55b176938ecea60889dcdc702a1e07cacd52144b43b3"
},
"downloads": -1,
"filename": "vnpy_ctp-6.7.2.1.tar.gz",
"has_sig": false,
"md5_digest": "873ca0b371908e9c0218d2ccbaea0740",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 12858210,
"upload_time": "2024-12-25T14:49:27",
"upload_time_iso_8601": "2024-12-25T14:49:27.161869Z",
"url": "https://files.pythonhosted.org/packages/df/3a/4d43efe7816a3d5fb945db89025a954ff0efc40bb276189c023c39bda91d/vnpy_ctp-6.7.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-25 14:49:27",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "vnpy-ctp"
}