# 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.11.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|3.13-blue.svg" />
<img src ="https://img.shields.io/github/license/vnpy/vnpy.svg?color=orange"/>
</p>
## 说明
基于CTP期货版的6.7.11接口封装开发,接口中自带的是【穿透式实盘、评测环境合并】的dll文件。
## 安装
安装环境推荐基于4.0.0版本以上的【[**VeighNa Studio**](https://www.vnpy.com)】。
直接使用pip命令:
```
pip install vnpy_ctp
```
或者下载源代码后,解压后在cmd中运行:
```
pip install .
```
使用源代码安装时需要进行C++编译,因此在执行上述命令之前请确保已经安装了【Visual Studio(Windows)】、【GCC(Linux)】、【XCode(Mac)】编译器。
如果需要以**开发模式**安装到当前Python环境,可以使用下述命令:
```
pip install -e . --no-build-isolation --config-settings=build-dir=.\vnpy_ctp\api
```
## 使用
以脚本方式启动(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系统支持
由于新版本CTP的Mac系统API项目结构发生了较大变化,改为了使用framework目录的结构,因此无法再直接从PyPI下载预编译好的wheel二进制包进行安装。
用户需要克隆(或下载)本仓库的源代码到本地后自行编译安装,具体命令如下:
```
git clone https://github.com/vnpy/vnpy_ctp.git
cd vnpy_ctp
pip3 install .
```
相关注意事项如下:
源码编译需要依赖XCode开发工具中的C++编译器,请务必先安装好。
Raw data
{
"_id": null,
"home_page": null,
"name": "vnpy_ctp",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "quant, quantitative, investment, trading, algotrading, ctp",
"author": null,
"author_email": "Xiaoyou Chen <xiaoyou.chen@mail.vnpy.com>",
"download_url": "https://files.pythonhosted.org/packages/ee/9c/a770676af2a5724943260ed457f71295b3030d4c123056730d3357ad4911/vnpy_ctp-6.7.11.1.tar.gz",
"platform": null,
"description": "# VeighNa\u6846\u67b6\u7684CTP\u5e95\u5c42\u63a5\u53e3\n\n<p align=\"center\">\n <img src =\"https://vnpy.oss-cn-shanghai.aliyuncs.com/vnpy-logo.png\"/>\n</p>\n\n<p align=\"center\">\n <img src =\"https://img.shields.io/badge/version-6.7.11.1-blueviolet.svg\"/>\n <img src =\"https://img.shields.io/badge/platform-windows|linux|macos-yellow.svg\"/>\n <img src =\"https://img.shields.io/badge/python-3.10|3.11|3.12|3.13-blue.svg\" />\n <img src =\"https://img.shields.io/github/license/vnpy/vnpy.svg?color=orange\"/>\n</p>\n\n## \u8bf4\u660e\n\n\u57fa\u4e8eCTP\u671f\u8d27\u7248\u76846.7.11\u63a5\u53e3\u5c01\u88c5\u5f00\u53d1\uff0c\u63a5\u53e3\u4e2d\u81ea\u5e26\u7684\u662f\u3010\u7a7f\u900f\u5f0f\u5b9e\u76d8\u3001\u8bc4\u6d4b\u73af\u5883\u5408\u5e76\u3011\u7684dll\u6587\u4ef6\u3002\n\n## \u5b89\u88c5\n\n\u5b89\u88c5\u73af\u5883\u63a8\u8350\u57fa\u4e8e4.0.0\u7248\u672c\u4ee5\u4e0a\u7684\u3010[**VeighNa Studio**](https://www.vnpy.com)\u3011\u3002\n\n\u76f4\u63a5\u4f7f\u7528pip\u547d\u4ee4\uff1a\n\n```\npip install vnpy_ctp\n```\n\n\u6216\u8005\u4e0b\u8f7d\u6e90\u4ee3\u7801\u540e\uff0c\u89e3\u538b\u540e\u5728cmd\u4e2d\u8fd0\u884c\uff1a\n\n```\npip install .\n```\n\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\n\n\u5982\u679c\u9700\u8981\u4ee5**\u5f00\u53d1\u6a21\u5f0f**\u5b89\u88c5\u5230\u5f53\u524dPython\u73af\u5883\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u8ff0\u547d\u4ee4\uff1a\n\n```\npip install -e . --no-build-isolation --config-settings=build-dir=.\\vnpy_ctp\\api\n```\n\n## \u4f7f\u7528\n\n\u4ee5\u811a\u672c\u65b9\u5f0f\u542f\u52a8\uff08script/run.py\uff09\uff1a\n\n```\nfrom vnpy.event import EventEngine\nfrom vnpy.trader.engine import MainEngine\nfrom vnpy.trader.ui import MainWindow, create_qapp\n\nfrom vnpy_ctp import CtpGateway\n\n\ndef main():\n \"\"\"\u4e3b\u5165\u53e3\u51fd\u6570\"\"\"\n qapp = create_qapp()\n\n event_engine = EventEngine()\n main_engine = MainEngine(event_engine)\n main_engine.add_gateway(CtpGateway)\n \n main_window = MainWindow(main_engine, event_engine)\n main_window.showMaximized()\n\n qapp.exec()\n\n\nif __name__ == \"__main__\":\n main()\n```\n\n## Mac\u7cfb\u7edf\u652f\u6301\n\n\u7531\u4e8e\u65b0\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\n\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\n\n```\ngit clone https://github.com/vnpy/vnpy_ctp.git\n\ncd vnpy_ctp\n\npip3 install .\n```\n\n\u76f8\u5173\u6ce8\u610f\u4e8b\u9879\u5982\u4e0b\uff1a\n\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",
"bugtrack_url": null,
"license": "MIT",
"summary": "CTP gateway for vn.py quant trading framework.",
"version": "6.7.11.1",
"project_urls": {
"Changes": "https://github.com/vnpy/vnpy_ctp/blob/master/CHANGELOG.md",
"Documentation": "https://www.vnpy.com/docs",
"Forum": "https://www.vnpy.com/forum",
"Homepage": "https://www.vnpy.com",
"Source": "https://github.com/vnpy/vnpy_ctp/"
},
"split_keywords": [
"quant",
" quantitative",
" investment",
" trading",
" algotrading",
" ctp"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "12a854a12dbe97e7ce4081fccf5b7ce52d4b974e940c9a34b430c35c023d4440",
"md5": "475e2ad79c2b9b2cf41b19d4c09f9c83",
"sha256": "a5e6f885eba35021ed8bd5560d410aaeb2635505f0b203375c5055025d055a9f"
},
"downloads": -1,
"filename": "vnpy_ctp-6.7.11.1-cp313-cp313-win_amd64.whl",
"has_sig": false,
"md5_digest": "475e2ad79c2b9b2cf41b19d4c09f9c83",
"packagetype": "bdist_wheel",
"python_version": "cp313",
"requires_python": ">=3.10",
"size": 3582090,
"upload_time": "2025-10-26T08:07:53",
"upload_time_iso_8601": "2025-10-26T08:07:53.587282Z",
"url": "https://files.pythonhosted.org/packages/12/a8/54a12dbe97e7ce4081fccf5b7ce52d4b974e940c9a34b430c35c023d4440/vnpy_ctp-6.7.11.1-cp313-cp313-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "ee9ca770676af2a5724943260ed457f71295b3030d4c123056730d3357ad4911",
"md5": "bb5df36b9336f9074dc349f4c82a8b0f",
"sha256": "b3c31e5e61069b29789ca2085777a3686a972dd37476ae95c0042b040b661539"
},
"downloads": -1,
"filename": "vnpy_ctp-6.7.11.1.tar.gz",
"has_sig": false,
"md5_digest": "bb5df36b9336f9074dc349f4c82a8b0f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 12580119,
"upload_time": "2025-10-26T08:08:18",
"upload_time_iso_8601": "2025-10-26T08:08:18.677847Z",
"url": "https://files.pythonhosted.org/packages/ee/9c/a770676af2a5724943260ed457f71295b3030d4c123056730d3357ad4911/vnpy_ctp-6.7.11.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-26 08:08:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "vnpy",
"github_project": "vnpy_ctp",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "vnpy_ctp"
}