本文整理匯總了Python中tushare.get_tick_data方法的典型用法代碼示例。如果您正苦於以下問題:Python tushare.get_tick_data方法的具體用法?Python tushare.get_tick_data怎麽用?Python tushare.get_tick_data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tushare
的用法示例。
在下文中一共展示了tushare.get_tick_data方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getStockTickHistory
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_tick_data [as 別名]
def getStockTickHistory(self,dbName,stockCode):
try:
db = self._Conn[dbName]
collection = db.get_collection(stockCode)
date = self.extractData("NBD","nbd_news_company",['date'])[0]
begin_date = min(date).split(' ')[0]
date_list = self.getCalendar(begin_date)
for dt in date_list:
tickDataOfEachDate = ts.get_tick_data(stockCode,date=dt)
if not math.isnan(tickDataOfEachDate['price'][0]): #exist data at that day
data = {}
for i in range(len(tickDataOfEachDate)-1,-1,-1):
data.update({'date' : dt})
data.update({'time' : tickDataOfEachDate['time'][i]})
data.update({'price' : tickDataOfEachDate['price'][i]})
data.update({'change' : tickDataOfEachDate['change'][i]})
data.update({'volume' : int(tickDataOfEachDate['volume'][i])})
data.update({'amount' : int(tickDataOfEachDate['amount'][i])})
data.update({'type' : tickDataOfEachDate['type'][i]})
collection.insert_one(data)
data = {}
print(dt + ' crawl finished ... ')
except Exception:
traceback.print_exc()
示例2: QA_fetch_get_stock_tick
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_tick_data [as 別名]
def QA_fetch_get_stock_tick(name, date):
if (len(name) != 6):
name = str(name)[0:6]
return ts.get_tick_data(name, date)
示例3: db
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_tick_data [as 別名]
def db():
df = ts.get_tick_data('600848',date='2014-12-22')
engine = create_engine('mysql://root:jimmy1@127.0.0.1/mystock?charset=utf8')
# db = MySQLdb.connect(host='127.0.0.1',user='root',passwd='jimmy1',db="mystock",charset="utf8")
# df.to_sql('TICK_DATA',con=db,flavor='mysql')
# db.close()
df.to_sql('tick_data',engine,if_exists='append')
示例4: nosql
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_tick_data [as 別名]
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()
示例5: updating_stock_tick_data
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_tick_data [as 別名]
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