# ctp-rs **Repository Path**: kozyan/ctp-rs ## Basic Information - **Project Name**: ctp-rs - **Description**: 尝试在 rust 下使用 ctp api 来写程序 - **Primary Language**: Rust - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 3 - **Created**: 2022-08-17 - **Last Updated**: 2023-07-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: Rust, ctp ## README # ctp-rs CTP sdk version: `v6.6.1_P1_20210406` windows 环境下: 编译时需要安装 1. LLVM-14.0.6-win64.exe 2. 使用MSVC工具链和VSCode搭建Rust环境 https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/ 运行 examples 里的 mdapi 或 tdapi 命令如下: `cargo run --example mdapi` 或 `cargo run --example tdapi` 注意:由于 rust-bindgen 当前版本(0.60.1)有 bug,如果要重新生成 src/generated/mod.rs 文件,则产生的释构函数的 link 名称,需要用以下的来替换 ```c++ ??1Rust_CThostFtdcMdApi@@QEAA@XZ (public: __cdecl Rust_CThostFtdcMdApi::~Rust_CThostFtdcMdApi(void)): ??1Rust_CThostFtdcMdSpi@@QEAA@XZ (public: __cdecl Rust_CThostFtdcMdSpi::~Rust_CThostFtdcMdSpi(void)): ??1Rust_CThostFtdcTraderApi@@QEAA@XZ (public: __cdecl Rust_CThostFtdcTraderApi::~Rust_CThostFtdcTraderApi(void)): ??1Rust_CThostFtdcTraderSpi@@QEAA@XZ (public: __cdecl Rust_CThostFtdcTraderSpi::~Rust_CThostFtdcTraderSpi(void)): ``` ------------------------------------------------------------------- linux 环境下: 编译时需要安装 llvm 和 clang: # sudo apt install llvm-dev libclang-dev clang # sudo apt-get install clang ***特别说明:代码源自 https://github.com/SheldonNico/ctp-rs 的一个分支,但是我在 windows 环境下一直没有跑成功,所以另建一个名字来学习 ctp 及 rust。*** `*.hpp` and `*.cpp` are generated by `autobind.py`, then processed by [rut_bindgen](https://rust-lang.github.io/rust-bindgen/requirements.html). Look at [xtp-rs](https://github.com/dovahcrow/xtp-rs) for detail. __Use at your own risk__. The crate is unsafe, look at [examples/tdapi.rs](./examples/tdapi.rs) and [examples/mdapi.rs](./examples/mdapi.rs) for how to use it. ## where to put my .so files so files is not included, please put it like this: ``` $ tree shared shared ├── data_collect │   ├── unix.x86_64 │   │   ├── libLinuxDataCollect.so -> LinuxDataCollect.so │   │   └── LinuxDataCollect.so │   ├── windows.x86 │   │   ├── WinDataCollect.dll │   │   └── WinDataCollect.lib │   └── windows.x86_x64 │   ├── WinDataCollect.dll │   └── WinDataCollect.lib ├── include │   ├── DataCollect.h │   ├── ThostFtdcMdApi.h │   ├── ThostFtdcTraderApi.h │   ├── ThostFtdcUserApiDataType.h │   └── ThostFtdcUserApiStruct.h ├── md │   ├── unix.x86_64 │   │   ├── libthostmduserapi_se.so -> thostmduserapi_se.so │   │   └── thostmduserapi_se.so │   ├── windows.x86 │   │   ├── thostmduserapi_se.dll │   │   └── thostmduserapi_se.lib │   └── windows.x86_x64 │   ├── thostmduserapi_se.dll │   └── thostmduserapi_se.lib └── td ├── unix.x86_64 │   ├── libthosttraderapi_se.so -> thosttraderapi_se.so │   └── thosttraderapi_se.so ├── windows.x86 │   ├── thosttraderapi_se.dll │   └── thosttraderapi_se.lib └── windows.x86_x64 ├── thosttraderapi_se.dll └── thosttraderapi_se.lib ```