1.python基礎篇---監控股票

使用tushare庫html

獲取股票信息url

1.安裝tushare庫spa

  win+R輸入cmd進入控制檯.net

  輸入pip install tusharecode

2.獲取股票信息orm

1 import tushare,time 2 #導入tushare庫
3 data = tushare.get_realtime_quotes(‘000581’) 4 #獲取股票代碼爲000581的股票信息
5 print(data)

 

3.根據自定義要求,獲取指定數據htm

由於tushare獲取的返回值是一個pandas類型數據。能夠用loc方式獲取單獨數據blog

data = tushare.get_realtime_quotes(share.code)
share.name = data.loc[0][0]
share.open = float(data.loc[0][1])
share.price = float(data.loc[0][3])
share.high = float(data.loc[0][4])
share.low = float(data.loc[0][5])

4.tushare庫詳細用法ip

參考資料:http://tushare.waditu.com/trading.htmlget

完整代碼-------------------------------------------------------------------

 1 import tushare,time  2 
 3 def getrealtimedata(share):  4     data = tushare.get_realtime_quotes(share.code)  5     share.name = data.loc[0][0]  6     share.open = float(data.loc[0][1])  7     share.price = float(data.loc[0][3])  8     share.high = float(data.loc[0][4])  9     share.low = float(data.loc[0][5]) 10     share.describe='股票編號:{},股票名稱:{},今日開盤價:{},當前價格:{},今日最高價:{},今日最低價:{}'.format(share.code,share.name,share.open,share.price,share.high,share.low) 11     return share 12 
13 class Share(): 14     def __init__(self,code,buy,sale): 15         self.name = ''
16         self.open = ''
17         self.price = ''
18         self.high = ''
19         self.low = ''
20         self.describe=''
21         self.code = code 22         self.buy = buy 23         self.sale = sale 24 
25 def main(sharelist): 26     # share = Share(code)
27     for share in sharelist: 28         sss=getrealtimedata(share) 29         print(sss.describe) 30 
31         if sss.price <=sss.buy: 32             print('價格超低,趕忙買入!') 33         elif sss.price >= sss.sale: 34             print('趕忙賣出。大賺了!') 35         else: 36             print('靜觀其變……') 37 
38 while True: 39     share1=Share("000581",18.7,19.0) 40     share2=Share("600106",18.7,19.0) 41     share3=Share("000591",18.7,19.0) 42     sharelist = [share1,share2,share3] 43  main(sharelist) 44     time.sleep(5)
相關文章
相關標籤/搜索