The import tushare
The import time
Def getrealtimedata (share) :
DataNow=tushare. Get_realtime_quotes (share. Code)
Share. Name=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 the amount=dataNow. Loc [0] [9]
Share. OpenToday=dataNow. Loc [0] [1]
Share. Pre_close=dataNow. Loc [0] [2]
Share. Timee=dataNow. Loc [0] [30]
Share. The describe="stock name:" + share. Name + "the current price is:" + STR (. Share price)
Return share
# set stock class
The class Share () :
Def __init__ (self, code, buy, sale) :
The self. The name=""
Self. Price=""
Self. High=""
Self. Low=""
The self. The volumn=""
The self. The amount=""
Self. OpenToday=""
Self. Pre_close=""
The self. The timee=""
The self. The describe=""
Self. Code=""
Self. Buy=buy
The self. The sale=sale
Def main (code, buy, sale) :
Share=share (code)
SSS=getrealtimedata (share)
Print (SSS. The describe)
If SSS. Price<=buy:
Print (" to buy, if they had the money to buy ")
Elif SSS. Price>=sale:
Print (" reach the selling point, if they had the money to sell ")
The else:
Print (" don't buy don't sell, waiting for ")
While 1==1:
The main (" 000591 ", 3.3, 3.6)
Share (" 000591 ")
Time. Sleep (5)
CodePudding user response:
Create a Share in the main function instance only passed a parameterCodePudding user response:
Share=share (code) here only send a code parameter, actually class share () :Def __init__ (self, code, buy, sale) is the need to code, buy, sale of three parameters, or to buy back two parameters, sale attach a default value