def test_subcribe_depth_market_data(): """ 测试订阅行情 """ f1 = [] def OnRspSubMarketData(**kwargs): print 'OnRspSubMarketData() is called' f1.append(1) f2 = [] def OnRtnDepthMarketData(**kwargs): print 'OnRtnDepthMarketData() is called' f2.append(1) # 创建md对象 global frontAddress, mdFrontAddress, brokerID, userID, password md = Md(mdFrontAddress, brokerID, userID, password) md.bind(callback.OnRspSubMarketData, OnRspSubMarketData) md.bind(callback.OnRtnDepthMarketData, OnRtnDepthMarketData) md.SubscribeMarketData([getDefaultInstrumentID()]) sleep(1) print 'len(f1) =', len(f1) assert len(f1) > 0 assert len(f2) > 0
def test_md_process_create_and_clean(): """ 测试Md对象的创建和清理 """ global frontAddress, mdFrontAddress, brokerID, userID, password process = psutil.Process() # 创建后可以找到一个trader进程 md = Md(mdFrontAddress, brokerID, userID, password) pid = md.getConverterPid() assert pid and pid != 0 assert pid in [child.pid for child in process.children()] # 将变量指向None迫使垃圾回收,确认进程被清理了 md = None sleep(1) assert pid not in [child.pid for child in process.children()]