由index为timestamp的数据获取股票集合竞价数据

##string变struct_time变timestamp
##拿index取记录

import time
from datetime import datetime
from time import mktime

list_time = get_price("000001.XSHG", start_date=20150107, end_date=20150107, frequency='tick').index.tolist()  #随便给的股票和日期

start_str = "2015-01-07 09:25:00"  #此处换trading_date组装一下,盘前一定会大于等于九点二十五分
end_str = "2015-01-07 09:26:00"#盘前一定会小于等于九点二十六分

start_time = time.strptime(start_str,'%Y-%m-%d %H:%M:%S')
end_time = time.strptime(end_str,'%Y-%m-%d %H:%M:%S')

end_dt = datetime.fromtimestamp(mktime(end_time))
start_dt = datetime.fromtimestamp(mktime(start_time))

index_key = list(filter(lambda x : x<=end_dt and x>=start_dt,list_time))[0] #筛出盘前数据,根据rq的数据特点,取第一条925就是,不然其实还是要用volume筛一下的。

df.loc[index_key] ##return或者print

 

你可能感兴趣的:(Python)