CTP (China Futures Market) Python API Wrapper with multi-implementation support
Project description
ctpx
本项目使用 SWIG 将 CTP C++ 接口封装为 Python 接口,支持官方 CTP 库或三方兼容库(如融航、杰宜斯等)。
构建
依赖
若从源码构建,需要安装以下工具:
- Python >= 3.12
- SWIG
- Boost
- CMake
macOS
brew install swig boost cmake
Linux
sudo apt install swig libboost-all-dev cmake
编译及打包
项目使用 scikit-build-core 作为构建后端,构建时会自动调用 CMake 编译 SWIG 扩展并打包成 wheel。
./build.sh
或者
uv build
Linux manylinux 发布版
发布到 PyPI 的 Linux wheel 需要在 manylinux 容器中构建并使用 auditwheel repair。本项目通过 cibuildwheel 在 GitHub Actions 中完成这一流程,详见 .github/workflows/build-release.yml。
使用
- 安装 wheel
pip install dist/*.whl
#或者
pip install ctpx
- 官方 CTP 实现
from ctpx.ctp import mdapi, tdapi
trader_api = tdapi.CThostFtdcTraderApi.CreateFtdcTraderApi()
md_api = mdapi.CThostFtdcMdApi.CreateFtdcMdApi()
- 融航实现
from ctpx.rohon import mdapi, tdapi
trader_api = tdapi.CThostFtdcTraderApi.CreateFtdcTraderApi()
md_api = mdapi.CThostFtdcMdApi.CreateFtdcMdApi()
注意事项
- 同一进程只能使用一种实现:不可同时导入
ctpx.ctp和ctpx.rohon。 - Windows DLL 搜索:Python 3.8+ 使用
os.add_dll_directory,旧版本需要设置PATH。 - Linux 预加载:使用
ctypes.CDLL(..., RTLD_GLOBAL)确保符号全局可见。
参考
- openctp
- vnpy_ctp
- CTPAPI-Python 开发攻略
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ctpx-6.7.2.3-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: ctpx-6.7.2.3-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 31.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e934f677ebe49b8d41c97ff37aac2083908565d59f835085dcc7ede863a09b3
|
|
| MD5 |
b6ecd272bb1409abbcee19a9fa34250c
|
|
| BLAKE2b-256 |
1ef84842c9ae70b02d6f242ffd6e82c2cf4f869a6cf9c430f41ea9f6c0701aee
|
Provenance
The following attestation bundles were made for ctpx-6.7.2.3-cp312-cp312-manylinux_2_34_x86_64.whl:
Publisher:
build-release.yml on csuduan/pyctp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ctpx-6.7.2.3-cp312-cp312-manylinux_2_34_x86_64.whl -
Subject digest:
9e934f677ebe49b8d41c97ff37aac2083908565d59f835085dcc7ede863a09b3 - Sigstore transparency entry: 1951698504
- Sigstore integration time:
-
Permalink:
csuduan/pyctp@6a24f4967308f5c3e876d4d2ea37dd49fd12a3f3 -
Branch / Tag:
refs/tags/v6.7.2.3 - Owner: https://github.com/csuduan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-release.yml@6a24f4967308f5c3e876d4d2ea37dd49fd12a3f3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ctpx-6.7.2.3-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: ctpx-6.7.2.3-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 9.9 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6856983d4d1cc215f5779f6829fcf4363ce96aa9249359fce5d717cf483a7a90
|
|
| MD5 |
61f57a113c8c8496e8147e2e5137721f
|
|
| BLAKE2b-256 |
eaa272c9da590194b2de753441fe4e61f2fc1b5636b770acaa9093f0c6ec0ed1
|
Provenance
The following attestation bundles were made for ctpx-6.7.2.3-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
build-release.yml on csuduan/pyctp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ctpx-6.7.2.3-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
6856983d4d1cc215f5779f6829fcf4363ce96aa9249359fce5d717cf483a7a90 - Sigstore transparency entry: 1951698004
- Sigstore integration time:
-
Permalink:
csuduan/pyctp@6a24f4967308f5c3e876d4d2ea37dd49fd12a3f3 -
Branch / Tag:
refs/tags/v6.7.2.3 - Owner: https://github.com/csuduan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-release.yml@6a24f4967308f5c3e876d4d2ea37dd49fd12a3f3 -
Trigger Event:
push
-
Statement type: