diff --git a/bin/runtime724.ini b/bin/runtime724.ini new file mode 100644 index 0000000000000000000000000000000000000000..9e52524fdfab145714c4281b417db97490dd2b65 --- /dev/null +++ b/bin/runtime724.ini @@ -0,0 +1,32 @@ +[include] +section_config = ./section.csv +[actual_market] +market = ctp +front = tcp://180.168.146.187:10131 +broker = 9999 +userid = +passwd = + +[actual_trader] +trader = ctp +front = tcp://180.168.146.187:10130 +broker = 9999 +userid = +passwd = +appid = simnow_client_test +authcode = 0000000000000000 +prodict = lightning + + +[recorder] +type = csv +basic_path = ./record/runtime/ + + +[control] +localdb_name = runtime +userdata_size = 1024 +position_limit = 45 +fast_mode = false +loop_interval = 10000 +all_day = true diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ce76f890fbcc7858dd487f6688497167b288fba9..cf0b1ec9430a9f7ca6e240e801206fd37d2f749b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -# CMakeList.txt: 顶层 CMake 项目文件,在此处执行全局配置 +# CMakeList.txt: 顶层 CMake 项目文件,在此处执行全局配置 # 并包含子项目。 # cmake_minimum_required (VERSION 3.8) @@ -49,6 +49,10 @@ SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ) # 包含子项目。 +add_subdirectory ("LTBtRunner") + +add_subdirectory ("LTRunner") + add_subdirectory ("example") add_subdirectory("trader") diff --git a/src/LTBtRunner/.keep b/src/LTBtRunner/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/LTBtRunner/CMakeLists.txt b/src/LTBtRunner/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1439935b2732091313a08c6303a251a3e24d1bf5 --- /dev/null +++ b/src/LTBtRunner/CMakeLists.txt @@ -0,0 +1,24 @@ +# CMakeList.txt: gallop 的 CMake 项目,在此处包括源代码并定义 +# 项目特定的逻辑。 +# +cmake_minimum_required (VERSION 3.8) + +IF(UNIX) + SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} + "${PROJECT_SOURCE_DIR}/../api/v6.6.9_traderapi_20220920/v6.6.9_20220914_api_linux64/" + ) +ENDIF() + +include_directories(${CMAKE_INCLUDE_PATH}) +link_directories(${CMAKE_LIBRARY_PATH}) + +add_executable(LTBtRunner "LTBtRunner.cpp" "../example/marketing_strategy.cpp") + +target_link_libraries(LTBtRunner "framework") + +if (CMAKE_VERSION VERSION_GREATER 3.12) + set_property(TARGET LTBtRunner PROPERTY CXX_STANDARD 20) +endif() + +# TODO: 如有需要,请添加测试并安装目标。 + diff --git a/src/LTBtRunner/LTBtRunner.cpp b/src/LTBtRunner/LTBtRunner.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6fe54f5a9e69e96becc9273611d6a94b7e31e745 --- /dev/null +++ b/src/LTBtRunner/LTBtRunner.cpp @@ -0,0 +1,69 @@ +// 目标的源文件。 +// + +#include "LTBtRunner.h" +#include +#include "runtime_engine.h" +#include "evaluate_engine.h" +#include "../example/marketing_strategy.h" + + + +void start_evaluate(const char* account_config, const code_t& code, const std::vector& trading_days) +{ + lt::evaluate_engine app(account_config); + + std::vector> strategys; + + strategys.emplace_back(std::make_shared(2, app, code, 1, 1)); + + + app.set_trading_filter([&app](const code_t& code, offset_type offset, direction_type direction, uint32_t count, double_t price, order_flag flag)->bool { + auto now = app.get_last_time(); + auto last_order = app.last_order_time(); + + return true;//暂时先不过滤, + + if (now - last_order < 1) + { + return false; + } + return true; + }); + + for (auto& trading_day : trading_days) + { + app.back_test(strategys, trading_day); + } +} + + +int main(int argc,char* argv[]) +{ + //std::vector trading_days{ 20220801, 20220802, 20220803, 20220804, 20220805 }; + //start_evaluate("evaluate.ini", "SHFE.rb2210", trading_days); + + + if(argc ==1)//main (argc=1, argv=0x7fffffffdfb8) + { + LOG_ERROR("start atgc error"); + return -1; + } + // if (std::strcmp("evaluate", argv[1]) == 0) + // { + + const char* account_file = argv[1]; + //const char* strategy_file = argv[3]; + //const char* trading_day_file = argv[4]; + //LOG_INFO("start evaluate for %s %s %s\n", account_file, strategy_file, trading_day_file); + //start_evaluate(account_file, strategy_file, trading_day_file); + + std::vector trading_days{ 20220801, 20220802, 20220803, 20220804, 20220805 }; + start_evaluate(account_file, "SHFE.rb2210", trading_days); + // } + + + + + return 0; +} diff --git a/src/LTBtRunner/LTBtRunner.h b/src/LTBtRunner/LTBtRunner.h new file mode 100644 index 0000000000000000000000000000000000000000..250b1d23ae1445b9bc061d08b6fcb84a46da21d9 --- /dev/null +++ b/src/LTBtRunner/LTBtRunner.h @@ -0,0 +1,3 @@ +// example.h: 目标的头文件。 + +#pragma once diff --git a/src/LTBtRunner/build_debug.sh b/src/LTBtRunner/build_debug.sh new file mode 100644 index 0000000000000000000000000000000000000000..acbabacf8d36e9a63afa5627c221e1aea7faab1f --- /dev/null +++ b/src/LTBtRunner/build_debug.sh @@ -0,0 +1,6 @@ +if [ ! -d "../build_debug" ];then +mkdir build_debug +fi +cd build_debug +cmake -DCMAKE_BUILD_TYPE=Debug .. +make diff --git a/src/LTRunner/.keep b/src/LTRunner/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/LTRunner/CMakeLists.txt b/src/LTRunner/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ce86cbcafda41c0a0bc9327964cd168235c7a7e2 --- /dev/null +++ b/src/LTRunner/CMakeLists.txt @@ -0,0 +1,24 @@ +# CMakeList.txt: CMake 项目,在此处包括源代码并定义 +# 项目特定的逻辑。 +# +cmake_minimum_required (VERSION 3.8) + +IF(UNIX) + SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} + "${PROJECT_SOURCE_DIR}/../api/v6.6.9_traderapi_20220920/v6.6.9_20220914_api_linux64/" + ) +ENDIF() + +include_directories(${CMAKE_INCLUDE_PATH}) +link_directories(${CMAKE_LIBRARY_PATH}) + +add_executable(LTRunner "LTRunner.cpp" "../example/marketing_strategy.cpp") + +target_link_libraries(LTRunner "framework") + +if (CMAKE_VERSION VERSION_GREATER 3.12) + set_property(TARGET LTRunner PROPERTY CXX_STANDARD 20) +endif() + +# TODO: 如有需要,请添加测试并安装目标。 + diff --git a/src/LTRunner/LTRunner.cpp b/src/LTRunner/LTRunner.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ebdfd0082254aecf7167380386fd6a12c03bb03 --- /dev/null +++ b/src/LTRunner/LTRunner.cpp @@ -0,0 +1,60 @@ +// 目标的源文件。 +// + +#include "LTRunner.h" +#include +#include "runtime_engine.h" +#include "evaluate_engine.h" +#include "../example/marketing_strategy.h" + + +void start_runtime(const char* account_config, const code_t& code) +{ + lt::runtime_engine app(account_config); + + std::vector> strategys; + + strategys.emplace_back(std::make_shared(1, app, code, 1, 1)); + + app.set_trading_filter([&app](const code_t& code, offset_type offset, direction_type direction, uint32_t count, double_t price, order_flag flag)->bool { + auto now = app.get_last_time(); + auto last_order = app.last_order_time(); + + return true;//暂时先不用过滤, + + if (now - last_order < 1) + { + return false; + } + return true; + }); + + app.run_to_close(strategys); +} + + +int main(int argc,char* argv[]) +{ + //start_runtime("runtime.ini", "SHFE.ni2309"); + + if(argc ==1)//main (argc=1, argv=0x7fffffffdfb8) + { + LOG_ERROR("start atgc error"); + return -1; + } + + // if (std::strcmp("runtime", argv[1]) == 0) + // { + // } + + const char* account_file = argv[1]; + //const char* strategy_file = argv[3]; + //LOG_INFO("start runtime for %s %s\n", account_file, strategy_file); + //start_runtime(account_file, strategy_file); + + start_runtime(account_file, "SHFE.rb2310"); + + + + return 0; +} diff --git a/src/LTRunner/LTRunner.h b/src/LTRunner/LTRunner.h new file mode 100644 index 0000000000000000000000000000000000000000..250b1d23ae1445b9bc061d08b6fcb84a46da21d9 --- /dev/null +++ b/src/LTRunner/LTRunner.h @@ -0,0 +1,3 @@ +// example.h: 目标的头文件。 + +#pragma once diff --git a/src/LTRunner/build_debug.sh b/src/LTRunner/build_debug.sh new file mode 100644 index 0000000000000000000000000000000000000000..acbabacf8d36e9a63afa5627c221e1aea7faab1f --- /dev/null +++ b/src/LTRunner/build_debug.sh @@ -0,0 +1,6 @@ +if [ ! -d "../build_debug" ];then +mkdir build_debug +fi +cd build_debug +cmake -DCMAKE_BUILD_TYPE=Debug .. +make diff --git a/src/build_debug.sh b/src/build_debug.sh new file mode 100644 index 0000000000000000000000000000000000000000..acbabacf8d36e9a63afa5627c221e1aea7faab1f --- /dev/null +++ b/src/build_debug.sh @@ -0,0 +1,6 @@ +if [ ! -d "../build_debug" ];then +mkdir build_debug +fi +cd build_debug +cmake -DCMAKE_BUILD_TYPE=Debug .. +make diff --git a/src/build_release.sh b/src/build_release.sh new file mode 100644 index 0000000000000000000000000000000000000000..b06ce6d488dcd2784004ea9c95fb2d568813baad --- /dev/null +++ b/src/build_release.sh @@ -0,0 +1,6 @@ +if [ ! -d "../build_all" ];then +mkdir build_all +fi +cd build_all +cmake -DCMAKE_BUILD_TYPE=Release .. +make -j4 diff --git a/src/core/context.cpp b/src/core/context.cpp index ccc70f8d5550dbd6945dd5949eb6e13ec3c35a87..d0806d0c76ca33e140bcdd2a8a1bc444eb535baf 100644 --- a/src/core/context.cpp +++ b/src/core/context.cpp @@ -1,4 +1,4 @@ -#include "context.h" +#include "context.h" #include #include #include @@ -27,7 +27,8 @@ context::context(): _ready_callback(nullptr), _update_callback(nullptr), _last_tick_time(0), - realtime_event() + realtime_event(), + _all_day(false) { } @@ -69,6 +70,7 @@ void context::init(boost::property_tree::ptree& ctrl, boost::property_tree::ptre } _max_position = ctrl.get("position_limit", 10000); _fast_mode = ctrl.get("fast_mode", false); + _all_day = ctrl.get("all_day", false); _loop_interval = ctrl.get("loop_interval", 1); const auto& section_config = include_config.get("section_config", "./section.csv"); _section = std::make_shared(section_config); @@ -273,7 +275,7 @@ estid_t context::place_order(untid_t untid,offset_type offset, direction_type di LOG_DEBUG("place_order _is_trading_ready"); return INVALID_ESTID; } - if(!_section->is_in_trading(get_last_time())) + if(!_section->is_in_trading(get_last_time())&& !_all_day ) { LOG_DEBUG("place_order code not in trading %s", code.get_id()); return INVALID_ESTID; @@ -439,7 +441,7 @@ time_t context::get_close_time() { return 0; } - return _section->get_clase_time(); + return _section->get_close_time(); } void context::use_custom_chain(untid_t untid,bool flag) @@ -695,7 +697,7 @@ void context::handle_tick(const std::vector& param) _section->init(trading_day, last_tick.time); check_crossday(trading_day); } - if(!_section->is_in_trading(last_tick.time)) + if(!_section->is_in_trading(last_tick.time) && !_all_day) { return; } diff --git a/src/core/context.h b/src/core/context.h index b22d917572e15dc9bb7a6b72759da70c325eeb4f..2109a8cf0693bc234a339d63fdadbf95d3eea007 100644 --- a/src/core/context.h +++ b/src/core/context.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include #include @@ -76,6 +76,8 @@ private: bool _fast_mode ; + bool _all_day ; + uint32_t _loop_interval ; std::map _previous_tick; diff --git a/src/core/trading_section.cpp b/src/core/trading_section.cpp index 260452ff1b2c44b5c06d8333073d142480505b9f..a6c6dad238da4bd78fd6dcaf75aca5224f9d6f20 100644 --- a/src/core/trading_section.cpp +++ b/src/core/trading_section.cpp @@ -1,4 +1,4 @@ -#include "trading_section.h" +#include "trading_section.h" #include #include @@ -84,7 +84,7 @@ time_t trading_section::get_open_time() return frist_one->second; } -time_t trading_section::get_clase_time() +time_t trading_section::get_close_time() { auto last_one = _trading_section.rbegin(); if(last_one == _trading_section.rend()) diff --git a/src/core/trading_section.h b/src/core/trading_section.h index bfa2bc8211db34129bdca68fae4b26288ca631f7..2611a47c8119bbbdb9c4785b512881bf6766f331 100644 --- a/src/core/trading_section.h +++ b/src/core/trading_section.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include @@ -20,7 +20,7 @@ public: time_t get_open_time(); - time_t get_clase_time(); + time_t get_close_time(); }; diff --git a/src/include/time_utils.hpp b/src/include/time_utils.hpp index 836d5f5207c487e640196d8f13905442ddd94485..b75954d6496cc3815f7dec9fac43094684c92ffe 100644 --- a/src/include/time_utils.hpp +++ b/src/include/time_utils.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -28,6 +28,7 @@ static time_t make_datetime(int year, int month, int day, int hour=0, int minute t.tm_hour = hour; t.tm_min = minute; t.tm_sec = second; + t.tm_isdst = -1;//添加这一行初始化tm_isdst,不然mktime返回值恒为-1 return mktime(&t); } diff --git a/src/market/ctp_market.cpp b/src/market/ctp_market.cpp index 2183a7a11aefaa4131df306e35c161e117a5c9a1..c3ad1fe76abb672ea061ad1f0d84426d6e69c87a 100644 --- a/src/market/ctp_market.cpp +++ b/src/market/ctp_market.cpp @@ -1,4 +1,4 @@ - + #include "ctp_market.h" #include #include @@ -41,7 +41,7 @@ bool ctp_market::init(const boost::property_tree::ptree& config) } catch (...) { - LOG_ERROR("ctp_trader init error "); + LOG_ERROR("ctp_market init error "); return false; } @@ -66,13 +66,13 @@ void ctp_market::OnRspError( CThostFtdcRspInfoField *pRspInfo, int nRequestID, b { if(pRspInfo) { - LOG_ERROR("Error:%d->%s", pRspInfo->ErrorID, pRspInfo->ErrorMsg); + LOG_ERROR("OnRspError:%d->%s", pRspInfo->ErrorID, pRspInfo->ErrorMsg); } } void ctp_market::OnFrontConnected() { - LOG_INFO("Connected : %s", _front_addr.c_str()); + LOG_INFO("OnFrontConnected : %s", _front_addr.c_str()); do_userlogin(); } @@ -80,11 +80,11 @@ void ctp_market::OnRspUserLogin( CThostFtdcRspUserLoginField *pRspUserLogin, CTh { if(pRspInfo) { - LOG_DEBUG("UserLogin : %d -> %s", pRspInfo->ErrorID, pRspInfo->ErrorMsg); + LOG_DEBUG("OnRspUserLogin : %d -> %s", pRspInfo->ErrorID, pRspInfo->ErrorMsg); } if(bIsLast) { - LOG_INFO("UserLogin : Market data server logined, {%s} {%s}", pRspUserLogin->TradingDay, pRspUserLogin->UserID); + LOG_INFO("OnRspUserLogin : Market data server logined, {%s} {%s}", pRspUserLogin->TradingDay, pRspUserLogin->UserID); //订阅行情数据 do_subscribe(); if(!_is_inited) @@ -98,13 +98,13 @@ void ctp_market::OnRspUserLogout(CThostFtdcUserLogoutField *pUserLogout, CThostF { if (pRspInfo) { - LOG_DEBUG("UserLogout : %d -> %s", pRspInfo->ErrorID, pRspInfo->ErrorMsg); + LOG_DEBUG("OnRspUserLogout : %d -> %s", pRspInfo->ErrorID, pRspInfo->ErrorMsg); } } void ctp_market::OnFrontDisconnected( int nReason ) { - LOG_INFO("FrontDisconnected : Reason -> %d", nReason); + LOG_INFO("OnFrontDisconnected : Reason -> %d", nReason); } @@ -114,7 +114,7 @@ void ctp_market::OnRtnDepthMarketData( CThostFtdcDepthMarketDataField *pDepthMar { return; } - LOG_DEBUG("MarketData = [%s] [%f]\n", pDepthMarketData->InstrumentID, pDepthMarketData->LastPrice); + LOG_DEBUG("OnRtnDepthMarketData = [%s] [%f]\n", pDepthMarketData->InstrumentID, pDepthMarketData->LastPrice); tick_info tick ; auto excg_it = _instrument_id_list.find(pDepthMarketData->InstrumentID); @@ -158,7 +158,7 @@ void ctp_market::OnRspSubMarketData( CThostFtdcSpecificInstrumentField *pSpecifi { if(pRspInfo) { - LOG_INFO("SubMarketData : code -> %d %s", pRspInfo->ErrorID, pRspInfo->ErrorMsg); + LOG_INFO("OnRspSubMarketData : code -> %d %s", pRspInfo->ErrorID, pRspInfo->ErrorMsg); } } @@ -166,7 +166,7 @@ void ctp_market::OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField* pSpecif { if (pRspInfo) { - LOG_INFO("SubMarketData : code -> %d %s", pRspInfo->ErrorID, pRspInfo->ErrorMsg); + LOG_INFO("OnRspUnSubMarketData : code -> %d %s", pRspInfo->ErrorID, pRspInfo->ErrorMsg); } }