Skip to content

SheldonNico/ctp-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ctp-rs

CTP sdk version: 6.3.15_20190220 15:47:00

*.hpp and *.cpp are generated by autobind.py, then processed by rust_bindgen. Look at xtp-rs for detail.

Use at your own risk. The crate is unsafe, look at examples/tdapi.rs and examples/mdapi.rs for how to use it.

How to use autobind.py

If you want to generate wrapp.hpp by yourself or wrapper similar apis. You can put your header files in shared/include like I did. Then run

python3 -m pip install libclang
python3 autobind.py > src/wrapper_ext

Those cpp code are included in src/wrapper.hpp, where you can add your custom functions.

Then the rust_bindgen will generate rust extern "C" func_XXX function declarations. Since then all api function should be usable.

There are lots of extern "C" Rust_XXX_Trait_On_XX function inside wrapper_ext, which are colloceted in build.rs to generate nice trait object. Remove it in autobind.py if you don't want it.

where to put my .so files

XXX.so files are not included, please put it like this to satify compiler:

$ exa -T shared
shared
├── include
│  ├── DataCollect.h
│  ├── ThostFtdcMdApi.h
│  ├── ThostFtdcTraderApi.h
│  ├── ThostFtdcUserApiDataType.h
│  └── ThostFtdcUserApiStruct.h
├── unix.x86_64
│  ├── 6.6.9_CP
│  │  ├── thostmduserapi_se.so
│  │  └── thosttraderapi_se.so
│  ├── 6.7.0_CP
│  │  ├── thostmduserapi_se.so
│  │  └── thosttraderapi_se.so
│  ├── libLinuxDataCollect.so -> LinuxDataCollect.so
│  ├── libthostmduserapi_se.so -> thostmduserapi_se.so
│  ├── libthosttraderapi_se.so -> thosttraderapi_se.so
│  ├── LinuxDataCollect.so
│  ├── thostmduserapi_se.so
│  └── thosttraderapi_se.so
├── windows.x86
│  ├── thostmduserapi_se.dll
│  ├── thostmduserapi_se.lib
│  ├── thosttraderapi_se.dll
│  ├── thosttraderapi_se.lib
│  ├── WinDataCollect.dll
│  └── WinDataCollect.lib
└── windows.x86_64
   ├── thostmduserapi_se.dll
   ├── thostmduserapi_se.lib
   ├── thosttraderapi_se.dll
   ├── thosttraderapi_se.lib
   ├── WinDataCollect.dll
   └── WinDataCollect.lib

How to build on windows

  1. File tree for windows:
PS D:\Desktop\ctp-rs> tree .\shared\
Folder PATH listing for volume Resources
Volume serial number is B26B-15B2
D:\DESKTOP\CTP-RS\SHARED
├───include
├───unix.x86_64
│   ├───6.6.9_CP
│   └───6.7.0_CP
├───windows.x86
└───windows.x86_64
PS D:\Desktop\ctp-rs> dir .\shared\windows.x86_64\


    目录: D:\Desktop\ctp-rs\shared\windows.x86_64


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         2022/12/6     17:28        2800128 thostmduserapi_se.dll
-a----         2022/12/6     17:28           3822 thostmduserapi_se.lib
-a----         2020/11/5     16:59        3181568 thosttraderapi_se.dll
-a----         2020/11/5     16:59           3960 thosttraderapi_se.lib
-a----         2020/11/5     16:59        1865216 WinDataCollect.dll
-a----         2020/11/5     16:59           1992 WinDataCollect.lib
  1. Make sure you have llvm + visual studio installed. Gcc may work, but I didn't try.
PS D:\Desktop\ctp-rs> scoop install llvm
WARN  'llvm' (19.1.3) is already installed.
Use 'scoop update llvm' to install a new version.

# scoop will setup environment path right to include libclang.dll. which is important.
#
# If you install llvm mannually, you should setup environment path by hand.
  1. cargo b --example tdapi should work. issue 1725 has been fiexed by updating bindgen-rs.

About

rust bindings for ctp

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published