vnpy/vn.lts/vnltsmd/test/mdtest.py

152 lines
4.0 KiB
Python
Raw Normal View History

# encoding = UTF-8
import sys
from time import sleep
from PyQt4 import QtGui
from vnltsmd import *
#----------------------------------------------------------------------
def print_dict(d):
"""<EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>ֵ<EFBFBD><EFBFBD>ӡһ<EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>"""
for key,value in d.items():
print key + ':' + str(value)
#----------------------------------------------------------------------
def simple_log(func):
"""<EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"""
def wrapper(*args, **kw):
print ""
print str(func.__name__)
return func(*args, **kw)
return wrapper
########################################################################
class TestMdApi(MdApi):
"""<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>"""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
super(TestMdApi, self).__init__()
#----------------------------------------------------------------------
@simple_log
def onFrontConnected(self):
"""<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"""
pass
#----------------------------------------------------------------------
@simple_log
def onFrontDisconnected(self, n):
"""<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD>"""
print n
#----------------------------------------------------------------------
@simple_log
def onHeartBeatWarning(self, n):
"""<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"""
print n
#----------------------------------------------------------------------
@simple_log
def onRspError(self, error, n, last):
"""<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"""
print_dict(error)
#----------------------------------------------------------------------
def onRspUserLogin(self, data, error, n, last):
"""<EFBFBD><EFBFBD>½<EFBFBD>ر<EFBFBD>"""
print_dict(data)
print_dict(error)
#----------------------------------------------------------------------
@simple_log
def onRspUserLogout(self, data, error, n, last):
"""<EFBFBD>dz<EFBFBD><EFBFBD>ر<EFBFBD>"""
print_dict(data)
print_dict(error)
#----------------------------------------------------------------------
@simple_log
def onRspSubMarketData(self, data, error, n, last):
"""<EFBFBD><EFBFBD><EFBFBD>ĺ<EFBFBD>Լ<EFBFBD>ر<EFBFBD>"""
print_dict(data)
print_dict(error)
#----------------------------------------------------------------------
@simple_log
def onRspUnSubMarketData(self, data, error, n, last):
"""<EFBFBD>˶<EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD>ر<EFBFBD>"""
print_dict(data)
print_dict(error)
#----------------------------------------------------------------------
@simple_log
def onRtnDepthMarketData(self, data):
"""<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"""
print_dict(data)
#----------------------------------------------------------------------
def main():
"""<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>sleep"""
reqid = 0
# <20><><EFBFBD><EFBFBD>QtӦ<74>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>ѭ<EFBFBD><D1AD>
app = QtGui.QApplication(sys.argv)
# <20><><EFBFBD><EFBFBD>API<50><49><EFBFBD><EFBFBD>
api = TestMdApi()
# <20><>C++<2B><><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>MdApi<70><69><EFBFBD>󣬴<EFBFBD><F3A3ACB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.con<6F>ļ<EFBFBD><C4BC>ĵ<EFBFBD>ַ
api.createFtdcMdApi('')
# ע<><D7A2>ǰ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>ַ
api.registerFront("tcp://101.231.210.1:24513")
# <20><>ʼ<EFBFBD><CABC>api<70><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>û<EFBFBD>
api.init()
sleep(0.5)
# <20><>½
loginReq = {} # <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>
loginReq['UserID'] = '' # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>ֵ<EFBFBD>ķ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
loginReq['Password'] = '' # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>C++<2B>еĽṹ<C4BD><E1B9B9><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>Ӧ
loginReq['BrokerID'] = '2011'
reqid = reqid + 1 # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB1A3>Ψһ<CEA8><D2BB>
i = api.reqUserLogin(loginReq, 1)
sleep(0.5)
## <20>dz<EFBFBD>
#reqid = reqid + 1
#i = api.reqUserLogout({}, 1)
#sleep(0.5)
# <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>գ<EFBFBD>Ŀǰ<C4BF><C7B0><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
#day = api.getTradingDay()
#print 'Trading Day is:' + str(day)
#sleep(0.5)
# <20><><EFBFBD>ĺ<EFBFBD>Լ
subReq = {}
subReq['InstrumentID'] = '600600'
subReq['ExchangeID'] = 'SSE'
i = api.subscribeMarketData(subReq)
## <20>˶<EFBFBD><CBB6><EFBFBD>Լ
#i = api.unSubscribeMarketData(subReq)
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
app.exec_()
if __name__ == '__main__':
main()