├── .gitignore ├── CMakeLists.txt ├── R └── CMakeLists.txt ├── README.md ├── cmake ├── FindCSharp.cmake ├── FindMaven.cmake ├── FindMono.cmake ├── FindOctave.cmake ├── FindR.cmake └── UseMono.cmake ├── code ├── CMakeLists.txt ├── Callback.cpp ├── Callback.h ├── Main.cpp ├── R │ └── CMakeLists.txt ├── callback.i ├── csharp │ ├── CMakeLists.txt │ └── Runme.cs ├── java │ ├── CMakeLists.txt │ └── Runme.java ├── octave │ ├── CMakeLists.txt │ └── runme.m ├── python │ ├── CMakeLists.txt │ └── runme.py └── ruby │ ├── CMakeLists.txt │ └── runme.rb ├── csharp └── CMakeLists.txt ├── ctp.i ├── ctp ├── api │ ├── risk │ │ ├── changelog.txt │ │ ├── lib │ │ │ ├── riskuserapi.dll │ │ │ └── riskuserapi.lib │ │ └── public │ │ │ ├── FtdcRiskUserApi.h │ │ │ ├── FtdcRiskUserApiDataType.h │ │ │ └── FtdcRiskUserApiStruct.h │ └── trade │ │ ├── changelog.txt │ │ ├── linux32 │ │ ├── lib │ │ │ ├── error.dtd │ │ │ ├── error.xml │ │ │ ├── libthostmduserapi.so │ │ │ ├── libthosttraderapi.so │ │ │ ├── thostmduserapi.so │ │ │ └── thosttraderapi.so │ │ └── public │ │ │ ├── ThostFtdcMdApi.h │ │ │ ├── ThostFtdcTraderApi.h │ │ │ ├── ThostFtdcUserApiDataType.h │ │ │ └── ThostFtdcUserApiStruct.h │ │ ├── linux64 │ │ ├── lib │ │ │ ├── error.dtd │ │ │ ├── error.xml │ │ │ ├── libthostmduserapi.so │ │ │ ├── libthosttraderapi.so │ │ │ ├── thostmduserapi.so │ │ │ └── thosttraderapi.so │ │ └── public │ │ │ ├── ThostFtdcMdApi.h │ │ │ ├── ThostFtdcTraderApi.h │ │ │ ├── ThostFtdcUserApiDataType.h │ │ │ └── ThostFtdcUserApiStruct.h │ │ └── win │ │ ├── lib │ │ ├── error.dtd │ │ ├── error.xml │ │ ├── thostmduserapi.dll │ │ ├── thostmduserapi.lib │ │ ├── thosttraderapi.dll │ │ └── thosttraderapi.lib │ │ └── public │ │ ├── ThostFtdcMdApi.h │ │ ├── ThostFtdcTraderApi.h │ │ ├── ThostFtdcUserApiDataType.h │ │ └── ThostFtdcUserApiStruct.h └── demo │ └── CMakeLists.txt ├── java ├── CMakeLists.txt └── Runmd.java ├── lua ├── CMakeLists.txt ├── pex.cpp ├── pex.h └── pex.i ├── octave └── CMakeLists.txt ├── perl └── CMakeLists.txt ├── pex.cpp ├── pex.h ├── python ├── CMakeLists.txt ├── char_array.i ├── examples │ └── md.py ├── install │ ├── __init__.py │ └── setup.py ├── runmd.py └── setup.py ├── ruby ├── .idea │ ├── scopes │ │ └── scope_settings.xml │ └── workspace.xml ├── CMakeLists.txt ├── char_array.i ├── ctp.gemspec └── runmd.rb ├── tcl └── CMakeLists.txt └── test ├── CMakeLists.txt └── ruby ├── CMakeLists.txt └── runmd.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.user 2 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(ctp-swig) 3 | 4 | set(BUILD_SHARED_LIBS true) 5 | set(CMAKE_BUILD_TYPE Release) 6 | set(CMAKE_VERBOSE_MAKEFILE true) 7 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) 8 | 9 | if(WIN32) 10 | set(CMAKE_INSTALL_PREFIX $ENV{HOMEPATH}) 11 | else() 12 | set(CMAKE_INSTALL_PREFIX $ENV{HOME}) 13 | endif() 14 | 15 | if(WIN32) 16 | set(CTP_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/ctp/api/trade/win/public) 17 | set(CTP_LIBRARY_DIRS ${PROJECT_SOURCE_DIR}/ctp/api/trade/win/lib ${PROJECT_SOURCE_DIR}/ctp/api/risk/lib) 18 | elseif(UNIX) 19 | set(CTP_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/ctp/api/trade/linux64/public) 20 | set(CTP_LIBRARY_DIRS ${PROJECT_SOURCE_DIR}/ctp/api/trade/linux64/lib) 21 | endif() 22 | 23 | if(WIN32) 24 | find_library(CTP_MDUSER_LIBRARY NAMES thostmduserapi PATHS ${CTP_LIBRARY_DIRS}) 25 | find_library(CTP_TRADE_LIBRARY NAMES thosttraderapi PATHS ${CTP_LIBRARY_DIRS}) 26 | find_library(CTP_RISK_LIBRARY NAMES riskuserapi PATHS ${CTP_LIBRARY_DIRS}) 27 | if(CTP_MDUSER_LIBRARY AND CTP_TRADE_LIBRARY AND CTP_RISK_LIBRARY) 28 | set(CTP_LIBRARIES ${CTP_MDUSER_LIBRARY} ${CTP_TRADE_LIBRARY} ${CTP_RISK_LIBRARY}) 29 | set(CTP_SHAREDLIBFILES ${PROJECT_SOURCE_DIR}/ctp/api/risk/lib/riskuserapi.dll 30 | ${PROJECT_SOURCE_DIR}/ctp/api/trade/win/lib/thostmduserapi.dll 31 | ${PROJECT_SOURCE_DIR}/ctp/api/trade/win/lib/thosttraderapi.dll 32 | ) 33 | endif() 34 | elseif(UNIX) 35 | find_library(CTP_MDUSER_LIBRARY thostmduserapi PATHS ${CTP_LIBRARY_DIRS}) 36 | find_library(CTP_TRADE_LIBRARY thosttraderapi PATHS ${CTP_LIBRARY_DIRS}) 37 | if(CTP_MDUSER_LIBRARY AND CTP_TRADE_LIBRARY) 38 | set(CTP_LIBRARIES ${CTP_MDUSER_LIBRARY} ${CTP_TRADE_LIBRARY}) 39 | set(CTP_SHAREDLIBFILES ${CTP_LIBRARIES}) 40 | endif() 41 | endif() 42 | include_directories(${CTP_INCLUDE_DIRS}) 43 | file(COPY ${CTP_SHAREDLIBFILES} DESTINATION "${CMAKE_INSTALL_PREFIX}/local/lib") 44 | 45 | find_package(SWIG REQUIRED) 46 | if(SWIG_FOUND) 47 | include(${SWIG_USE_FILE}) 48 | find_package(Java) 49 | find_package(JNI) 50 | find_package(Ruby) 51 | find_package(PythonInterp) 52 | find_package(PythonLibs) 53 | find_package(R) 54 | find_package(CSharp) 55 | find_package(Mono) 56 | # use $ENV{LUA_DIR} 57 | find_package(Lua51) 58 | find_package(PerlLibs) 59 | find_package(TCL) 60 | find_package(Octave) 61 | 62 | if(JNI_FOUND) 63 | # add_subdirectory(java) 64 | endif() 65 | 66 | if(RUBY_FOUND) 67 | # add_subdirectory(ruby) 68 | endif(RUBY_FOUND) 69 | 70 | if(R_FOUND) 71 | # add_subdirectory(R) 72 | endif(R_FOUND) 73 | 74 | if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND) 75 | add_subdirectory(python) 76 | endif() 77 | 78 | if(CSharp_FOUND OR MONO_FOUND) 79 | # add_subdirectory(csharp) 80 | endif() 81 | 82 | if(LUA51_FOUND) 83 | # add_subdirectory(lua) 84 | endif(LUA51_FOUND) 85 | 86 | if(TCL_FOUND) 87 | # add_subdirectory(tcl) 88 | endif(TCL_FOUND) 89 | 90 | if(PERLLIBS_FOUND) 91 | # add_subdirectory(perl) 92 | endif(PERLLIBS_FOUND) 93 | 94 | if(OCTAVE_FOUND) 95 | # add_subdirectory(octave) 96 | endif(OCTAVE_FOUND) 97 | endif() 98 | 99 | #add_subdirectory(code) 100 | #add_subdirectory(test) 101 | -------------------------------------------------------------------------------- /R/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${R_INCLUDE_DIRS}) 2 | 3 | set(CMAKE_SWIG_FLAGS "") 4 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) 5 | 6 | set(_target ctp-R) 7 | set(WRAPPER_FILES ../ctp.i) 8 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 9 | 10 | swig_add_module(${_target} R ${WRAPPER_FILES}) 11 | swig_link_libraries(${_target} ${R_LIBRARIES} ${CTP_LIBRARIES}) 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ctp-swig 2 | ======== 3 | 4 | swigged ctp library for java, csharp, python, ruby, R, matlab and etc. -------------------------------------------------------------------------------- /cmake/FindCSharp.cmake: -------------------------------------------------------------------------------- 1 | set(CSharp_FOUND FALSE) 2 | 3 | find_program(CSC_v1_EXECUTABLE 4 | NAMES csc 5 | HINTS 6 | [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\.NETFramework;InstallRoot]/v1.1.4322 7 | ) 8 | 9 | find_program(CSC_v2_EXECUTABLE csc 10 | HINTS 11 | [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\.NETFramework;InstallRoot]/v2.0.50727/ 12 | ) 13 | 14 | find_program(CSC_v3_EXECUTABLE csc 15 | HINTS 16 | [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\.NETFramework;InstallRoot]/v3.5/ 17 | ) 18 | 19 | find_program(CSC_v4_EXECUTABLE csc 20 | HINTS 21 | [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\.NETFramework;InstallRoot]/v4.0.30319/ 22 | ) 23 | 24 | if(CSC_v4_EXECUTABLE) 25 | set(CSC_EXECUTABLE ${CSC_v4_EXECUTABLE}) 26 | set(CSharp_FOUND TRUE) 27 | message(STATUS "C# Complier 4.0 found") 28 | elseif(CSC_v3_EXECUTABLE) 29 | set(CSC_EXECUTABLE ${CSC_v3_EXECUTABLE}) 30 | set(CSharp_FOUND TRUE) 31 | message(STATUS "C# Complier 3.0 found") 32 | elseif(CSC_v2_EXECUTABLE) 33 | set(CSC_EXECUTABLE ${CSC_v2_EXECUTABLE}) 34 | set(CSharp_FOUND TRUE) 35 | message(STATUS "C# Complier 2.0 found") 36 | elseif(CSC_v1_EXECUTABLE) 37 | set(CSC_EXECUTABLE ${CSC_v1_EXECUTABLE}) 38 | set(CSharp_FOUND TRUE) 39 | message(STATUS "C# Complier 1.0 found") 40 | elseif() 41 | set(CSharp_FOUND FALSE) 42 | message(STATUS "C# Complier not found") 43 | endif() 44 | 45 | mark_as_advanced(CSC_EXECUTABLE) 46 | 47 | -------------------------------------------------------------------------------- /cmake/FindMaven.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | 3 | if(WIN32) 4 | find_program(MAVEN_EXECUTABLE NAMES mvn.bat) 5 | else() 6 | find_program(MAVEN_EXECUTABLE NAMES mvn) 7 | endif() 8 | 9 | find_package_handle_standard_args(Maven DEFAULT_MSG MAVEN_EXECUTABLE) 10 | mark_as_advanced(MAVEN_EXECUTABLE) 11 | -------------------------------------------------------------------------------- /cmake/FindMono.cmake: -------------------------------------------------------------------------------- 1 | set(MONO_FOUND FALSE) 2 | 3 | find_program(MONO_EXECUTABLE mono) 4 | find_program(MCS_EXECUTABLE mcs) 5 | find_program(GMCS_EXECUTABLE gmcs) 6 | find_program(SMCS_EXECUTABLE smcs) 7 | find_program(GACUTIL_EXECUTABLE gacutil) 8 | find_program(ILASM_EXECUTABLE ilasm) 9 | find_program(SN_EXECUTABLE sn) 10 | 11 | if(MONO_EXECUTABLE AND MCS_EXECUTABLE) 12 | set(MONO_FOUND TRUE) 13 | execute_process(COMMAND ${MONO_EXECUTABLE} --version OUTPUT_VARIABLE MONO_VERSION_OUTPUT OUTPUT_STRIP_TRAILING_WHITESPACE) 14 | string(REGEX MATCH "([0-9]*)([.])([0-9]*)([.]*)([0-9]*)" MONO_VERSION ${MONO_VERSION_OUTPUT}) 15 | endif() 16 | 17 | if(NOT MONO_FOUND) 18 | if(NOT MONO_FIND_QUIETLY AND MONO_FIND_REQUIRED) 19 | message(FATAL_ERROR "MONO was not found. Please specify mono/mcs executable location") 20 | else() 21 | message(STATUS "MONO was not found. Please specify mono/mcs executable location") 22 | endif() 23 | endif() 24 | 25 | set(MONO_USE_FILE ${CMAKE_MODULE_PATH}/UseMono.cmake) 26 | 27 | mark_as_advanced(MONO_EXECUTABLE MCS_EXECUTABLE GMCS_EXECUTABLE SMCS_EXECUTABLE ILASM_EXECUTABLE SN_EXECUTABLE GACUTIL_EXECUTABLE) 28 | -------------------------------------------------------------------------------- /cmake/FindOctave.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Octave 2 | # Once done this will define 3 | # OCTAVE_FOUND - System has octave 4 | # OCTAVE_INCLUDE_DIRS - The octave include directories 5 | # OCTAVE_LIBRARIES - The libraries needed to use octave 6 | 7 | set(OCTAVE_FOUND FALSE) 8 | 9 | execute_process(COMMAND octave-config -p OCTLIBDIR OUTPUT_VARIABLE _LIBDIR OUTPUT_STRIP_TRAILING_WHITESPACE) 10 | execute_process(COMMAND octave-config -p OCTINCLUDEDIR OUTPUT_VARIABLE _INCDIR OUTPUT_STRIP_TRAILING_WHITESPACE) 11 | execute_process(COMMAND octave-config -p VERSION OUTPUT_VARIABLE _version OUTPUT_STRIP_TRAILING_WHITESPACE) 12 | 13 | find_path(OCTAVE_INCLUDE_DIR octave/oct.h PATHS ${_INCDIR} ${_INCDIR}/..) 14 | find_library(OCTAVE_LIBRARY octave PATHS ${_LIBDIR} ) 15 | 16 | if(NOT (OCTAVE_INCLUDE_DIR AND OCTAVE_LIBRARY)) 17 | if(OCTAVE_FIND_REQUIRED) 18 | message(FATAL_ERROR "OCTAVE required, please specify it's location.") 19 | else() 20 | message(STATUS "OCTAVE was not found.") 21 | endif() 22 | elseif(OCTAVE_INCLUDE_DIR AND OCTAVE_LIBRARY) 23 | set(OCTAVE_FOUND TRUE) 24 | endif() 25 | 26 | list(APPEND OCTAVE_INCLUDE_DIRS ${OCTAVE_INCLUDE_DIR}) 27 | list(APPEND OCTAVE_LIBRARIES ${OCTAVE_LIBRARY}) 28 | 29 | include(FindPackageHandleStandardArgs) 30 | find_package_handle_standard_args(liboctave DEFAULT_MSG OCTAVE_INCLUDE_DIRS OCTAVE_LIBRARIES) 31 | mark_as_advanced(OCTAVE_INCLUDE_DIRS OCTAVE_LIBRARIES) 32 | 33 | 34 | -------------------------------------------------------------------------------- /cmake/FindR.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | find_program(R_EXECUTABLE R) 3 | if(R_EXECUTABLE) 4 | execute_process(COMMAND "${R_EXECUTABLE} RHOME" OUTPUT_VARIABLE R_HOME_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) 5 | execute_process(COMMAND "${R_EXECUTABLE} RHOME" OUTPUT_VARIABLE R_HOME_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) 6 | # set(R_HOME ${R_BASE_DIR} CACHE PATH "R home directory obtained from R RHOME") 7 | # mark_as_advanced(R_HOME) 8 | #message(${R_HOME_DIR}) 9 | set(_cmd "${R_EXECUTABLE} --slave -e \"print(Sys.getenv(\\\"R_INfCLUDE_DIR\\\"))\"") 10 | #message(${_cmd}) 11 | execute_process(COMMAND ${_cmd} OUTPUT_VARIABLE _tempstr) 12 | message(STATUS ${_tempstr}) 13 | #[1] "/usr/share/R/include" 14 | # string(REGEX REPLACE "[ ]*(R_LIBS_USER)[ ]*\n\"(.*)\"" "\\2" R_LIBS_USER ${_rlibsuser}) 15 | 16 | # string(LENGTH ${_tempstr} _strlen) 17 | # string(SUBSTRING ${_tempstr} 4 ${_strlen} ${_tempstr}) 18 | # string(STRIP ${_tempstr} ${_tempstr}) 19 | #message(${_strlen}) 20 | set(R_INCLUDE_DIR /usr/share/R/include) 21 | list(APPEND R_INCLUDE_DIRS ${R_INCLUDE_DIR}) 22 | endif(R_EXECUTABLE) 23 | 24 | find_program(RSCRIPT_EXECUTABLE Rscript) 25 | find_library(R_LIBRARIES R PATHS ${R_HOME_DIR} PATH_SUFFIXES lib bin/i386) 26 | mark_as_advanced(R_EXECUTABLE R_INCLUDE_DIRS R_LIBRARIES) 27 | find_package_handle_standard_args(R DEFAULT_MSG R_EXECUTABLE R_INCLUDE_DIRS R_LIBRARIES) 28 | -------------------------------------------------------------------------------- /cmake/UseMono.cmake: -------------------------------------------------------------------------------- 1 | message(STATUS "Using Mono compiler version ${MONO_VERSION}") 2 | -------------------------------------------------------------------------------- /code/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -pthread") 2 | 3 | add_definitions(-DDEBUG_DIRECTOR_OWNED) 4 | add_executable(tCallback Main.cpp Callback.cpp) 5 | add_library(callback Callback.cpp) 6 | include_directories(.) 7 | 8 | find_package(SWIG REQUIRED) 9 | if(SWIG_FOUND) 10 | include(${SWIG_USE_FILE}) 11 | find_package(Java) 12 | find_package(JNI) 13 | find_package(Ruby) 14 | find_package(PythonInterp) 15 | find_package(PythonLibs) 16 | find_package(R) 17 | find_package(CSharp) 18 | find_package(Mono) 19 | # use $ENV{LUA_DIR} 20 | find_package(Lua51) 21 | find_package(PerlLibs) 22 | find_package(TCL) 23 | find_package(Octave) 24 | 25 | if(CSharp_FOUND OR MONO_FOUND) 26 | # add_subdirectory(csharp) 27 | endif() 28 | 29 | if(JNI_FOUND) 30 | # add_subdirectory(java) 31 | endif() 32 | 33 | if(RUBY_FOUND) 34 | # add_subdirectory(ruby) 35 | endif(RUBY_FOUND) 36 | 37 | if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND) 38 | add_subdirectory(python) 39 | endif() 40 | 41 | if(OCTAVE_FOUND) 42 | add_subdirectory(octave) 43 | endif(OCTAVE_FOUND) 44 | 45 | if(R_FOUND) 46 | # add_subdirectory(R) 47 | endif(R_FOUND) 48 | endif() 49 | -------------------------------------------------------------------------------- /code/Callback.cpp: -------------------------------------------------------------------------------- 1 | #include "Callback.h" 2 | -------------------------------------------------------------------------------- /code/Callback.h: -------------------------------------------------------------------------------- 1 | #ifndef _callback_h 2 | #define _callback_h 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class Callback { 9 | public: 10 | virtual ~Callback() {} 11 | virtual void response() = 0; 12 | }; 13 | 14 | class Caller { 15 | public: 16 | Caller(Callback *cb) : callback(cb) {} 17 | void request() { 18 | std::cout << "in c++ lib, request in thread " << std::this_thread::get_id() << std::endl; 19 | std::thread t(&Caller::response, this); 20 | if (t.joinable()) t.join(); 21 | } 22 | 23 | void response() { 24 | std::cout << "in c++ lib, response in thread " << std::this_thread::get_id() << std::endl; 25 | callback->response(); 26 | } 27 | 28 | private: 29 | Callback *callback; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /code/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Callback.h" 2 | 3 | class DCallback : public Callback { 4 | public: 5 | virtual void response() { 6 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 7 | } 8 | }; 9 | 10 | int main(int argc, char *argv[]) { 11 | DCallback cb; 12 | Caller caller(&cb); 13 | caller.request(); 14 | } 15 | -------------------------------------------------------------------------------- /code/R/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${R_INCLUDE_DIRS}) 2 | 3 | set(CMAKE_SWIG_FLAGS "") 4 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) 5 | 6 | set(_target callback-R) 7 | set(WRAPPER_FILES ../callback.i) 8 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 9 | 10 | swig_add_module(${_target} R ${WRAPPER_FILES}) 11 | swig_link_libraries(${_target} ${R_LIBRARIES}) 12 | 13 | set(REXT_DIR /home/alex/R/x86_64-pc-linux-gnu-library/2.15) 14 | -------------------------------------------------------------------------------- /code/callback.i: -------------------------------------------------------------------------------- 1 | %module(directors="1") swigmt 2 | 3 | %{ 4 | #include "Callback.h" 5 | %} 6 | 7 | %feature("director") Callback; 8 | 9 | %include "Callback.h" 10 | -------------------------------------------------------------------------------- /code/csharp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(MONO_FOUND) 2 | include(${MONO_USE_FILE}) 3 | set(CS_COMPLIER ${MCS_EXECUTABLE}) 4 | elseif(CSharp_FOUND) 5 | set(CS_COMPLIER ${CSC_EXECUTABLE}) 6 | endif() 7 | 8 | set(_target callback-cs) 9 | set(SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/src) 10 | set(CMAKE_SWIG_OUTDIR ${SRC_DIR}) 11 | file(MAKE_DIRECTORY ${SRC_DIR}) 12 | 13 | set(_namespace Swigmt) 14 | set(CMAKE_SWIG_FLAGS -namespace ${_namespace} -dllimport ${_target}) 15 | 16 | set(WRAPPER_FILES ../callback.i) 17 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 18 | swig_add_module(${_target} csharp ${WRAPPER_FILES}) 19 | swig_link_libraries(${_target}) 20 | 21 | file(COPY Runme.cs DESTINATION ${CMAKE_SWIG_OUTDIR}) 22 | 23 | set(CS_SOURCES ${CMAKE_SWIG_OUTDIR}/*.cs) 24 | file(TO_NATIVE_PATH ${CS_SOURCES} CS_SOURCES) 25 | 26 | set(BIN_FILE "Runme.exe") 27 | 28 | add_custom_command( 29 | OUTPUT _complie_runme 30 | COMMAND ${CS_COMPLIER} /nologo /platform:x86 /t:exe /out:${BIN_FILE} ${CS_SOURCES} 31 | DEPENDS ${_target} 32 | ) 33 | 34 | add_custom_target(runcs ALL DEPENDS _complie_runme) 35 | -------------------------------------------------------------------------------- /code/csharp/Runme.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | 4 | namespace Swigmt 5 | { 6 | public class DCallback : Callback 7 | { 8 | public override void response() 9 | { 10 | Console.WriteLine("response from c# in thread " + Thread.CurrentThread.ManagedThreadId); 11 | } 12 | } 13 | 14 | public class Runme 15 | { 16 | public static void Main() 17 | { 18 | 19 | Callback callback = new Callback(); 20 | Caller caller = new Caller(callback); 21 | Console.WriteLine("request from c# in thread " + Thread.CurrentThread.ManagedThreadId); 22 | caller.request(); 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /code/java/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${JAVA_INCLUDE_PATH} ${JNI_INCLUDE_DIRS}) 2 | 3 | set(_package_name "swigmt") 4 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/${_package_name}) 5 | set(CMAKE_SWIG_FLAGS "-package" ${_package_name}) 6 | 7 | set(WRAPPER_FILES ../callback.i) 8 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 9 | swig_add_module(callback-java java ${WRAPPER_FILES}) 10 | swig_link_libraries(callback-java) 11 | 12 | set(SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}) 13 | set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/build) 14 | file(MAKE_DIRECTORY ${SOURCE_DIR}) 15 | file(MAKE_DIRECTORY ${BINARY_DIR}) 16 | 17 | get_target_property(_target_location callback-java LOCATION) 18 | get_filename_component(_target_name ${_target_location} NAME) 19 | 20 | file(COPY Runme.java DESTINATION ${CMAKE_SWIG_OUTDIR}) 21 | 22 | set(BIN_FILE "callback.jar") 23 | 24 | add_custom_command(OUTPUT _complie_java 25 | COMMAND ${Java_JAVAC_EXECUTABLE} -d ${BINARY_DIR} ${CMAKE_SWIG_OUTDIR}/*.java 26 | COMMAND ${Java_JAR_EXECUTABLE} cf ${CMAKE_CURRENT_BINARY_DIR}/${BIN_FILE} -C ${BINARY_DIR} swigmt 27 | COMMAND ${Java_JAR_EXECUTABLE} uf ${CMAKE_CURRENT_BINARY_DIR}/${BIN_FILE} ${_target_name} 28 | # COMMAND ${Java_JAVADOC_EXECUTABLE} -quiet -d ${BINARY_DIR}/javadoc -sourcepath ${SOURCE_DIR} ${_package_name} 29 | # COMMAND ${Java_JAR_EXECUTABLE} cf ${CMAKE_CURRENT_BINARY_DIR}/${DOC_FILE} -C ${BINARY_DIR}/javadoc ${_package_top_dir} 30 | # COMMAND ${Java_JAR_EXECUTABLE} cf ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${_package_top_dir} 31 | DEPENDS callback-java 32 | ) 33 | 34 | add_custom_target(runjava ALL DEPENDS _complie_java) 35 | -------------------------------------------------------------------------------- /code/java/Runme.java: -------------------------------------------------------------------------------- 1 | package swigmt; 2 | 3 | import java.lang.System; 4 | import java.io.*; 5 | 6 | public class Runme extends Callback { 7 | static private void loadLib(final String name) throws IOException { 8 | String prefix = ""; 9 | String suffix = ""; 10 | String osName = System.getProperty("os.name"); 11 | if (osName.equals("Linux")) { 12 | prefix = "lib"; 13 | suffix = ".so"; 14 | } else if (osName.substring(0, 7).equals("Windows")) { 15 | suffix = ".dll"; 16 | } 17 | InputStream in = Runme.class.getResource("/" + prefix + name + suffix).openStream(); 18 | File lib = File.createTempFile(name, suffix); 19 | FileOutputStream out = new FileOutputStream(lib); 20 | int i; 21 | byte[] buf = new byte[1024]; 22 | while ((i = in.read(buf)) != -1) { 23 | out.write(buf, 0, i); 24 | } 25 | in.close(); 26 | out.close(); 27 | lib.deleteOnExit(); 28 | System.load(lib.toString()); 29 | } 30 | 31 | static { 32 | try { 33 | loadLib("callback-java"); 34 | } catch (Exception e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | 39 | public void response() { 40 | System.out.println("response from java thread" + Thread.currentThread().toString()); 41 | } 42 | 43 | public static void main(String[] args) { 44 | Callback cb = new Runme(); 45 | Caller caller = new Caller(cb); 46 | System.out.println("request from java thread" + Thread.currentThread().toString()); 47 | caller.request(); 48 | } 49 | } -------------------------------------------------------------------------------- /code/octave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${OCTAVE_INCLUDE_DIRS}) 2 | 3 | set(CMAKE_SWIG_FLAGS "-Wall") 4 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) 5 | 6 | set(_target callback-octave) 7 | set(WRAPPER_FILES ../callback.i) 8 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 9 | 10 | swig_add_module(${_target} octave ${WRAPPER_FILES}) 11 | swig_link_libraries(${_target} ${OCTAVE_LIBRARIES}) 12 | 13 | set_target_properties(${SWIG_MODULE_${_target}_REAL_NAME} PROPERTIES OUTPUT_NAME "callback") 14 | set_target_properties(${SWIG_MODULE_${_target}_REAL_NAME} PROPERTIES SUFFIX ".oct" PREFIX "") 15 | 16 | execute_process(COMMAND octave-config --oct-site-dir OUTPUT_VARIABLE _oct_site_dir OUTPUT_STRIP_TRAILING_WHITESPACE) 17 | 18 | install(TARGETS ${SWIG_MODULE_${_target}_REAL_NAME} DESTINATION ${_oct_site_dir}) 19 | -------------------------------------------------------------------------------- /code/octave/runme.m: -------------------------------------------------------------------------------- 1 | callback 2 | 3 | DCallback=@() subclass(example.Callback(), 'response',@(self) printf("response from octave.\n")); 4 | callback = DCallback().__disown(); 5 | caller = example.Caller(callback); 6 | caller.request(); 7 | 8 | -------------------------------------------------------------------------------- /code/python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${PYTHON_INCLUDE_DIRS}) 2 | set(CMAKE_SWIG_FLAGS -features autodoc=1) 3 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) 4 | 5 | set(_target swigmt) 6 | set(WRAPPER_FILES ../callback.i) 7 | 8 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 9 | swig_add_module(${_target} python ${WRAPPER_FILES}) 10 | swig_link_libraries(${_target} ${PYTHON_LIBRARIES}) 11 | set_target_properties(${SWIG_MODULE_${_target}_REAL_NAME} PROPERTIES OUTPUT_NAME "_swigmt") 12 | 13 | execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_path('platlib'))" 14 | OUTPUT_VARIABLE _py_site_package_dir OUTPUT_STRIP_TRAILING_WHITESPACE) 15 | install(TARGETS ${SWIG_MODULE_${_target}_REAL_NAME} DESTINATION ${_py_site_package_dir}) 16 | install(FILES ${CMAKE_SWIG_OUTDIR}/swigmt.py DESTINATION ${_py_site_package_dir}) 17 | 18 | file(COPY runme.py DESTINATION ${CMAKE_SWIG_OUTDIR}) 19 | -------------------------------------------------------------------------------- /code/python/runme.py: -------------------------------------------------------------------------------- 1 | from swigmt import *; 2 | import threading; 3 | 4 | class DCallback(Callback): 5 | def __init__(self): 6 | Callback.__init__(self) 7 | 8 | def response(self): 9 | print("response from python in thread " + threading.current_thread().getName()) 10 | 11 | cb = DCallback() 12 | caller = Caller(cb) 13 | print("request from python in thread " + threading.current_thread().getName()) 14 | caller.request() 15 | -------------------------------------------------------------------------------- /code/ruby/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${RUBY_INCLUDE_DIRS}) 2 | set(CMAKE_SWIG_FLAGS -autorename) 3 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) 4 | 5 | set(_target callback-ruby) 6 | set(WRAPPER_FILES ../callback.i) 7 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 8 | swig_add_module(${_target} ruby ${WRAPPER_FILES}) 9 | swig_link_libraries(${_target} ${RUBY_LIBRARY} ${CTP_LIBRARIES}) 10 | set_target_properties(${_target} PROPERTIES PREFIX "" SUFFIX ".so") 11 | set_target_properties(${_target} PROPERTIES OUTPUT_NAME "swigmt") 12 | 13 | execute_process(COMMAND ${RUBY_EXECUTABLE} -e "print RbConfig::CONFIG['sitearchdir']" OUTPUT_VARIABLE _ruby_site_dir) 14 | install(TARGETS ${_target} DESTINATION ${_ruby_site_dir}) 15 | 16 | #file(TO_NATIVE_PATH ${CMAKE_SWIG_OUTDIR} CMAKE_SWIG_OUTDIR) 17 | #file(COPY runme.rb DESTINATION ${CMAKE_SWIG_OUTDIR}) 18 | -------------------------------------------------------------------------------- /code/ruby/runme.rb: -------------------------------------------------------------------------------- 1 | require 'thread' 2 | require 'swigmt' 3 | 4 | include Swigmt 5 | 6 | class DCallback < Callback 7 | def response 8 | puts "response from ruby in another thread " + Thread.current.to_s 9 | end 10 | end 11 | 12 | cb = DCallback.new 13 | caller = Caller.new(cb) 14 | puts "request in ruby, in thread " + Thread.current.to_s 15 | caller.request -------------------------------------------------------------------------------- /csharp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(MONO_FOUND) 2 | include(${MONO_USE_FILE}) 3 | set(CS_COMPLIER ${MCS_EXECUTABLE}) 4 | elseif(CSharp_FOUND) 5 | set(CS_COMPLIER ${CSC_EXECUTABLE}) 6 | endif() 7 | 8 | set(_target ctp-cs) 9 | set(SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/src CACHE INTERNAL "") 10 | set(BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE INTERNAL "") 11 | file(MAKE_DIRECTORY ${SRC_DIR}) 12 | file(MAKE_DIRECTORY ${BIN_DIR}) 13 | set(CMAKE_SWIG_OUTDIR ${SRC_DIR}) 14 | 15 | set(_namespace FreeQuant.Ctp) 16 | set(CMAKE_SWIG_FLAGS "-namespace" ${_namespace}) 17 | 18 | set(WRAPPER_FILES ../ctp.i) 19 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 20 | swig_add_module(${_target} csharp ${WRAPPER_FILES}) 21 | swig_link_libraries(${_target} ${CTP_LIBRARIES}) 22 | 23 | set(CS_SOURCES ${CMAKE_SWIG_OUTDIR}/*.cs) 24 | set(BIN_FILE "ctp.dll") 25 | 26 | add_custom_command(OUTPUT _ctp_cs_dll 27 | COMMENT "Creating cs dll..." 28 | COMMAND ${CS_COMPLIER} /nologo /target:library /out:${BIN_DIR}/${BIN_FILE} ${CS_SOURCES} 29 | DEPENDS ${_target} 30 | ) 31 | 32 | add_custom_target(do_ctp_cs_dll ALL DEPENDS _ctp_cs_dll) 33 | -------------------------------------------------------------------------------- /ctp.i: -------------------------------------------------------------------------------- 1 | #if defined(SWIGPYTHON) || defined(SWIGRUBY) 2 | %module(directors="1") ctp 3 | #else 4 | %module(directors="1") Ctp 5 | #endif 6 | 7 | %include "typemaps.i" 8 | 9 | %{ 10 | #ifdef SWIGPYTHON 11 | #define SWIG_FILE_WITH_INIT 12 | #endif 13 | 14 | #include "ThostFtdcUserApiDataType.h" 15 | #include "ThostFtdcUserApiStruct.h" 16 | #include "ThostFtdcTraderApi.h" 17 | #include "ThostFtdcMdApi.h" 18 | %} 19 | 20 | /* These symbols are NEVER used in original files */ 21 | %ignore TThostFtdcVirementTradeCodeType; 22 | %ignore THOST_FTDC_VTC_BankBankToFuture; 23 | %ignore THOST_FTDC_VTC_BankFutureToBank; 24 | %ignore THOST_FTDC_VTC_FutureBankToFuture; 25 | %ignore THOST_FTDC_VTC_FutureFutureToBank; 26 | 27 | %ignore TThostFtdcFBTTradeCodeEnumType; 28 | %ignore THOST_FTDC_FTC_BankLaunchBankToBroker; 29 | %ignore THOST_FTDC_FTC_BrokerLaunchBankToBroker; 30 | %ignore THOST_FTDC_FTC_BankLaunchBrokerToBank; 31 | %ignore THOST_FTDC_FTC_BrokerLaunchBrokerToBank; 32 | 33 | #ifdef SWIGJAVA 34 | %rename(ThostTeResumeType) THOST_TE_RESUME_TYPE; 35 | %rename("%(lowercamelcase)s", %$isfunction) ""; 36 | %include "various.i" 37 | %apply char **STRING_ARRAY { char *ppInstrumentID[] }; 38 | 39 | %javaconst(1); 40 | 41 | #endif 42 | 43 | #ifdef SWIGCSHARP 44 | %include "arrays_csharp.i" 45 | %rename(ThostTeResumeType) THOST_TE_RESUME_TYPE; 46 | %csconst(1); 47 | CSHARP_ARRAYS(char *, string) 48 | %typemap(imtype, inattributes="[In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0, ArraySubType=UnmanagedType.LPStr)]") char *INPUT[] "string[]" 49 | %apply char *INPUT[] { char *ppInstrumentID[] }; 50 | #endif 51 | 52 | #ifdef SWIGRUBY 53 | %include "ruby/char_array.i" 54 | %apply (char **ARRAY, int SIZE) { (char *ppInstrumentID[], int nCount) }; 55 | #endif 56 | 57 | #ifdef SWIGPYTHON 58 | %include "python/char_array.i" 59 | %apply (char **ARRAY, int SIZE) { (char *ppInstrumentID[], int nCount) }; 60 | #endif 61 | 62 | %include "ThostFtdcUserApiDataType.h" 63 | %include "ThostFtdcUserApiStruct.h" 64 | 65 | 66 | %feature("director") CThostFtdcMdSpi; 67 | %include "ThostFtdcMdApi.h" 68 | 69 | 70 | %feature("director") CThostFtdcTraderSpi; 71 | %include "ThostFtdcTraderApi.h" 72 | 73 | -------------------------------------------------------------------------------- /ctp/api/risk/changelog.txt: -------------------------------------------------------------------------------- 1 | current version: v5.5.2 -------------------------------------------------------------------------------- /ctp/api/risk/lib/riskuserapi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/risk/lib/riskuserapi.dll -------------------------------------------------------------------------------- /ctp/api/risk/lib/riskuserapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/risk/lib/riskuserapi.lib -------------------------------------------------------------------------------- /ctp/api/risk/public/FtdcRiskUserApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/risk/public/FtdcRiskUserApi.h -------------------------------------------------------------------------------- /ctp/api/risk/public/FtdcRiskUserApiDataType.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/risk/public/FtdcRiskUserApiDataType.h -------------------------------------------------------------------------------- /ctp/api/risk/public/FtdcRiskUserApiStruct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/risk/public/FtdcRiskUserApiStruct.h -------------------------------------------------------------------------------- /ctp/api/trade/changelog.txt: -------------------------------------------------------------------------------- 1 | current version: 20120530 2 | -------------------------------------------------------------------------------- /ctp/api/trade/linux32/lib/error.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /ctp/api/trade/linux32/lib/error.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux32/lib/error.xml -------------------------------------------------------------------------------- /ctp/api/trade/linux32/lib/libthostmduserapi.so: -------------------------------------------------------------------------------- 1 | /home/alex/ctp-swig/ctp/api/trade/linux32/lib/thostmduserapi.so -------------------------------------------------------------------------------- /ctp/api/trade/linux32/lib/libthosttraderapi.so: -------------------------------------------------------------------------------- 1 | /home/alex/ctp-swig/ctp/api/trade/linux32/lib/thosttraderapi.so -------------------------------------------------------------------------------- /ctp/api/trade/linux32/lib/thostmduserapi.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux32/lib/thostmduserapi.so -------------------------------------------------------------------------------- /ctp/api/trade/linux32/lib/thosttraderapi.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux32/lib/thosttraderapi.so -------------------------------------------------------------------------------- /ctp/api/trade/linux32/public/ThostFtdcMdApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux32/public/ThostFtdcMdApi.h -------------------------------------------------------------------------------- /ctp/api/trade/linux32/public/ThostFtdcTraderApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux32/public/ThostFtdcTraderApi.h -------------------------------------------------------------------------------- /ctp/api/trade/linux32/public/ThostFtdcUserApiDataType.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux32/public/ThostFtdcUserApiDataType.h -------------------------------------------------------------------------------- /ctp/api/trade/linux32/public/ThostFtdcUserApiStruct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux32/public/ThostFtdcUserApiStruct.h -------------------------------------------------------------------------------- /ctp/api/trade/linux64/lib/error.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /ctp/api/trade/linux64/lib/error.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux64/lib/error.xml -------------------------------------------------------------------------------- /ctp/api/trade/linux64/lib/libthostmduserapi.so: -------------------------------------------------------------------------------- 1 | /home/alex/ctp-swig/ctp/api/trade/linux64/lib/thostmduserapi.so -------------------------------------------------------------------------------- /ctp/api/trade/linux64/lib/libthosttraderapi.so: -------------------------------------------------------------------------------- 1 | /home/alex/ctp-swig/ctp/api/trade/linux64/lib/thosttraderapi.so -------------------------------------------------------------------------------- /ctp/api/trade/linux64/lib/thostmduserapi.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux64/lib/thostmduserapi.so -------------------------------------------------------------------------------- /ctp/api/trade/linux64/lib/thosttraderapi.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux64/lib/thosttraderapi.so -------------------------------------------------------------------------------- /ctp/api/trade/linux64/public/ThostFtdcMdApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux64/public/ThostFtdcMdApi.h -------------------------------------------------------------------------------- /ctp/api/trade/linux64/public/ThostFtdcTraderApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux64/public/ThostFtdcTraderApi.h -------------------------------------------------------------------------------- /ctp/api/trade/linux64/public/ThostFtdcUserApiDataType.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux64/public/ThostFtdcUserApiDataType.h -------------------------------------------------------------------------------- /ctp/api/trade/linux64/public/ThostFtdcUserApiStruct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/linux64/public/ThostFtdcUserApiStruct.h -------------------------------------------------------------------------------- /ctp/api/trade/win/lib/error.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /ctp/api/trade/win/lib/error.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/win/lib/error.xml -------------------------------------------------------------------------------- /ctp/api/trade/win/lib/thostmduserapi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/win/lib/thostmduserapi.dll -------------------------------------------------------------------------------- /ctp/api/trade/win/lib/thostmduserapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/win/lib/thostmduserapi.lib -------------------------------------------------------------------------------- /ctp/api/trade/win/lib/thosttraderapi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/win/lib/thosttraderapi.dll -------------------------------------------------------------------------------- /ctp/api/trade/win/lib/thosttraderapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/win/lib/thosttraderapi.lib -------------------------------------------------------------------------------- /ctp/api/trade/win/public/ThostFtdcMdApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/win/public/ThostFtdcMdApi.h -------------------------------------------------------------------------------- /ctp/api/trade/win/public/ThostFtdcTraderApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/win/public/ThostFtdcTraderApi.h -------------------------------------------------------------------------------- /ctp/api/trade/win/public/ThostFtdcUserApiDataType.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/win/public/ThostFtdcUserApiDataType.h -------------------------------------------------------------------------------- /ctp/api/trade/win/public/ThostFtdcUserApiStruct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/api/trade/win/public/ThostFtdcUserApiStruct.h -------------------------------------------------------------------------------- /ctp/demo/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/ctp/demo/CMakeLists.txt -------------------------------------------------------------------------------- /java/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${JAVA_INCLUDE_PATH} ${JNI_INCLUDE_DIRS}) 2 | set(_package_name "org.freequant.ctp") 3 | string(REPLACE "." "/" _package_dir ${_package_name}) 4 | set(_package_top_dir "org") 5 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/${_package_dir}) 6 | set(CMAKE_SWIG_FLAGS "-package" ${_package_name}) 7 | set(WRAPPER_FILES ../ctp.i) 8 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 9 | swig_add_module(ctp java ${WRAPPER_FILES}) 10 | swig_link_libraries(ctp ${CTP_LIBRARIES}) 11 | 12 | set(SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}) 13 | set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/build) 14 | file(MAKE_DIRECTORY ${SOURCE_DIR}) 15 | file(MAKE_DIRECTORY ${BINARY_DIR}) 16 | 17 | set(JAVA_SOURCES ${CMAKE_SWIG_OUTDIR}/*.java) 18 | set(BIN_FILE "ctp.jar") 19 | set(DOC_FILE "ctp-doc.jar") 20 | set(SRC_FILE "ctp-src.jar") 21 | 22 | #foreach(_file ${CTP_SHAREDLIBFILES}) 23 | # file(COPY ${_file} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 24 | # get_filename_component(_rfile ${_file} NAME) 25 | # list(APPEND _ctpfiles ${_rfile}) 26 | #endforeach() 27 | get_target_property(_target_location ctp LOCATION) 28 | get_filename_component(_target_name ${_target_location} NAME) 29 | 30 | file(COPY Runmd.java DESTINATION ${CMAKE_SWIG_OUTDIR}) 31 | 32 | add_custom_command(OUTPUT _build_jar 33 | COMMENT "Creating jar file..." 34 | COMMAND ${Java_JAVAC_EXECUTABLE} -d ${BINARY_DIR} ${JAVA_SOURCES} 35 | COMMAND ${Java_JAR_EXECUTABLE} cf ${CMAKE_CURRENT_BINARY_DIR}/${BIN_FILE} -C ${BINARY_DIR} ${_package_top_dir} 36 | COMMAND ${Java_JAR_EXECUTABLE} uf ${CMAKE_CURRENT_BINARY_DIR}/${BIN_FILE} ${_ctpfiles} ${_target_name} 37 | # COMMAND ${Java_JAVADOC_EXECUTABLE} -quiet -d ${BINARY_DIR}/javadoc -sourcepath ${SOURCE_DIR} ${_package_name} 38 | # COMMAND ${Java_JAR_EXECUTABLE} cf ${CMAKE_CURRENT_BINARY_DIR}/${DOC_FILE} -C ${BINARY_DIR}/javadoc ${_package_top_dir} 39 | COMMAND ${Java_JAR_EXECUTABLE} cf ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${_package_top_dir} 40 | DEPENDS ctp 41 | ) 42 | 43 | add_custom_target(run_build_jar ALL DEPENDS _build_jar) 44 | -------------------------------------------------------------------------------- /java/Runmd.java: -------------------------------------------------------------------------------- 1 | package org.freequant.ctp; 2 | 3 | import java.lang.System; 4 | import java.io.*; 5 | 6 | public class Runmd extends CThostFtdcMdSpi { 7 | static private void loadLib(final String name) throws IOException { 8 | String prefix = ""; 9 | String suffix = ""; 10 | String osName = System.getProperty("os.name"); 11 | if (osName.equals("Linux")) { 12 | prefix = "lib"; 13 | suffix = ".so"; 14 | } else if (osName.substring(0, 7).equals("Windows")) { 15 | suffix = ".dll"; 16 | } 17 | InputStream in = Runmd.class.getResource("/" + prefix + name + suffix).openStream(); 18 | File lib = File.createTempFile(name, suffix); 19 | FileOutputStream out = new FileOutputStream(lib); 20 | int i; 21 | byte[] buf = new byte[1024]; 22 | while ((i = in.read(buf)) != -1) { 23 | out.write(buf, 0, i); 24 | } 25 | in.close(); 26 | out.close(); 27 | lib.deleteOnExit(); 28 | System.load(lib.toString()); 29 | } 30 | 31 | static { 32 | try { 33 | loadLib("ctp"); 34 | } catch (Exception e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | 39 | private CThostFtdcMdApi api; 40 | String front; 41 | String brokerId; 42 | String userId; 43 | String password ; 44 | public Runmd(String front, String brokerId, String userId, String password) { 45 | this.front = front; 46 | this.brokerId = brokerId; 47 | this.userId = userId; 48 | this.password = password; 49 | api = CThostFtdcMdApi.createFtdcMdApi(""); 50 | api.registerSpi(this); 51 | api.registerFront(front); 52 | api.init(); 53 | } 54 | 55 | public void release() { 56 | api.release(); 57 | } 58 | 59 | public void join() { 60 | api.join(); 61 | } 62 | 63 | public void OnFrontConnected() { 64 | System.out.println("OnFrontConnected"); 65 | } 66 | 67 | public static void main(String[] args) { 68 | String front = "tcp://asp-sim2-front1.financial-trading-platform.com:26213"; 69 | String broker = "2030"; 70 | String user = "352240"; 71 | String password = "888888"; 72 | Runmd spi = new Runmd(front, broker, user, password); 73 | spi.release(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /lua/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${LUA_INCLUDE_DIR}) 2 | 3 | set(CMAKE_SWIG_FLAGS "") 4 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) 5 | 6 | set(_target ctp-lua) 7 | set(WRAPPER_FILES ../ctp.i) 8 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 9 | swig_add_module(${_target} lua ${WRAPPER_FILES}) 10 | swig_link_libraries(${_target} ${LUA_LIBRARIES} ${CTP_LIBRARIES}) 11 | set_target_properties(${_target} PROPERTIES OUTPUT_NAME "ctp") 12 | -------------------------------------------------------------------------------- /lua/pex.cpp: -------------------------------------------------------------------------------- 1 | #include "pex.h" 2 | -------------------------------------------------------------------------------- /lua/pex.h: -------------------------------------------------------------------------------- 1 | #define PP '2' 2 | #define ER 1 3 | 4 | typedef char Thost[22]; 5 | struct Ddd { 6 | Thost thost; 7 | }; 8 | 9 | //class Shape { 10 | //public: 11 | // Shape() { 12 | // nshapes++; 13 | // } 14 | // virtual ~Shape() { 15 | // nshapes--; 16 | // }; 17 | // static int nshapes; 18 | //}; 19 | -------------------------------------------------------------------------------- /lua/pex.i: -------------------------------------------------------------------------------- 1 | %module pex 2 | 3 | %{ 4 | #define SWIG_FILE_WITH_INIT 5 | #include "pex.h" 6 | %} 7 | 8 | %include "pex.h" 9 | -------------------------------------------------------------------------------- /octave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${OCTAVE_INCLUDE_DIRS}) 2 | 3 | set(CMAKE_SWIG_FLAGS "") 4 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) 5 | 6 | set(_target ctp-octave) 7 | set(WRAPPER_FILES ../ctp.i) 8 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 9 | 10 | swig_add_module(${_target} octave ${WRAPPER_FILES}) 11 | swig_link_libraries(${_target} ${OCTAVE_LIBRARIES} ${CTP_LIBRARIES}) 12 | -------------------------------------------------------------------------------- /perl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${PERL_INCLUDE_PATH}) 2 | 3 | set(CMAKE_SWIG_FLAGS "") 4 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) 5 | 6 | set(_target ctp-perl) 7 | set(WRAPPER_FILES ../ctp.i) 8 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 9 | 10 | swig_add_module(${_target} perl ${WRAPPER_FILES}) 11 | swig_link_libraries(${_target} ${PERL_LIBRARIES} ${CTP_LIBRARIES}) 12 | -------------------------------------------------------------------------------- /pex.cpp: -------------------------------------------------------------------------------- 1 | #include "pex.h" 2 | -------------------------------------------------------------------------------- /pex.h: -------------------------------------------------------------------------------- 1 | #define PP '2' 2 | #define ER 1 3 | struct Ddd { 4 | char Thost[22] thost; 5 | } 6 | 7 | class Shape { 8 | public: 9 | Shape() { 10 | nshapes++; 11 | } 12 | virtual ~Shape() { 13 | nshapes--; 14 | }; 15 | static int nshapes; 16 | }; 17 | -------------------------------------------------------------------------------- /python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${PYTHON_INCLUDE_DIRS}) 2 | set(CMAKE_SWIG_FLAGS -features autodoc=1 -threads) 3 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/install) 4 | 5 | set(_target ctp-python) 6 | set(WRAPPER_FILES ../ctp.i) 7 | 8 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 9 | swig_add_module(${_target} python ${WRAPPER_FILES}) 10 | swig_link_libraries(${_target} ${PYTHON_LIBRARIES} ${CTP_LIBRARIES}) 11 | set_target_properties(${SWIG_MODULE_${_target}_REAL_NAME} PROPERTIES OUTPUT_NAME "_ctp" 12 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/install) 13 | 14 | file(COPY ${CTP_SHAREDLIBFILES} DESTINATION ${CMAKE_SWIG_OUTDIR}) 15 | file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/install DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 16 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/install) 17 | file(COPY ${CTP_SHAREDLIBFILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/install) 18 | 19 | execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_path('platlib'))" 20 | OUTPUT_VARIABLE _py_site_package_dir OUTPUT_STRIP_TRAILING_WHITESPACE) 21 | install(TARGETS ${SWIG_MODULE_${_target}_REAL_NAME} DESTINATION ${_py_site_package_dir}) 22 | install(FILES ${swig_generated_sources} DESTINATION ${_py_site_package_dir}) 23 | -------------------------------------------------------------------------------- /python/char_array.i: -------------------------------------------------------------------------------- 1 | %typemap(in) (char **ARRAY, int SIZE) { 2 | if (PyList_Check($input)) { 3 | int i = 0; 4 | $2 = PyList_Size($input); 5 | $1 = (char **)malloc(($2+1)*sizeof(char *)); 6 | for (; i < $2; i++) { 7 | PyObject *o = PyList_GetItem($input,i); 8 | if (PyString_Check(o)) 9 | $1[i] = PyString_AsString(PyList_GetItem($input,i)); 10 | else { 11 | PyErr_SetString(PyExc_TypeError,"list must contain strings"); 12 | free($1); 13 | return NULL; 14 | } 15 | } 16 | $1[i] = 0; 17 | } else { 18 | PyErr_SetString(PyExc_TypeError, "not a list"); 19 | return NULL; 20 | } 21 | } 22 | 23 | %typemap(freearg) (char **ARRAY, int SIZE) { 24 | free((char *)$1); 25 | } 26 | -------------------------------------------------------------------------------- /python/examples/md.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | #from ctp import CThostFtdcMdSpi 5 | 6 | import time, multiprocessing, signal, threading, thread 7 | import weakref 8 | 9 | # from ctp import * 10 | # import threading 11 | # 12 | # class MdSpi(CThostFtdcMdSpi): 13 | # request_id = 0 14 | # def __init__(self, front, broker_id, user_id, password): 15 | # CThostFtdcMdSpi.__init__(self) 16 | # 17 | # self.front = front 18 | # self.broker_id = broker_id 19 | # self.user_id = user_id 20 | # self.password = password 21 | # 22 | # self.api = CThostFtdcMdApi_CreateFtdcMdApi("") 23 | # self.api.RegisterSpi(self) 24 | # self.api.RegisterFront(front) 25 | # self.api.Init() 26 | # print(threading.current_thread()) 27 | # # self.api.RegisterFront("protocal=tcp;host=asp-sim2-front1.financial-trading-platform.com;port=26213;userid=352240;password=888888;brokerid=2030"); 28 | # return 29 | # def join(self): 30 | # self.api.Join() 31 | # 32 | # 33 | # def OnFrontConnected(self): 34 | # print("FrontConnected") 35 | # print(threading.current_thread()) 36 | # 37 | # field = CThostFtdcReqUserLoginField(); 38 | # field.BrokerID = "2030" 39 | # field.UserID = "352240" 40 | # field.Password = "888888" 41 | # request_id += 1 42 | # self.api.ReqUserLogin(field, request_id) 43 | # return 44 | # 45 | # def OnRspUserLogin(self, *args): 46 | # print("OnRspUserLogin") 47 | # return 48 | # 49 | # def OnRspError(self, *args): 50 | # return 51 | # 52 | # def OnRspSubMarketData(self, *args): 53 | # return 54 | # 55 | # def OnRtnDepthMarketData(self, *args): 56 | # return 57 | # 58 | # def __del__(self): 59 | # self.api.RegisterSpi(None) 60 | # self.api.Release() 61 | # return 62 | # 63 | # front = "tcp://asp-sim2-front1.financial-trading-platform.com:26213" 64 | # broker = "2030" 65 | # user = "352240" 66 | # password = "888888" 67 | import sys 68 | import signal 69 | 70 | class Master: 71 | def __index__(self): 72 | signal.signal(signal.SIGINT, self.handle_signal); 73 | return 74 | 75 | def run(self): 76 | while True: 77 | time.sleep(1) 78 | 79 | return 80 | 81 | def handle_signal(self): 82 | print("exit") 83 | sys.exit(0); 84 | 85 | 86 | def main(): 87 | print(1) 88 | # master = Master(); 89 | # master.run(); 90 | 91 | # signal.signal(signal.SIGTSTP, lambda ) 92 | signal.pause() 93 | # spi = MdSpi(); 94 | # spi.Init() 95 | # spi.Join() 96 | 97 | # spi = MdSpi(front, broker, user, password) 98 | # spi.join() 99 | return 100 | 101 | 102 | if __name__ == "__main__": 103 | main() 104 | -------------------------------------------------------------------------------- /python/install/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javagg/ctp-swig/eafe69f8cbb8c2d42cf6b81e89f9e42a010d6b56/python/install/__init__.py -------------------------------------------------------------------------------- /python/install/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup 4 | from distutils.extension import Extension 5 | 6 | setup(name='ctp', 7 | version='1.0', 8 | package_dir={'ctp': ''}, 9 | packages=['ctp'], 10 | package_data={'ctp': ['_ctp.so', 'libthostmduserapi.so', 'libthosttraderapi.so']}, 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /python/runmd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | #from ctp import CThostFtdcMdSpi 4 | 5 | from ctp import * 6 | import threading 7 | 8 | def runme(): 9 | # spi = MdSpi(); 10 | # spi.Init() 11 | # spi.Join() 12 | return 13 | 14 | class MdSpi(CThostFtdcMdSpi): 15 | request_id = 0 16 | def __init__(self, front, broker_id, user_id, password): 17 | CThostFtdcMdSpi.__init__(self) 18 | 19 | self.front = front 20 | self.broker_id = broker_id 21 | self.user_id = user_id 22 | self.password = password 23 | 24 | self.api = CThostFtdcMdApi_CreateFtdcMdApi("") 25 | self.api.RegisterSpi(self) 26 | self.api.RegisterFront(front) 27 | self.api.Init() 28 | print(threading.current_thread()) 29 | # self.api.RegisterFront("protocal=tcp;host=asp-sim2-front1.financial-trading-platform.com;port=26213;userid=352240;password=888888;brokerid=2030"); 30 | return 31 | def join(self): 32 | self.api.Join() 33 | 34 | 35 | def OnFrontConnected(self): 36 | print("FrontConnected") 37 | print(threading.current_thread()) 38 | 39 | field = CThostFtdcReqUserLoginField(); 40 | field.BrokerID = "2030" 41 | field.UserID = "352240" 42 | field.Password = "888888" 43 | request_id += 1 44 | self.api.ReqUserLogin(field, request_id) 45 | return 46 | 47 | def OnRspUserLogin(self, *args): 48 | print("OnRspUserLogin") 49 | return 50 | 51 | def OnRspError(self, *args): 52 | return 53 | 54 | def OnRspSubMarketData(self, *args): 55 | return 56 | 57 | def OnRtnDepthMarketData(self, *args): 58 | return 59 | 60 | def __del__(self): 61 | self.api.RegisterSpi(None) 62 | self.api.Release() 63 | return 64 | 65 | front = "tcp://asp-sim2-front1.financial-trading-platform.com:26213" 66 | broker = "2030" 67 | user = "352240" 68 | password = "888888" 69 | 70 | spi = MdSpi(front, broker, user, password) 71 | spi.join() -------------------------------------------------------------------------------- /python/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup, Extension 4 | 5 | ctp_module = Extension('_ctp', sources=['ctpPYTHON_wrap.cxx'], 6 | 7 | setup(name='ctp', version='1.0', author='Alex Lee', url='http://www.freequant.org', packages=['ctp']) 8 | -------------------------------------------------------------------------------- /ruby/.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /ruby/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 1356960103123 132 | 1356960103123 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 162 | 163 | 174 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | -------------------------------------------------------------------------------- /ruby/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${RUBY_INCLUDE_DIRS}) 2 | set(CMAKE_SWIG_FLAGS -autorename) 3 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) 4 | 5 | set(_target ctp-ruby) 6 | set(WRAPPER_FILES ../ctp.i) 7 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 8 | swig_add_module(${_target} ruby ${WRAPPER_FILES}) 9 | swig_link_libraries(${_target} ${RUBY_LIBRARY} ${CTP_LIBRARIES}) 10 | set_target_properties(${_target} PROPERTIES PREFIX "" SUFFIX ".so") 11 | set_target_properties(${_target} PROPERTIES OUTPUT_NAME "ctp") 12 | 13 | execute_process(COMMAND ${RUBY_EXECUTABLE} -e "print RbConfig::CONFIG['sitearchdir']" OUTPUT_VARIABLE _ruby_site_dir) 14 | install(TARGETS ${_target} DESTINATION ${_ruby_site_dir}) 15 | 16 | add_custom_command( 17 | OUTPUT runmd.rb 18 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/runmd.rb ${CMAKE_CURRENT_BINARY_DIR}/runmd.rb 19 | DEPENDS ${_target}) 20 | add_custom_target(run ALL DEPENDS runmd.rb) 21 | 22 | #find_program(GEM_EXECUTABLE gem) 23 | #if(GEM_EXECUTABLE) 24 | # add_custom_command( 25 | # OUTPUT _make_and_install_gem 26 | # COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/ctp.gemspec ${CMAKE_CURRENT_BINARY_DIR}/ctp.gemspec 27 | ## COMMAND ${GEM_EXECUTABLE} build ${CMAKE_CURRENT_BINARY_DIR}/ctp.gemspec 28 | ## COMMAND ${GEM_EXECUTABLE} install ctp-0.0.1-x86_64-linux.gem 29 | # DEPENDS ${_target} 30 | # ) 31 | #endif() 32 | 33 | #add_custom_target(run ALL DEPENDS runmd.rb _make_and_install_gem) 34 | -------------------------------------------------------------------------------- /ruby/char_array.i: -------------------------------------------------------------------------------- 1 | %typemap(in) (char **ARRAY, int SIZE) { 2 | if (rb_obj_is_kind_of($input, rb_cArray)) { 3 | int size = RARRAY_LEN($input); 4 | $2 = ($2_ltype)size; 5 | $1 = (char **)malloc((size+1)*sizeof(char *)); 6 | VALUE *ptr = RARRAY_PTR($input); 7 | int i=0; 8 | for (; i < size; i++, ptr++) { 9 | $1[i] = StringValuePtr(*ptr); 10 | } 11 | $1[i] = 0; 12 | } else { 13 | $1 = 0; $2 = 0; 14 | %argument_fail(SWIG_TypeError, "char **ARRAY, int SIZE", $symname, $argnum); 15 | } 16 | } 17 | 18 | %typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (char **ARRAY, int SIZE) { 19 | $1 = rb_obj_is_kind_of($input, rb_cArray); 20 | } 21 | 22 | %typemap(freearg) (char **ARRAY, int SIZE) { 23 | free((char *)$1); 24 | } 25 | -------------------------------------------------------------------------------- /ruby/ctp.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |spec| 2 | spec.name = 'ctp' 3 | spec.version = '0.0.1' 4 | spec.summary = 'Summary ctp' 5 | spec.description = 'Description ctp' 6 | spec.email = 'myemail@provider.com' 7 | spec.homepage = 'http://myapp.com' 8 | spec.author = 'me' 9 | spec.files = Dir['*.so'] + Dir['*.dll'] 10 | spec.platform = Gem::Platform::CURRENT 11 | # spec.require_paths = [ 'lib', 'ext' ] 12 | end 13 | -------------------------------------------------------------------------------- /ruby/runmd.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | 4 | require 'thread' 5 | require 'ctp' 6 | include Ctp 7 | 8 | 9 | mutex = Mutex.new 10 | resource = ConditionVariable.new 11 | 12 | 13 | class MdSpi < CThostFtdcMdSpi 14 | @@request_id = 0 15 | 16 | def initialize 17 | super 18 | end 19 | 20 | def start(front, broke_id, user_id, password) 21 | @front = front; 22 | @broke_id = broke_id 23 | @user_id = user_id 24 | @password = password 25 | @api = CThostFtdcMdApi.create_ftdc_md_api() 26 | @api.register_spi(self) 27 | @api.register_front(@front) 28 | @api.init() 29 | end 30 | 31 | def join 32 | @api.join() 33 | end 34 | 35 | def stop 36 | @api.register_spi(nil) 37 | @api.release 38 | end 39 | 40 | def subscribe 41 | puts "subcribe..." 42 | @api.subscribe_market_data(["IF1302"]); 43 | end 44 | 45 | def on_front_connected 46 | puts "on_front_connected" 47 | 48 | field = CThostFtdcReqUserLoginField.new 49 | field.BrokerID = @broke_id 50 | field.UserID = @user_id 51 | field.Password = @password 52 | @@request_id += 1 53 | @api.req_user_login field, @@request_id 54 | end 55 | # 56 | def on_front_disconnected(reason) 57 | puts "on_front_connected" 58 | end 59 | # 60 | def on_heart_beat_warning(time_lapse) 61 | puts "on_heart_beat_warning" 62 | end 63 | # 64 | def on_rsp_user_login(field, info, request_id, last) 65 | puts "on_rsp_user_login" 66 | #day = @api.get_trading_day() 67 | #puts day 68 | #mutex.synchronize { 69 | # resource.signal 70 | #} 71 | 72 | puts "dddd" + Thread.current.to_s 73 | end 74 | # 75 | #def on_rsp_user_logout 76 | #end 77 | # 78 | def on_rsp_error(rsp_info, request_id, last) 79 | end 80 | # 81 | def on_rsp_sub_market_data(field, info, request_id, last) 82 | puts 'on_rsp_sub_market_data' 83 | end 84 | # 85 | #def on_rsp_un_sub_market_data 86 | #end 87 | # 88 | #def on_rtn_depth_market_data 89 | #end 90 | end 91 | 92 | conn = "tcp://asp-sim2-front1.financial-trading-platform.com:26213" 93 | broker = "2030" 94 | user = "352240" 95 | password = "888888" 96 | 97 | spi = MdSpi.new 98 | spi.start(conn, broker, user, password) 99 | puts Thread.current 100 | #mutex.synchronize { 101 | # resource.wait(mutex) 102 | #} 103 | 104 | #spi.subscribe 105 | spi.join 106 | spi.stop 107 | -------------------------------------------------------------------------------- /tcl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${TCL_INCLUDE_PATH}) 2 | 3 | set(CMAKE_SWIG_FLAGS "") 4 | set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) 5 | 6 | set(_target ctp-tcl) 7 | set(WRAPPER_FILES ../ctp.i) 8 | set_source_files_properties(${WRAPPER_FILES} PROPERTIES CPLUSPLUS ON) 9 | 10 | swig_add_module(${_target} tcl ${WRAPPER_FILES}) 11 | swig_link_libraries(${_target} ${TCL_LIBRARIES} ${CTP_LIBRARIES}) 12 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(ruby) 2 | -------------------------------------------------------------------------------- /test/ruby/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #file(COPY runmd.rb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 2 | -------------------------------------------------------------------------------- /test/ruby/runmd.rb: -------------------------------------------------------------------------------- 1 | $:.unshift File.dirname(__FILE__) 2 | 3 | 4 | 5 | puts File.join(File.dirname(__FILE__), '../..') --------------------------------------------------------------------------------