{"id":20317404,"url":"https://github.com/openctp/openctp-ctpopt-python","last_synced_at":"2025-04-11T17:50:43.778Z","repository":{"id":225171711,"uuid":"764565009","full_name":"openctp/openctp-ctpopt-python","owner":"openctp","description":"CTP股票期权柜台的Python接口，使用Swig技术制作，支持pip install。","archived":false,"fork":false,"pushed_at":"2024-12-13T04:28:29.000Z","size":5616,"stargazers_count":12,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T07:37:22.303Z","etag":null,"topics":["ctp","ctpapi","futures","openctp","options","quant","stocks","trader"],"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":null,"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":"2024-02-28T10:05:08.000Z","updated_at":"2024-12-15T21:58:06.000Z","dependencies_parsed_at":"2024-07-10T19:10:56.114Z","dependency_job_id":null,"html_url":"https://github.com/openctp/openctp-ctpopt-python","commit_stats":null,"previous_names":["jedore/openctp-ctpopt-python","openctp/openctp-ctpopt-python"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openctp%2Fopenctp-ctpopt-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openctp%2Fopenctp-ctpopt-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openctp%2Fopenctp-ctpopt-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openctp%2Fopenctp-ctpopt-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openctp","download_url":"https://codeload.github.com/openctp/openctp-ctpopt-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248455282,"owners_count":21106590,"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","futures","openctp","options","quant","stocks","trader"],"created_at":"2024-11-14T18:31:48.008Z","updated_at":"2025-04-11T17:50:43.763Z","avatar_url":"https://github.com/openctp.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CTP股票期权Python接口\n\n## 直接使用\n\nopenctp提供了pip install和文件下载两种方法安装CTPOPT-Python库，可以直接使用，均支持3.5.8~3.7.0各个版本。\n\n### pip install方式\n\n```bash\npip install openctp-ctpopt==3.7.0.* -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host=pypi.tuna.tsinghua.edu.cn\n```\n\n### 文件下载方式\n\n[CTPOPT-Python接口下载](http://openctp.cn/download.html)\n\n## 自己编译\nCTPOPT-Python使用Swig技术开发，可以自己按以下步骤编译，需要安装swig等组件，详细攻略见：[CTPAPI-Python开发攻略](https://zhuanlan.zhihu.com/p/688672132)。\n\n本仓库选用的是CTPOPT-3.7.0，如需编译其它版本，请下载相应的CTPOPT文件覆盖对应目录下的CTPOPT文件。\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编译成功后，将生成的文件连同CTPOPT的dll（soptthosttraderapi.dll、soptthostmduserapi.dll）拷贝到你的程序运行目录下即可：\n- soptthosttraderapi.py\n- soptthostmduserapi.py\n- _soptthostmduserapi.pyd\n- _soptthosttraderapi.pyd\n\n#### Win32\n```\ncd CTPOPT\nmkdir build\ncd build\ncmake ..\ncmake --build . --config Release\n```\n\n#### Win64\n```\ncd CTPOPT\nmkdir build\ncd build\ncmake -A x64 ..\ncmake --build . --config Release\n```\n\n### Linux编译\n编译成功后，将生成的文件连同CTPOPT的so文件（soptthosttraderapi.so、soptthostmduserapi.so）拷贝到你的程序运行目录下即可：\n- soptthosttraderapi.py\n- soptthostmduserapi.py\n- _soptthostmduserapi.so\n- _soptthosttraderapi.so\n```\ncd CTPOPT\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-ctpopt-python/CTPOPT/lin64/ThostFtdcTraderApi.h:30: Warning 514: Director base class CThostFtdcTraderSpi has no virtual destructor.\n/home/krenx/programming/github-ssh/openctp-ctpopt-python/CTPOPT/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-ctpopt-python/CTPOPT/build\n[krenx]$ make\nScanning dependencies of target _soptthostmduserapi\n[ 50%] Building CXX object CMakeFiles/_soptthostmduserapi.dir/soptthostmduserapi_wrap.cxx.o\nLinking CXX shared library _soptthostmduserapi.so\n[ 50%] Built target _soptthostmduserapi\nScanning dependencies of target _soptthosttraderapi\n[100%] Building CXX object CMakeFiles/_soptthosttraderapi.dir/soptthosttraderapi_wrap.cxx.o\nLinking CXX shared library _soptthosttraderapi.so\n[100%] Built target _soptthosttraderapi\n[krenx]$\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenctp%2Fopenctp-ctpopt-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenctp%2Fopenctp-ctpopt-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenctp%2Fopenctp-ctpopt-python/lists"}