def get_open_close_hist_price(code, start_date=None, end_date=None):
'''
:param code: ????
:param date: ??????
:return: ?????open close ???
'''
import tushare as ts
if start_date != None and end_date != None:
if type(code) is not str or type(start_date) is not str:
code = str(code)
start_date = str(start_date)
end_date = str(end_date)
df = ts.get_hist_data(code, start_date,end_date)
df = df.head(1)
dtime = df.set_index('time')
price = dtime['price']
if price.shape == (0,):
print code, "can't get ", start_date, "am_pm data!"
return float('nan'), float('nan')
else:
return price[-1], price[len(df.time)/4]
else:
df = ts.get_hist_data(code)
df = df.head(1)
dtime = df.set_index('time')
price = dtime['price']
if price.shape == (0,):
print code, "can't get ", start_date, "am_pm data!"
return float('nan'), float('nan')
else:
return price[-1], price[len(df.time)/4]
评论列表
文章目录