diff --git a/vn.lts/vnltsmd/pyltsmd/vnltsmd.cpp b/vn.lts/vnltsmd/pyltsmd/vnltsmd.cpp index 4ed66837..927928bd 100644 --- a/vn.lts/vnltsmd/pyltsmd/vnltsmd.cpp +++ b/vn.lts/vnltsmd/pyltsmd/vnltsmd.cpp @@ -433,6 +433,15 @@ int MdApi::join() return i; }; +int MdApi::exit() +{ + //该函数在原生API里没有,用于安全退出API用,原生的join似乎不太稳定 + this->api->RegisterSpi(NULL); + this->api->Release(); + this->api = NULL; + return 1; +}; + string MdApi::getTradingDay() { string day = this->api->GetTradingDay(); @@ -642,6 +651,7 @@ BOOST_PYTHON_MODULE(vnltsmd) .def("release", &MdApiWrap::release) .def("init", &MdApiWrap::init) .def("join", &MdApiWrap::join) + .def("exit", &MdApiWrap::exit) .def("getTradingDay", &MdApiWrap::getTradingDay) .def("registerFront", &MdApiWrap::registerFront) .def("subscribeMarketData", &MdApiWrap::subscribeMarketData) diff --git a/vn.lts/vnltsmd/pyltsmd/vnltsmd.h b/vn.lts/vnltsmd/pyltsmd/vnltsmd.h index b5bf9190..44240c8f 100644 --- a/vn.lts/vnltsmd/pyltsmd/vnltsmd.h +++ b/vn.lts/vnltsmd/pyltsmd/vnltsmd.h @@ -258,6 +258,8 @@ public: int join(); + int exit(); + string getTradingDay(); void registerFront(string pszFrontAddress); diff --git a/vn.lts/vnltsmd/test/mdtest.py b/vn.lts/vnltsmd/test/mdtest.py index 8480ee9d..d753997d 100644 --- a/vn.lts/vnltsmd/test/mdtest.py +++ b/vn.lts/vnltsmd/test/mdtest.py @@ -128,16 +128,19 @@ def main(): #i = api.reqUserLogout({}, 1) #sleep(0.5) + ## 瀹夊叏閫鍑猴紝娴嬭瘯閫氳繃 + #i = api.exit() + # 鑾峰彇浜ゆ槗鏃ワ紝鐩墠杈撳嚭涓虹┖ #day = api.getTradingDay() #print 'Trading Day is:' + str(day) #sleep(0.5) - # 璁㈤槄鍚堢害 - subReq = {} - subReq['InstrumentID'] = '11000061' - subReq['ExchangeID'] = 'SSE' - i = api.subscribeMarketData(subReq) + ## 璁㈤槄鍚堢害 + #subReq = {} + #subReq['InstrumentID'] = '11000061' + #subReq['ExchangeID'] = 'SSE' + #i = api.subscribeMarketData(subReq) ## 閫璁㈠悎绾 #i = api.unSubscribeMarketData(subReq) diff --git a/vn.lts/vnltsmd/test/vnltsmd.pyd b/vn.lts/vnltsmd/test/vnltsmd.pyd index 52844e77..a4298b84 100644 Binary files a/vn.lts/vnltsmd/test/vnltsmd.pyd and b/vn.lts/vnltsmd/test/vnltsmd.pyd differ diff --git a/vn.lts/vnltstd/pyltstd/vnltstd.cpp b/vn.lts/vnltstd/pyltstd/vnltstd.cpp index 74a596a0..99334d08 100644 --- a/vn.lts/vnltstd/pyltstd/vnltstd.cpp +++ b/vn.lts/vnltstd/pyltstd/vnltstd.cpp @@ -2127,6 +2127,15 @@ int TdApi::join() return i; }; +int TdApi::exit() +{ + //该函数在原生API里没有,用于安全退出API用,原生的join似乎不太稳定 + this->api->RegisterSpi(NULL); + this->api->Release(); + this->api = NULL; + return 1; +}; + string TdApi::getTradingDay() { string day = this->api->GetTradingDay(); @@ -3129,6 +3138,7 @@ BOOST_PYTHON_MODULE(vnltstd) .def("release", &TdApiWrap::release) .def("init", &TdApiWrap::init) .def("join", &TdApiWrap::join) + .def("exit", &TdApiWrap::exit) .def("getTradingDay", &TdApiWrap::getTradingDay) .def("registerFront", &TdApiWrap::registerFront) .def("subscribePrivateTopic", &TdApiWrap::subscribePrivateTopic) diff --git a/vn.lts/vnltstd/pyltstd/vnltstd.h b/vn.lts/vnltstd/pyltstd/vnltstd.h index 417778fe..e8a3db34 100644 --- a/vn.lts/vnltstd/pyltstd/vnltstd.h +++ b/vn.lts/vnltstd/pyltstd/vnltstd.h @@ -496,6 +496,8 @@ public: int join(); + int exit(); + string getTradingDay(); void registerFront(string pszFrontAddress); diff --git a/vn.lts/vnltstd/test/tdtest.py b/vn.lts/vnltstd/test/tdtest.py index 6c438e45..a6b2b82e 100644 --- a/vn.lts/vnltstd/test/tdtest.py +++ b/vn.lts/vnltstd/test/tdtest.py @@ -345,6 +345,9 @@ def main(): #i = api.reqUserLogout({}, 1) #sleep(0.5) + ## 瀹夊叏閫鍑猴紝娴嬭瘯閫氳繃 + #i = api.exit() + ## 鑾峰彇浜ゆ槗鏃ワ紝鐩墠杈撳嚭涓虹┖锛屾祴璇曢氳繃 #day = api.getTradingDay() #print 'Trading Day is:' + str(day) diff --git a/vn.lts/vnltstd/test/vnltstd.pyd b/vn.lts/vnltstd/test/vnltstd.pyd index f33d57e9..9e756bb0 100644 Binary files a/vn.lts/vnltstd/test/vnltstd.pyd and b/vn.lts/vnltstd/test/vnltstd.pyd differ