Skip to main content

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()

注意事项

  1. 同一进程只能使用一种实现:不可同时导入 ctpx.ctp 和 ctpx.rohon。
  2. Windows DLL 搜索:Python 3.8+ 使用 os.add_dll_directory,旧版本需要设置 PATH。
  3. Linux 预加载:使用 ctypes.CDLL(..., RTLD_GLOBAL) 确保符号全局可见。

参考

Metadata

Release files for ctpx 6.7.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for ctpx 6.7.2.6
File Interpreter ABI Platform Actions
ctpx-6.7.2.6-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for ctpx-6.7.2.6-cp312-cp312-win_amd64.whl
ctpx-6.7.2.6-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details for ctpx-6.7.2.6-cp312-cp312-manylinux_2_34_x86_64.whl
ctpx-6.7.2.6-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for ctpx-6.7.2.6-cp312-cp312-macosx_11_0_arm64.whl

Total release size: 86.4 MB

Release files / ctpx-6.7.2.6-cp312-cp312-win_amd64.whl

Download URL ctpx-6.7.2.6-cp312-cp312-win_amd64.whl
Size 45.2 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
3ea83835766c8c55651551b1052286812e5d1adb865fa7b6de29d8135705a62d
BLAKE2b-256 checksum
How to use checksums
16fa6d5c06f0b8f1f7e0e8f2cb27fdca4e514c56cbaa1336de48eafeaddc5e7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 27, 2026.

Transparency log

Release files / ctpx-6.7.2.6-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL ctpx-6.7.2.6-cp312-cp312-manylinux_2_34_x86_64.whl
Size 31.3 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
f7e4dc8c60996eab8cc03cfa765488dba9ab6634376566fefb1a89656cdd3a58
BLAKE2b-256 checksum
How to use checksums
d4028cd4c34166c1e1609490dca7aca79115714508807cbdd2699a5c232aa273
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 27, 2026.

Transparency log

Release files / ctpx-6.7.2.6-cp312-cp312-macosx_11_0_arm64.whl

Download URL ctpx-6.7.2.6-cp312-cp312-macosx_11_0_arm64.whl
Size 9.9 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
65cd140656d8b69bc05ac41aebfc24252f1bafc10bd307fddb002b76b5c1419d
BLAKE2b-256 checksum
How to use checksums
eb482194838062522e2732e8bdb66c5fbef3b779704610f972be484f99b8e5d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 27, 2026.

Transparency log

Security for ctpx 6.7.2.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 3 files in this release have been uploaded with provenance metadata.

Select from 3 files

Attestation for ctpx-6.7.2.6-cp312-cp312-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page