本文整理汇总了Python中tushare.get_tick_data函数的典型用法代码示例。如果您正苦于以下问题:Python get_tick_data函数的具体用法?Python get_tick_data怎么用?Python get_tick_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_tick_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_tick
def get_tick(code, start, end=None, file=None):
date = get_dates(start, end)
if not file:
file = '-'.join([code, start.replace('-', ''), str(len(date))]) + r'.csv'
for d in date:
df = ts.get_tick_data(code, date=d)
df.to_csv(file, mode='a')
示例2: multi_write
def multi_write((code,start_date,end_date)):
startdate=datetime.datetime.strptime(start_date,'%Y-%m-%d').date()
enddate = datetime.datetime.strptime(end_date, '%Y-%m-%d').date()
#string-to-dateobject conversion
date_list=date_loop.date_loop(start_date= startdate,end_date= enddate)
#return a list of dates
DTS=[]
for dates in date_list:
preDTS = ts.get_tick_data(code, date=dates)
#DTS=Data To be Saved
try:
preDTS['type'][0].split()
#throw an AttributeError when no data is available
preDTS['date'] = dates
#insert date column
preDTS=preDTS.sort_values(by='time',ascending= True)
#sql table will be named like 'hist_Part0,1,2,3,4...'
DTS.append(preDTS)
except AttributeError:
print 'No available data for ', dates
try:
DTS = pd.concat(DTS)
except ValueError :
DTS=None
return DTS
示例3: request_test_tick
def request_test_tick(code, engine, start_date, end_date):
create_test_talbe(code)
cur_day = start_date
logging.info('requesting tick, code: ' + code + str(threading.currentThread()))
while cur_day != end_date:
try:
#logging.info('cur_day: ' + str(cur_day) + str(threading.currentThread()))
tick = ts.get_tick_data(code, date=cur_day.date(), retry_count=500, src='tt')
if not tick.empty:
if tick.time[0] != 'alert("当天没有数据");':
tick['type'] = tick['type'].apply(lambda x: trade_type_dic[x])
tick['change'] = tick['change'].apply(change_dic)
tick['time'] = str(cur_day.date()) + ' '+ tick['time']
tick.to_sql('test_' + code, engine, if_exists='append', dtype={'time': DateTime})
logging.info('save to test_' + code + ' on '+ str(cur_day) + ' thread ' + str(threading.currentThread()))
except Exception:
logging.error(str(code) + ' request tick failed on ' + str(cur_day) + str(threading.currentThread()))
delta = datetime.timedelta(days=1)
cur_day = cur_day + delta
示例4: deal_list_download
def deal_list_download(self, stock, engine, start='2014-10-16'):
'''
分时数据下载
'''
deals = ts.get_tick_data(stock, date='2015-10-16')
table_name = stock + '_deal'
deals.to_sql(table_name, engine)
示例5: get_in_out
def get_in_out(symbol, date):
df = ts.get_tick_data(symbol, date=date, src='tt')
thre = df.amount.quantile(0.99)
thre = np.max([thre, 1e6])
in_amount = df[(df.amount>thre)&(df.type=="买盘")].amount.sum()/1e8
out_amount = df[(df.amount>thre)&(df.type=="卖盘")].amount.sum()/1e8
return [in_amount, out_amount]
示例6: get_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
示例7: get_tick_feng
def get_tick_feng(_stock_id, _trade_date):
df = None
try:
df = ts.get_tick_data(_stock_id, date=_trade_date, retry_count=5, pause=1)
except Exception:
log_error("warn: %s get ticks exception!", _stock_id)
time.sleep(5)
return None
if df is None :
log_error("warn: stock %s, %s is None, next", _stock_id, _trade_date)
return None
if df.empty:
log_error("warn: stock %s, %s is empty, next", _stock_id, _trade_date)
return None
if len(df) <= 5:
log_error("warn: stock %s, %s is short %d, next", _stock_id, _trade_date, len(df))
return None
df = df.set_index('time').sort_index()
return df
示例8: check_if_reach_limit
def check_if_reach_limit(code, date=datetime.now().strftime("%Y-%m-%d")):
"""
"""
kdata = ts.get_hist_data(code,date,date,ktype='D')
if kdata.ix[0]['p_change'] < 9.9:
return False
stock = ts.get_tick_data(code,date)[['time','price']]
indx, = np.where(np.diff(list(reversed(stock['price'])))==0)
# print "length: ", len(indx)
arr = []
beg = 0
cur = indx[0]-1
for i,val in enumerate(indx):
if cur+1 == val:
cur += 1
else:
if i > (beg+1):
arr.append((indx[beg], indx[i-1]))
beg = i
cur = val
arr.append((indx[beg],cur))
mindx = np.argmax([x[1]-x[0] for x in arr])
print "length of arr: ", len(arr)
p = arr[mindx][0]
print 'starting index: ', p
print 'starting time: ', stock.ix[stock.shape[0]-p-1]['time']
return stock.ix[stock.shape[0]-p-1]['time']
示例9: tick
def tick(tstamp):
date = tstamp.split(" ")[0]
tick_data = ts.get_tick_data(code,date=date,retry_count=10,pause=5)
nrows = tick_data.shape[0]
tick_data['date'] = pd.Series([date]*nrows)
return tick_data
示例10: get_sd
def get_sd(id, label_start_date, fea_delta = 240):
# delta 指的是 确定label;的时候 是一个星期的涨幅还是什么
# fea delta 指的是, 我要准备多久的数据
## 获取分笔数据
# get all time ticks
# 创建一个日期列表
ticks = None
date_list = dt_tool.dt_range(label_start_date, -fea_delta)
for date in date_list:
try:
tick = ts.get_tick_data(id, date)
except Exception, e:
print e
continue
if tick is None:
continue
tick.type = tick.type.apply(lambda x : type2id(x))
ft = tick.sort('amount', ascending=False).head(10).reset_index().drop(['index', 'time', 'change'], 1).stack().reset_index()
ft.index = ft.level_0.map(str) + '_' + ft.level_1
fT = ft.drop(['level_0', 'level_1'], 1).T
fT['date'] = dt_tool.format(date)
if ticks is None:
ticks = fT
else:
ticks = ticks.append(fT)
ticks.to_csv('data/ticks.csv', index=None)
示例11: pankou
def pankou(name):
# rang =pd.date_range('20150101', periods=5)
# a = ts.get_tick_data(code, rang)
a = ts.get_tick_data(name, date='2017-03-09')
buy_sum = 0
sell_sum = 0
other_sum = 0
for item in range(0, len(a)):
row = a[item:item + 1]
type = row['type']
if type[item] == '卖盘':
sell_sum += row['amount'][item]
elif type[item] == '买盘':
buy_sum += row['amount'][item]
else:
other_sum += row['amount'][item]
pan_sum = sum([sell_sum, buy_sum, other_sum])
mp = buy_sum / pan_sum
sp = sell_sum / pan_sum
zx = other_sum / pan_sum
# print('股票',code,(sell_sum, buy_sum, other_sum)/pan_sum)
print('股票', name, mp, sp, zx)
if isnan(mp):
return
with UseDatabase(config) as cursor:
_SQL = """insert into pankou
(name, mp, sp, zx)
values
(%s, %s, %s, %s)"""
cursor.execute(_SQL, (name, mp, sp, zx))
示例12: multi_write
def multi_write((start_date,end_date)):
startdate=datetime.datetime.strptime(start_date,'%Y-%m-%d').date()
enddate = datetime.datetime.strptime(end_date, '%Y-%m-%d').date()
#string-to-dateobject conversion
date_list=date_loop.date_loop(start_date= startdate,end_date= enddate)
#return a list of date
#engine=create_engine('mysql+mysqldb://root:[email protected]:3306/tusharedb?charset=utf8')
DTS=[]
for dates in date_list:
preDTS = ts.get_tick_data('600640', date=dates)
#DTS=Data To be Saved
try:
preDTS['type'][0].split()
#throw an AttributeError when no data is available
preDTS.sort_index(axis=0, ascending=True)
#reverse the dataframe with latest data placed at the bottom
preDTS['date'] = dates
#insert date column
#sql table will be named like 'hist_Part0,1,2,3,4...'
DTS.append(preDTS)
except AttributeError:
print 'No available data for ', dates
try:
DTS = pd.concat(DTS)
except ValueError :
DTS=None
return DTS
示例13: get_tick_history
def get_tick_history(exsymbol, days=10):
store = get_store(store_type)
dates = store.get('id000001').index
symbol = exsymbol_to_symbol(exsymbol)
df_res = pd.DataFrame(columns=["kaipan_vol", "kaipan_money", "shoupan_vol", "shoupan_money"])
for i in range(days, 0, -1):
date = dates[len(dates)-i].strftime("%Y-%m-%d")
df = ts.get_tick_data(symbol, date=date, src="tt")
if df is None or len(df) == 0:
continue
df["time"] = pd.to_datetime(df["time"], format='%H:%M:%S')
kaipan_time = df.iloc[0].time
kaipan_vol = 0
kaipan_money = 0
if kaipan_time.hour == 9 and kaipan_time.minute < 30:
kaipan_vol = df.iloc[0].volume
kaipan_money = df.iloc[0].amount
shoupan_time = df.iloc[len(df)-1].time
shoupan_vol = 0
shoupan_money = 0
if shoupan_time.hour >= 15 and shoupan_time.minute >= 0:
shoupan_vol = df.iloc[len(df)-1].volume
shoupan_money = df.iloc[len(df)-1].amount
df_res.loc[date] = [kaipan_vol, kaipan_money, shoupan_vol, shoupan_money]
return df_res
示例14: get_multiday_ave_compare_silent
def get_multiday_ave_compare_silent(code, dayl='10'):
dtick = ts.get_today_ticks(code)
d_hist = ema.getdata_ema_trend_silent(code, dayl, 'd')
# print d_hist
day_t = ema.get_today()
if day_t in d_hist.index:
dl = d_hist.drop(day_t).index
else:
dl = d_hist.index
# print dl
# print dl
ep_list = []
for da in dl.values:
# print code,da
td = ts.get_tick_data(code, da)
# print td
if not type(td) == types.NoneType:
ep = td['amount'].sum() / td['volume'].sum()
ep_list.append(ep)
# print ("D: %s P: %s" % (da[-5:], ep))
ave = ema.less_average(ep_list)
if len(dtick.index) > 0:
ep = dtick['amount'].sum() / dtick['volume'].sum()
p_now = dtick['price'].values[0] * 100
if p_now > ave or ep > ave:
print ("GOLD:%s ep:%s UP:%s!!! A:%s %s !!!" % (code, ep, p_now, ave, get_now_time()))
# elif p_now > ave and ep < ave:
# print ("gold:%s ep:%s UP:%s! A:%s %s !" % (code, ep, p_now, ave, get_now_time()))
# elif p_now < ave and ep > ave:
# print ("down:%s ep:%s Dow:%s? A:%s %s ?" % (code, ep, p_now, ave, get_now_time()))
return True
else:
if p_now < ave and ep < ave:
print ("DOWN:%s ep:%s now:%s??? A:%s %s ???" % (code, ep, p_now, ave, get_now_time()))
return False
示例15: __init__
def __init__(self, tableName):
'''
Constructor
'''
bdl.BaseDataLoader.__init__(self, tableName)
#self.db = msql.MySQLConnection.GetConnection()
#self.ml = mlg.MyLogger.getLogger()
#tradingday = datetime.strftime(datetime.today(), "%Y-%m-%d")
code = '600848'
tradingday = '2015-11-30'
self.ml.info("Loading Data")
data = ts.get_tick_data(code=code, date=tradingday)
data['tradingday'] = tradingday
data['code'] = code
indexdata = data.set_index(['tradingday', 'code'])
self.ml.info("Saving Data")
indexdata.to_sql(self.tableName, self.db, flavor="mysql", if_exists="append")
#关闭连接
#db.close()
self.ml.info("Saving Success")