{"id":20317406,"url":"https://github.com/openctp/openctp-ctp-python","last_synced_at":"2025-05-15T22:12:07.652Z","repository":{"id":152589444,"uuid":"622847205","full_name":"openctp/openctp-ctp-python","owner":"openctp","description":"CTPAPI的Python接口，使用Swig技术制作，支持pip install。","archived":false,"fork":false,"pushed_at":"2025-04-13T06:42:52.000Z","size":3329,"stargazers_count":183,"open_issues_count":7,"forks_count":42,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-15T13:43:55.306Z","etag":null,"topics":["ctp","ctpapi","investment","openctp","python","quant","trader","trading"],"latest_commit_sha":null,"homepage":"http://www.openctp.cn","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openctp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-03T07:27:11.000Z","updated_at":"2025-05-13T19:09:39.000Z","dependencies_parsed_at":"2024-07-09T16:11:13.819Z","dependency_job_id":null,"html_url":"https://github.com/openctp/openctp-ctp-python","commit_stats":null,"previous_names":["jedore/openctp-ctp-python"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openctp%2Fopenctp-ctp-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openctp%2Fopenctp-ctp-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openctp%2Fopenctp-ctp-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openctp%2Fopenctp-ctp-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openctp","download_url":"https://codeload.github.com/openctp/openctp-ctp-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254364180,"owners_count":22058874,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ctp","ctpapi","investment","openctp","python","quant","trader","trading"],"created_at":"2024-11-14T18:31:48.484Z","updated_at":"2025-05-15T22:12:02.643Z","avatar_url":"https://github.com/openctp.png","language":"C","readme":"# Python版CTPAPI\n\n## 直接使用\n\nopenctp提供了pip install和文件下载两种方法安装CTPAPI-Python库，可以直接使用，均支持6.3.15~6.7.2各个版本。\n\n### pip install方式\n\n```bash\npip install openctp-ctp==6.3.15.* -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host=pypi.tuna.tsinghua.edu.cn\n```\n\n### 文件下载方式\n\n[CTPAPI-Python接口下载](http://openctp.cn/download.html)\n\n## 自己编译\nCTPAPI-Python使用Swig技术开发，可以自己按以下步骤编译，需要安装swig等组件，详细攻略见：[CTPAPI-Python开发攻略](https://zhuanlan.zhihu.com/p/688672132)。\n\n本仓库选用的是CTPAPI-6.3.15，如需编译其它版本，请下载相应的CTPAPI文件覆盖对应目录下的CTPAPI文件。\n\n### 准备\n- 安装VirtualStudio、Swig、Python3、boost、cmake，boost库用到的是locale库，用来转换字符集。\n- 设置BOOST_INCLUDE、BOOST_LIB环境变量分别指向相应库的头文件及库目录，如E:\\boost_1_73_0、E:\\boost_1_73_0\\stage\\lib。\n- 设置PYTHON_INCLUDE、PYTHON_LIB环境变量分别指向相应库的头文件及库目录，如C:\\Program Files\\Python312\\include、C:\\Program Files\\Python312\\libs。\n\n### Windows编译\n编译成功后，将生成的文件连同CTPAPI的dll（thosttraderapi.dll、thostmduserapi.dll）拷贝到你的程序运行目录下即可：\n- thosttraderapi.py\n- thostmduserapi.py\n- _thostmduserapi.pyd\n- _thosttraderapi.pyd\n\n#### Win32\n```\ncd CTPAPI\nmkdir build\ncd build\ncmake ..\ncmake --build . --config Release\n```\n\n#### Win64\n```\ncd CTPAPI\nmkdir build\ncd build\ncmake -A x64 ..\ncmake --build . --config Release\n```\n\n### Linux编译\n编译成功后，将生成的文件连同CTPAPI的so文件（thosttraderapi.so、thostmduserapi.so）拷贝到你的程序运行目录下即可：\n- thosttraderapi.py\n- thostmduserapi.py\n- _thostmduserapi.so\n- _thosttraderapi.so\n```\ncd CTPAPI\nmkdir build\ncd build\ncmake ..\nmake\n```\n### 效果\n```\n[krenx]$ cmake ..\n-- The C compiler identification is GNU 9.3.1\n-- The CXX compiler identification is GNU 9.3.1\n-- Check for working C compiler: /opt/rh/devtoolset-9/root/usr/bin/cc\n-- Check for working C compiler: /opt/rh/devtoolset-9/root/usr/bin/cc -- works\n-- Detecting C compiler ABI info\n-- Detecting C compiler ABI info - done\n-- Check for working CXX compiler: /opt/rh/devtoolset-9/root/usr/bin/c++\n-- Check for working CXX compiler: /opt/rh/devtoolset-9/root/usr/bin/c++ -- works\n-- Detecting CXX compiler ABI info\n-- Detecting CXX compiler ABI info - done\ngenerate swig wrap files ...\n/home/krenx/programming/github-ssh/openctp-ctp-python/CTPAPI/lin64/ThostFtdcTraderApi.h:30: Warning 514: Director base class CThostFtdcTraderSpi has no virtual destructor.\n/home/krenx/programming/github-ssh/openctp-ctp-python/CTPAPI/lin64/ThostFtdcMdApi.h:30: Warning 514: Director base class CThostFtdcMdSpi has no virtual destructor.\n-- Configuring done\n-- Generating done\n-- Build files have been written to: /home/krenx/programming/github-ssh/openctp-ctp-python/CTPAPI/build\n[krenx]$ make\nScanning dependencies of target _thostmduserapi\n[ 50%] Building CXX object CMakeFiles/_thostmduserapi.dir/thostmduserapi_wrap.cxx.o\nLinking CXX shared library _thostmduserapi.so\n[ 50%] Built target _thostmduserapi\nScanning dependencies of target _thosttraderapi\n[100%] Building CXX object CMakeFiles/_thosttraderapi.dir/thosttraderapi_wrap.cxx.o\nLinking CXX shared library _thosttraderapi.so\n[100%] Built target _thosttraderapi\n[krenx]$\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenctp%2Fopenctp-ctp-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenctp%2Fopenctp-ctp-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenctp%2Fopenctp-ctp-python/lists"}