List多只股票实时价格监控代码

import time
from jiJingTest import getRealTimeData
class shareList(object):

   def __init__(self,code,buy,sale):
       self.stockName = ""
       self.price = ""
       self.high = ""
       self.low = ""
       self.volumn = ""
       self.amount = ""
       self.openToday = ""
       self.preClose = ""
       self.timee = ""
       self.dec =""
       self.code= code
       self.buy=buy
       self.sale=sale


class maina(object):

    def main(shareList):
        for share in shareList:

            sss=getRealTimeData(share)

            if sss.price<=float(sss.buy):
                print(sss.dec,"达到买入...")
            elif sss.price>=float(sss.sale):
                print(sss.dec,"达到卖出...")
            else:
                print(sss.dec,"数据监控中...")

while 1==1:

    share1=shareList("600106",3.6,3.8)
    share2 = shareList("600116", 3.6, 3.8)
    share3 = shareList("000591", 3.6, 3.8)

    list1=[share1,share2,share3]
    print("---------------")
    maina.main(list1)
    time.sleep(5)

tushare 查询


import tushare

def getRealTimeData(share):
    dataNow=tushare.get_realtime_quotes(share.code)
    share.stockName=dataNow.loc[0][0]
    share.price=float(dataNow.loc[0][3])
    share.high=dataNow.loc[0][4]
    share.low=dataNow.loc[0][5]
    share.volumn=dataNow.loc[0][8]
    share.amount=dataNow.loc[0][9]
    share.openToday=dataNow.loc[0][1]
    share.preClose=dataNow.loc[0][2]
    share.timee=dataNow.loc[0][30]
    share.dec=("股票名称:"+share.stockName+"\t价格:"+str(share.price))
    return share

猜你喜欢

转载自blog.csdn.net/weixin_44371918/article/details/89894208