def get_am_pm_price(code, date):
'''
:param code: ????
:param date: ??????
:return: ??????????????10?,???2:30???
'''
if type(code) is not str or type(date) is not str:
code = str(code)
date = str(date)
import tushare as ts
df = ts.get_tick_data(code, date)
dtime = df.set_index('time')
price = dtime['price']
if price.shape == (0,):
print code, "can't get ", date, "am_pm data!"
return float('nan'), float('nan')
else:
return price[-1], price[len(df.time)/4]
python类get_tick_data()的实例源码
def QA_fetch_get_stock_tick(name, date):
if (len(name) != 6):
name = str(name)[0:6]
return QATs.get_tick_data(name, date)
def nosql():
import pymongo
import json
conn = pymongo.Connection('127.0.0.1', port=27017)
df = ts.get_tick_data('600848',date='2014-12-22')
print(df.to_json(orient='records'))
conn.db.tickdata.insert(json.loads(df.to_json(orient='records')))
# print conn.db.tickdata.find()
def get_mount():
df = ts.get_tick_data('300141', date='2016-07-25')
df.plot()
print df
def getBigVol(code):
#???????
#today_vol=ts.get_today_ticks(code)
#hist_vol=ts.get_tick_data(code,date='2016-11-28')
#print today_vol.head(10)
#print hist_vol
hist_big_deal = ts.get_sina_dd(code, date='2016-12-01', vol=500)
if hist_big_deal is None:
print "No Big Deal"
else:
print hist_big_deal
def sql_store():
df = ts.get_tick_data('300333', date='2016-12-22')
df.to_sql('tick_data', engine)
#empty_type()
#exception_test()
#get_basic()
#detail_tushare()
#empty_type()
#exception_test()
#get_basic()
#detail_tushare()
#get_all_stock_id()
#get_real_time()
#get_mount()
#for_test()
#get_each_mount()
#plot_test2()
#save_excel()
#get_real_time()
#gsz()
#new_api()
#filename="mystock.txt"
#getStockList(filename)
#getBigVol('300527')
#get_real_time()
#get_k_test()
#holiday()
def get_tick(stockCode=None, date=None):
"""
???????????????/????????
Return
--------
DataFrame
"""
tick_data = ''
if date != None and date != '':
tick_data = ts.get_tick_data(stockCode, date)
else:
tick_data = ts.get_today_ticks(stockCode)
if not tick_data.dropna(axis=0, how='any', thresh=None).empty:
tick_data.insert(0, 'code', stockCode) #????????
return tick_data
def get_tick_data(self, code, t_date = None):
if t_date is None:
t_date = dataTime.datetimeRelative(delta = 0)
t_date = t_date.replace(' 00:00:00', '')
df = ts.get_tick_data(code, date = t_date)
df = self.format_date_to_datetime(df, t_date = t_date)
return df
def QA_fetch_get_stock_tick(name, date):
if (len(name) != 6):
name = str(name)[0:6]
return QATs.get_tick_data(name, date)
def fetch_tick(stock, date):
with timer(logtime("ts.get_tick_data('%s', date='%s')" % (stock, date))):
df = await wait_concurrent(event_loop, proc_pool, ts.get_tick_data, stock, date=date, pause=0.1)
if df is None or (len(df) > 0 and "??????" in df['time'][0]):
# no data found
logging.debug("no tick data for stock: ts.get_tick_data('%s', date='%s')" % (stock, date))
return
# with timer(logtime("tick_data_proc")):
df['stock'] = stock
df['time'] = (date + ' ' + df['time']).map(lambda x: pd.Timestamp(datetime.strptime(x, time_fmt)).strftime(format="%Y-%m-%d %H:%M:%S%z"))
return tick_buffer.proc_data(df)
Filter_Stock_Cashflow_CHN.py 文件源码
项目:StockRecommendSystem
作者: doncat99
项目源码
文件源码
阅读 30
收藏 0
点赞 0
评论 0
def updating_stock_tick_data(root_path, exception_df, symbol, date_list):
file_path = root_path + "/Data/CSV/tick/" + symbol + "/"
exception_file = root_path + "/Data/CSV/exception/" + symbol + ".csv"
if os.path.exists(file_path) == False:
os.mkdir(file_path)
now_date = (datetime.datetime.now()).strftime("%Y-%m-%d")
need_update_exception = False
need_update_data = False
#pbar = trange(len(date_list), leave=False)
#for i in pbar:
temp_list = []
for date in date_list:
#start = time.time()
#date = date_list[i]
new_file_name = file_path + symbol + "_" + date + ".csv"
if os.path.exists(new_file_name):
continue
try:
temp_list.append(date)
data = ts.get_tick_data(symbol ,date=date, src ='tt')
except:
print("stock:", symbol, " date:", date, "get data failed")
if data is not None:
need_update_data = True
data.to_csv(new_file_name)
else:
need_update_exception = True
exception_df.loc[len(exception_df)] = [date, 1, now_date]
# print("tick data", symbol, date, "is None")
#outMessage = '%s processed in: %.4s seconds' % (date, (time.time() - start))
#pbar.set_description(outMessage)
if need_update_exception:
exception_df = exception_df.groupby(["date"]).agg({'retry':'sum', 'last_update':'max'}).reset_index()
exception_df.to_csv(exception_file)
if len(temp_list) > 0: print(symbol, temp_list)
return need_update_data