docs.rs failed to build ctp2rs-0.1.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
ctp2rs-0.1.8
Ctp2rs
采用 libloading 加载 ctp 动态库的 CTP API 的 Rust 绑定封装
历史项目 ctp-dyn
Usage
- 项目中添加相关库
cargo add ctp2rs
或者在 Cargo.toml 中添加
[]
= "0.1.0"
# or below
= { = "https://github.com/pseudocodes/ctp2rs", = "ctp2rs" }
- 切换 CTP API 版本
当前支持 CTP v6.7.2, v6.7.7 两个版本, 详细请查看 Cargo.toml
[]
= { = "0.1.0", = ["ctp_v6_7_7"] }
- 基本样例
let dynlib_path = "../../ctp-dyn/api/v6.7.2/v6.7.2_MacOS_20231016/thostmduserapi_se.framework/thostmduserapi_se";
let dynlib_path = "../../ctp-dyn/api/v6.7.2/v6.7.2_20230913_api_traderapi_se_linux64/thostmduserapi_se.so";
let mdapi = create_api;
...
Examples
See /examples for various uses of Ctp2rs. You can run them with:
- channel: 采用 channel 来获取行情,支持 MacOS 以及 Linux
- localctp: 运行 localctp 的一个样例,支持 Linux
- openctp: 连接 openctp 模拟平台的行情以及交易样例,支持 MacOS 以及 Linux
Related Projects
| 项目名称 | 链接 | crate | 支持平台 | 关系/特点 | |
|---|---|---|---|---|---|
| 1 | WiSaGaN/ctp-rs | github.com/WiSaGaN/ctp-rs | N/A | Win64/Linux | 采用 vtable 映射实现 C++ 类的方法调用, |
| 2 | SheldonNico/ctp-rs | github.com/SheldonNico/ctp-rs | N/A | Win64/Linux | 采用 C++ wrapper 代码作为桥接辅助封装 |
| 3 | rust-share | github.com/mineralres/rust-share | N/A | Win64/Linux | 首个提供了构建时解析 CTP 头文件并生成 Rust 封装代码的功能的项目,同时提供了异步 Stream 调用接口功能 |
| 4 | gqf2008/ctp-rs | github.com/gqf2008/ctp-rs | N/A | Win64/Linux | 类似2, 采用 C++ 代码辅助封装 |
| 5 | libctp-sys | github.com/unknown-marketwizards/libctp-sys | libctp-sys | Win64/Linux | 类似2, 采用 C++ 代码辅助封装 |
| 6 | ctp-rust | github.com/kozyan/ctp-rust | N/A | Win64/Linux | 2 的分支项目 |
| 7 | ctp-alone | github.com/calebx/ctp-alone | N/A | Win64/Linux | 1 的分支项目 |
| 8 | ctp-sys | https://github.com/daedalus2022/ctp-sys | ctp-sys | Win64/Linux | rust-share 的分支实现 |
| 9 | ctp-futures | github.com/baiguoname/ctp-futures | ctp-futures | Win64/Linux | rust-share 的分支实现 |
| 10 | localctp-sys | github.com/WhisperCapital/localctp-sys | localctp-sys | Win64/Linux | rust-share 分支实现,作者重写了封装代码生成模块,扩展性较强,仅适配 LocalCTP, 不支持官方版本 |
Potential Issues
- 以上项目均为静态编译项目,构建过程中需要二进制库参与编译,项目运行时需要通过环境变量指定动态库加载位置
- 当 CTP 升级版本时,开发者需要自行重新构建项目,用以升级依赖的 Cpp 头文件和依赖库
- 同上,当需要切换 CTP API 柜台时,部署时需要通过环境变量替换动态库,无法在同一个进程中访问多种柜台
- 基本不支持 MacOS 平台
Development Environment
以下开发环境编译成功
- MacOS (Apple Silicon)
> clang --version
Apple clang version 16.0.0 (clang-1600.0.26.4)
Target: arm64-apple-darwin23.6.0
> rustc --version
rustc 1.81.0 (eeb90cda1 2024-09-04)
- Ubuntu 22.04.1 LTS (Aliyun ecs)
> clang --version
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
> g++ --version
g++ (Ubuntu 11.2.0-19ubuntu1) 11.2.0
> rustc --version
rustc 1.77.2 (25ef9e3d8 2024-04-09)
Reference
【1】OpenCTP: 类上期技术 SimNow 开放模拟环境
【2】LocalCTP: 部署于本地的仿 CTP 项目
【3】Go2CTP: Go 语言加载动态库 CTP 接口封装