001量化專案總結 --02獲取五檔買盤價格

Lionever發表於2024-05-02

一、獲取五檔買盤

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
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

相關文章