一、获取五档买盘
price = 0.0
pmarkcode = 0
sip = ''
sport = 0
l1 = []
time_now = datetime.now().minute
if (scode[0] == '0' and scode[1] == '0') or scode[0] == '3':
pmarkcode = 0
else:
pmarkcode = 1
api = TdxHq_API()
if time_now % 2 == 0:
sip = '*.*' #
sport = 7709
else:
sip = '*.*' #
sport = 7711
if api.connect(sip, sport):
data = api.get_security_quotes([pmarkcode, scode])
cdata = api.get_company_info_category(pmarkcode, scode)
# print(data)
# print(type(data))
# print(type(data[0]))
# print(datetime.now().minute)
d1 = collections.OrderedDict()
d1 = data[0]
for i in range(5):
for key, value in d1.items():
if key == 'bid' + str(i):
price = value
l1.append(price)
api.disconnect()
return l1
二、获取五档卖盘价格
price =0.0标签:02,pmarkcode,--,api,scode,sport,data,五档,d1 From: https://www.cnblogs.com/lionmxs/p/18170374
pmarkcode =0
sip =''
sport =0
l1=[]
time_now =datetime.now().minute
if (scode[0]=='0' and scode[1]=='0') or scode[0]=='3':
pmarkcode=0
else:
pmarkcode=1
api = TdxHq_API()
if time_now%2==0:
sip='*.*'
sport =7709
else:
sip='*.*'
sport=7711
if api.connect(sip,sport ):
data = api.get_security_quotes([pmarkcode,scode])
cdata = api.get_company_info_category(pmarkcode,scode)
d1= collections.OrderedDict()
d1 = data[0]
for i in range(6):
for key ,value in d1.items():
if key=='ask'+str(i):
price= value
l1.append(price)
api.disconnect()
return l1