基于 SWIG 实现的对上期技术 CTP 的封装。支持 64 位的 Windows 及 Linux 操作系统,动态链接库已被包含至 jar 包内,并在类加载时自动 loadLibrary,只需添加 jar 包即可直接使用。
当前已封装的 CTP 版本:
6.6.1_P1-1.0.0
6.6.1_P1_CP-1.0.0
6.3.19_P1-1.0.0
6.3.19_T1-1.0.0
API 及使用方法同上期技术官方提供的 C++ 版 CTP SDK,另外使用前可以通过以下方法判断动态链接库是否已被成功加载:
import org.rationalityfrontline.jctp.*
fun main() {
if (jctpJNI.libraryLoaded()) {
// do something with CTP, here we print its sdk version
println(CThostFtdcTraderApi.GetApiVersion())
// release native gc root in jni, jctp will be unavailable after doing this
jctpJNI.release()
} else {
System.err.println("Library load failed!")
}
}
如果在 Linux 环境下使用,则需要确保已安装 zh_CN.GB18030 字符集:
sudo locale-gen zh_CN.GB18030
sudo dpkg-reconfigure locales
Gradle Kotlin DSL:
repositories {
mavenCentral()
}
dependencies {
implementation("org.rationalityfrontline:jctp:6.6.1_P1-1.0.0")
}
Maven:
<dependency>
<groupId>org.rationalityfrontline</groupId>
<artifactId>jctp</artifactId>
<version>6.6.1_P1-1.0.0</version>
</dependency>
Jar:
使用 Jar 包前请先添加 native-lib-loader 依赖:
dependencies {
implementation("org.scijava:native-lib-loader:2.3.5")
}
前提要求(版本信息仅供参考,非必要):
- 安装 SWIG 4.0.2 并将其添加至环境变量中
- 安装 CMake > 3.16 并将其添加至环境变量中
- 安装 C++ 编译器( Windows 下是 msvc,Linux 下是 gcc/g++)
- 安装 JDK 14 并将其添加至环境变量中
Windows
build.cmd
Linux
./build.sh
以上为单平台版本编译,如需编译跨平台版本,则需要在两个平台下各编译一次(顺序随意)。
build 完毕后,生成的 jar 包在 java/build/libs 目录下。
https://blog.csdn.net/pjjing/article/details/53186394
http://www.swig.org/Doc4.0/Contents.html#Contents
https://github.com/scijava/native-lib-loader
JCTP is released under the Apache 2.0 license.
Copyright 2020-2021 RationalityFrontline
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.