我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用tushare.get_today_all()。
def get_basic(): hsdq = stock_info.ix['300141'] print hsdq report = ts.get_report_data(2014, 1) print report #hsdq=stock_info.ix['300141'] #print hsdq #report=ts.get_report_data(2014,1) #print report print '*' * 20 df = ts.get_today_all() zrkj = df[df['code'] == '300333'] print type(zrkj) print type(zrkj['code']) print zrkj['name'].values[0]
def GetAllTodayData(self): #???? ???? ?,?????????? filename=self.today+'_all_.xls' #??data???? filename=os.path.join(self.path,filename) if not os.path.exists(filename): self.df_today_all=ts.get_today_all() #????? self.df_today_all.drop(self.df_today_all[self.df_today_all['turnoverratio']==0].index,inplace=True) #?????????? #n1=self.df_today_all[self.df_today_all['turnoverratio']==0] #n2=self.df_today_all.drop(n1.index) #print n2 print self.df_today_all self.df_today_all.to_excel(filename,sheet_name='All') else: self.df_today_all=pd.read_excel(filename,sheet_name='All') print "File existed"
def main(): # ?????? ?3???? history = ts.get_hist_data(id) print u"??3????" print history.head(10) history_all = ts.get_h_data(id, '20015101', '20160101') print u'???????' print history_all # print type(stockInfo) # print stockInfo.head() # print stockInfo.dtypes # df = ts.get_stock_basics() #data = df.ix[id]['timeToMarket'] #print data #ts.get_today_all()
def general_info(): t_all = ts.get_today_all() result = [] t1 = t_all[t_all['changepercent'] <= -9.0].count()['changepercent'] result.append(t1) for i in range(-9, 9, 1): temp = t_all[(i * 1.00 < t_all['changepercent']) & (t_all['changepercent'] <= (i + 1) * 1.00)].count()[ 'changepercent'] result.append(temp) t2 = t_all[t_all['changepercent'] > 9.0].count()['changepercent'] result.append(t2) return result #test in sourcetree #test in house #????
def QA_fetch_get_stock_realtime(): data = QATs.get_today_all() data_json = QA_util_to_json_from_pandas(data) return data_json
def filter_stock_by_average_pe(min, max): path = os.path.join(current_folder, '3????????????%s.csv' % today) if not os.path.exists(path): # ?????3??????? calcu_all_stocks_3year_average_profit(calcu_average_profit_end_year) gplb = pd.read_csv(path, index_col=0, encoding='utf-8') # ???????? price_path = os.path.join(current_folder, today + '????.csv') if not os.path.exists(price_path): ts.get_today_all().set_index('code').to_csv(price_path, encoding="utf-8") current_price = pd.read_csv(price_path, encoding="utf-8", index_col=0) current_price = current_price[['trade']] current_price.columns = ['??'] gplb = gplb[ ['??', '??', '??', '????', '???', '???(?)', '????', '????', '????', '???', '????', '????']] data = pd.merge(gplb, current_price, left_index=True, right_index=True) # ?????????????????????????????? data['?????'] = data['???'] * data['??'] * 10000 / data['????'] print('%s:' % today) print() print('%d???' % data.shape[0]) print('3???????%.1f' % round(data['?????'].median(), 1)) print('3???????%.1f' % round(data['???'].median(), 1)) data = data[data['?????'] < max] data = data[data['?????'] > min] data['?????'] = data['?????'].round(1) data['????'] = data['????'].round() data['???'] = data['???'].round(1) data['????'] = data['????'].round() data['????'] = data['????'].round() data['???'] = data['???'].round() data['????'] = data['????'].round() average_pe_file = os.path.join(current_folder, today + '-3???????%s?%s?????.xlsx' % (min, max)) data.to_excel(average_pe_file)
def get_real_time(): df = ts.get_today_all() print df
def save_excel(): df = ts.get_today_all() df.to_excel('1.xls', sheet_name='all_stock') df2 = ts.get_hist_data('300333') df2.to_excel('1.xls', sheet_name='basic_info') df.ExcelWriter out = pd.ExcelWriter("2.xls") df.to_excel()
def gsz(): hq = ts.get_today_all() hq['trade'] = hq.apply(lambda x: x.settlement if x.trade == 0 else x.trade, axis=1) basedata = stock_info[['outstanding', 'totals', 'reservedPerShare', 'esp']] hqdata = hq[['code', 'name', 'trade', 'mktcap', 'nmc']] hqdata = hqdata.set_index('code') data = basedata.merge(hqdata, left_index=True, right_index=True) print data.head(10)
def basic_usage(): df = ts.get_today_all() print df[df['code'] == '000006'] # print df.to_excel('tets.xls') #print df[df['code']=='000006']
def get_today_all(): print "[%s] get_today_all" %(datetime.now().strftime("%H:%M:%S.%f")) df = ts.get_today_all() filename = PREFIX + '/' + 'today_all.csv' os.remove(filename) return save_to_file(filename, df)
def get_target(self): # lc = ts.get_today_all() # lc.to_csv('a.txt',encoding="utf-8") lc = pd.read_csv('a.txt',encoding='utf-8') lc_amount = lc.query('amount>10000000') lc_amount_except_ST = lc_amount[(lc_amount['name'].str.contains(stRegex, regex=True))] res = lc_amount_except_ST.sort_values(by="mktcap").head(self.__cnt) # print(res) # res = res[['code','name','trade','amount']] self.__target = res[['code','name','trade']] self.__target['share'] = 0 self.__target['action'] = ''
def daily_market(): df = ts.get_today_all() try: df.to_sql(SaveData.today,daily_engine,if_exists='replace') except Exception,e: print e print "Save {} data to MySQL".format(SaveData.today)
def __init__(self): self.today_stock=ts.get_today_all() now=datetime.datetime.now() self.today=now.strftime("%Y-%m-%d") #weekday=now+datetime.timedelta(days=-2) #weekday=weekday.strftime("%Y-%m-%d") #print weekday #today=now.strftime('%Y-%m-%d') self.path=os.path.join(os.getcwd(),'data') self.filename=os.path.join(self.path,'recordMyChoice.xls')
def daily_market(self): ''' ???????????? :return: ''' df = ts.get_today_all() print df try: df.to_sql(self.today, daily_engine, if_exists='replace') except Exception, e: print e print "Save {} data to MySQL".format(self.today)
def base_function(self, id): if id == None: print "Input stock id please " return stockInfo = ts.get_hist_data(id) # print type(stockInfo) # print stockInfo.head() # print stockInfo.dtypes df = ts.get_stock_basics() data = df.ix[id]['timeToMarket'] print data all_data = ts.get_today_all() print all_data.ix[id]['name']
def realtime(self, id): # all_stock=ts.get_today_all() # print all_stock df = ts.get_realtime_quotes(id) # print df[['time','name','price','bid','ask','volume']] # print df.head() # price_change = ts.get_today_ticks(id) # print price_change[['time','change','type','volume']] big_share = ts.get_sina_dd(id, date=self.date) print big_share[['time', 'code', 'price', 'preprice', 'volume', 'type']] print big_share.sort(columns='volume')
def main(): now = time.strftime("%Y-%m-%d") # print now token = '60517739976b768e07823056c6f9cb0fee33ed55a1709b3eaa14a76c6a1b7a56' sb = StockBox() # sb.looper(id) id = '300333' # sb.realtime(id) sb.base_function("300333") # pandas_test=Pandas_test() # pandas_test.test_function() # sb.longhuban('2016-04-05') # sb.getNews() # sb.fund() #sb.get_stock_chengfeng() #sb.date_store() #sb.profit_test() #sb.daily_longhu() # ?????? ?3???? history = ts.get_hist_data(id) print u"??3????" print history.head(10) history_all = ts.get_h_data(id, '20015101', '20160101') print u'???????' print history_all # print type(stockInfo) # print stockInfo.head() # print stockInfo.dtypes #df = ts.get_stock_basics() #data = df.ix[id]['timeToMarket'] #print data #ts.get_today_all()
def realtime(self, id): # all_stock=ts.get_today_all() # print all_stock df = ts.get_realtime_quotes(id) # print df[['time','name','price','bid','ask','volume']] # print df.head() price_change = ts.get_today_ticks(id) print price_change[['time', 'change', 'type', 'volume']] big_share = ts.get_sina_dd(id, date='2016-04-01') print big_share[['time', 'code', 'price', 'preprice', 'volume', 'type']]
def stat_today_all(tmp_datetime): datetime_str = (tmp_datetime).strftime("%Y-%m-%d") datetime_int = (tmp_datetime).strftime("%Y%m%d") print("datetime_str:", datetime_str) print("datetime_int:", datetime_int) data = ts.get_today_all() # ?????????????????????????concat???? if not data is None and len(data) > 0: # ?????? # del data["reason"] data["date"] = datetime_int # ??????int??? data = data.drop_duplicates(subset="code", keep="last") data.head(n=1) common.insert_db(data, "ts_today_all", False, "`date`,`code`") else: print("no data .") time.sleep(5) # ??5? data = ts.get_index() # ?????????????????????????concat???? if not data is None and len(data) > 0: # ?????? # del data["reason"] data["date"] = datetime_int # ??????int??? data = data.drop_duplicates(subset="code", keep="last") data.head(n=1) common.insert_db(data, "ts_index_all", False, "`date`,`code`") else: print("no data .") print(datetime_str) # main????
def QA_fetch_get_stock_realtime(): data = QATs.get_today_all() data_json = json.loads(data.to_json(orient='records')) return data_json
def plot_days(): if request.method == 'GET' : today = ts.get_today_all() code_info = ts.get_industry_classified() today['code'] = today['code'].astype(unicode) one_day = gd.get_data_real_time(code_info, today) body = heatmap.get_heatmap('Today', one_day) return render_template('heatmap.html', body=body)
def update_market(): df = ts.get_today_all() engine = create_engine('mysql://root:@127.0.0.1/stock_1.0?charset=utf8') #????? df.to_sql('current_market',engine,if_exists='replace') print("Done")
def get_today_codes(): stock_basics = ts.get_today_all() return stock_basics.code.values