You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
4.0 KiB
108 lines
4.0 KiB
2 years ago
|
import pymssql
|
||
|
import gzip
|
||
|
from ProtoBuffEntitys import TickMessage_pb2
|
||
|
from ProtoBuffEntitys import OrderMessage_pb2
|
||
|
from ProtoBuffEntitys import TranseMessage_pb2
|
||
|
from ProtoBuffEntitys import TickQueueMessage_pb2
|
||
|
from ProtoBuffEntitys import KLineMessage_pb2
|
||
|
|
||
|
def ReadTick(ip,user,pw,dbName,code,date):
|
||
|
conn = pymssql.connect(host=ip,user=user,password=pw,database=dbName)
|
||
|
cursor = conn.cursor()
|
||
|
sql = '''SELECT [S_INFO_WINDCODE]
|
||
|
,[TRADE_DT]
|
||
|
,[Bytes]
|
||
|
FROM [{0}].[dbo].[Tick]
|
||
|
WHERE [TRADE_DT]='{1}' AND [S_INFO_WINDCODE]='{2}' '''.format(dbName, date,code)
|
||
|
cursor.execute(sql)
|
||
|
rs = cursor.fetchall()
|
||
|
if len(rs) == 0:
|
||
|
return []
|
||
|
f_all=rs[0][2]
|
||
|
f_all=gzip.decompress(f_all)
|
||
|
dataArray=TickMessage_pb2.TickArray()
|
||
|
dataArray.ParseFromString(f_all)
|
||
|
return dataArray.dataArray
|
||
|
|
||
|
array=ReadTick('10.10.11.61','yuhaomiao','yhm9591','Level2BytesTick','000001.SZ',20200911)
|
||
|
print('''Tick Code:{0}'''.format(array[0].code))
|
||
|
def ReadTickQue(ip,user,pw,dbName,code,date):
|
||
|
conn = pymssql.connect(host=ip,user=user,password=pw,database=dbName)
|
||
|
cursor = conn.cursor()
|
||
|
sql = '''SELECT [S_INFO_WINDCODE]
|
||
|
,[TRADE_DT]
|
||
|
,[Bytes]
|
||
|
FROM [{0}].[dbo].[TickQue]
|
||
|
WHERE [TRADE_DT]='{1}' AND [S_INFO_WINDCODE]='{2}' '''.format(dbName, date,code)
|
||
|
cursor.execute(sql)
|
||
|
rs = cursor.fetchall()
|
||
|
if len(rs) == 0:
|
||
|
return []
|
||
|
f_all=rs[0][2]
|
||
|
f_all=gzip.decompress(f_all)
|
||
|
dataArray=TickQueueMessage_pb2.TickQueueArray()
|
||
|
dataArray.ParseFromString(f_all)
|
||
|
return dataArray.dataArray
|
||
|
|
||
|
array=ReadTickQue('10.10.11.61','yuhaomiao','yhm9591','Level2BytesTickQue','000001.SZ',20200911)
|
||
|
print('''TickQue Code:{0}'''.format(array[0].code))
|
||
|
def ReadTranse(ip,user,pw,dbName,code,date):
|
||
|
conn = pymssql.connect(host=ip,user=user,password=pw,database=dbName)
|
||
|
cursor = conn.cursor()
|
||
|
sql = '''SELECT [S_INFO_WINDCODE]
|
||
|
,[TRADE_DT]
|
||
|
,[Bytes]
|
||
|
FROM [{0}].[dbo].[Transe]
|
||
|
WHERE [TRADE_DT]='{1}' AND [S_INFO_WINDCODE]='{2}' '''.format(dbName, date,code)
|
||
|
cursor.execute(sql)
|
||
|
rs = cursor.fetchall()
|
||
|
if len(rs) == 0:
|
||
|
return []
|
||
|
f_all=rs[0][2]
|
||
|
f_all=gzip.decompress(f_all)
|
||
|
dataArray=TranseMessage_pb2.TranseArray()
|
||
|
dataArray.ParseFromString(f_all)
|
||
|
return dataArray.dataArray
|
||
|
|
||
|
array=ReadTranse('10.10.11.61','yuhaomiao','yhm9591','Level2BytesTranse','000001.SZ',20200911)
|
||
|
print('''Transe Code:{0}'''.format(array[0].code))
|
||
|
def ReadOrder(ip,user,pw,dbName,code,date):
|
||
|
conn = pymssql.connect(host=ip,user=user,password=pw,database=dbName)
|
||
|
cursor = conn.cursor()
|
||
|
sql = '''SELECT [S_INFO_WINDCODE]
|
||
|
,[TRADE_DT]
|
||
|
,[Bytes]
|
||
|
FROM [{0}].[dbo].[Order]
|
||
|
WHERE [TRADE_DT]='{1}' AND [S_INFO_WINDCODE]='{2}' '''.format(dbName, date,code)
|
||
|
cursor.execute(sql)
|
||
|
rs = cursor.fetchall()
|
||
|
if len(rs) == 0:
|
||
|
return []
|
||
|
f_all=rs[0][2]
|
||
|
f_all=gzip.decompress(f_all)
|
||
|
dataArray=OrderMessage_pb2.OrderArray()
|
||
|
dataArray.ParseFromString(f_all)
|
||
|
return dataArray.dataArray
|
||
|
|
||
|
array=ReadOrder('10.10.11.61','yuhaomiao','yhm9591','Level2BytesOrder','000001.SZ',20200911)
|
||
|
print('''Order Code:{0}'''.format(array[0].code))
|
||
|
def ReadKLine(ip,user,pw,dbName,code,date):
|
||
|
conn = pymssql.connect(host=ip,user=user,password=pw,database=dbName)
|
||
|
cursor = conn.cursor()
|
||
|
sql = '''SELECT [S_INFO_WINDCODE]
|
||
|
,[TRADE_DT]
|
||
|
,[Bytes]
|
||
|
FROM [{0}].[dbo].[KLine]
|
||
|
WHERE [TRADE_DT]='{1}' AND [S_INFO_WINDCODE]='{2}' '''.format(dbName, date,code)
|
||
|
cursor.execute(sql)
|
||
|
rs = cursor.fetchall()
|
||
|
if len(rs) == 0:
|
||
|
return []
|
||
|
f_all=rs[0][2]
|
||
|
f_all=gzip.decompress(f_all)
|
||
|
dataArray=KLineMessage_pb2.KLineArray()
|
||
|
dataArray.ParseFromString(f_all)
|
||
|
return dataArray.dataArray
|
||
|
|
||
|
array=ReadKLine('10.10.11.61','yuhaomiao','yhm9591','Level2BytesKLine','000001.SZ',20200911)
|
||
|
print('''KLine Code:{0}'''.format(array[0].code))
|