本文整理匯總了Python中tushare.get_today_all方法的典型用法代碼示例。如果您正苦於以下問題:Python tushare.get_today_all方法的具體用法?Python tushare.get_today_all怎麽用?Python tushare.get_today_all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tushare
的用法示例。
在下文中一共展示了tushare.get_today_all方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _getStockCodesFromTuShare
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
def _getStockCodesFromTuShare(self):
self._info.print("開始從TuShare獲取股票代碼表...")
try:
df = ts.get_today_all() # it's slow because TuShare will get one page by one page
except Exception as ex:
self._info.print("從TuShare獲取股票代碼表異常: {}".format(ex), DyLogData.error)
return None
if df is None or df.empty:
self._info.print("從TuShare獲取股票代碼表為空", DyLogData.error)
return None
codes = {}
data = df[['code', 'name']].values.tolist()
for code, name in data:
if code[0] == '6':
codes[code + '.SH'] = name
else:
codes[code + '.SZ'] = name
self._info.print("從TuShare獲取股票代碼表成功")
return codes
示例2: download_realtime_stock_price
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
def download_realtime_stock_price():
"""
# 下載股票的實時行情
:return:
"""
try:
engine = db.get_w_engine()
df_price = ts.get_today_all()
stock_time = GetNowTime()
if stock_time[11:] > "15:00:00":
stock_time = stock_time[:11] + "15:00:00"
df_price['date'] = stock_time
# df_price.to_sql(STOCK_REALTIME_TABLE, engine, if_exists='append', index=False)
to_sql(STOCK_REALTIME_TABLE, engine, df_price, type='replace')
except Exception as e:
print(e)
#######################
## private methods ##
#######################
示例3: _getStockCodesFromTuShare
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
def _getStockCodesFromTuShare(self):
try:
df = ts.get_today_all() # it's slow because TuShare will get one page by one page
except Exception as ex:
return None
if df is None or df.empty:
return None
codes = {}
data = df[['code', 'name']].values.tolist()
for code, name in data:
if code[0] == '6':
codes[code + '.SH'] = name
else:
codes[code + '.SZ'] = name
return codes
示例4: QA_fetch_get_stock_realtime
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
def QA_fetch_get_stock_realtime():
data = ts.get_today_all()
data_json = QA_util_to_json_from_pandas(data)
return data_json
示例5: stat_today_all
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
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函數入口
示例6: filter_by_roe
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
def filter_by_roe(min): # 篩選出最近5年ROE都高於min的公司
path = os.path.join(current_folder, '3年平均利潤及其他財務指標%s.csv' % today)
if not os.path.exists(path): # 沒有就生成3年平均利潤列表
calcu_all_stocks_3year_roe_and_average_profit(
calcu_average_profit_end_year)
gplb = pd.read_csv(path, index_col=0, encoding='utf-8')
gplb = gplb[gplb['當年roe'] > min]
gplb = gplb[gplb['上1年roe'] > min]
gplb = gplb[gplb['上2年roe'] > min]
gplb = gplb[gplb['上3年roe'] > min]
gplb = gplb[gplb['上4年roe'] > min]
# 獲取當前股票價格
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[[
'名字', '行業', '地區', '流通股本', '總股本', '總資產(萬)', '流動資產', '固定資產', '每股淨資',
'市淨率', '上市日期', '平均利潤', '當年roe', '上1年roe', '上2年roe', '上3年roe', '上4年roe'
]]
data = pd.merge(gplb, current_price, left_index=True, right_index=True)
# 因為這裏的平均利潤單位是萬元,而總股本單位是億,價格單位是元
data['平均市盈率'] = data['總股本'] * data['價格'] * 10000 / data['平均利潤']
data['平均市盈率'] = data['平均市盈率'].round(1)
data['市淨率'] = data['市淨率'].round(1)
high_roe_file = os.path.join(current_folder,
today + f'-最近5年ROE都高於{min}%的公司.xlsx')
data.to_excel(high_roe_file, encoding='utf-8')
示例7: k_today
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
def k_today():
return ts.get_today_all()
示例8: getLiveChinaStockPrice
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
def getLiveChinaStockPrice(stockCode):
try:
exchange = "sh" if (int(stockCode) // 100000 == 6) else "sz"
dataUrl = "http://hq.sinajs.cn/list=" + exchange + stockCode
stdout = urllib2.urlopen(dataUrl)
stdoutInfo = stdout.read().decode('gb2312').encode('utf-8')
# 正則表達式說明
# 搜索 “ ”雙引號內的字符串,包含換行符,將匹配的字符串分為三組:用()表示
# group(2):取第二組數據
tempData = re.search('''(")(.+)(")''', stdoutInfo).group(2)
stockInfo = tempData.split(",")
#bb[0]:股票名 bb[1]:今日開盤價 bb[2]:昨日收盤價 bb[3]:當前價格 bb[4]:今日最高價 bb[5]:今日最低價
#bb[6]:買一報價 bb[7]:賣一報價 bb[8]:成交股票數/100 bb[9]:成交金額/w bb[10]:買一申請股數 bb[11]:買一報價
#bb[12]:買二股數 bb[13]:買二報價 bb[14]:買三股數 bb[15]:買三報價 bb[16]:買四申請股數 bb[17]:買四報價
#bb[18]:買五股數 bb[19]:買五報價 bb[20]:賣一股數 bb[21]:賣一報價 bb[22]:賣二申請股數 bb[23]:賣二報價
#bb[24]:賣三股數 bb[25]:賣三報價 bb[26]:賣四股數 bb[27]:賣四報價 bb[28]:賣五股數 bb[29]:賣五報價
#bb[30]:日期 bb[31]:時間 bb[8]:不知道
return st.Stock(stockInfo)
except Exception as e:
print(">>>>>> Exception: " + str(e))
finally:
None
# 獲取A股所有股票的實時股價
# 通過 ts.get_today_all 獲取
示例9: get_real_price_dataframe
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
def get_real_price_dataframe():
df = ts.get_today_all()
return df
示例10: get_stock_price
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
def get_stock_price(code, include_realtime_price):
"""
獲取個股股價
:param code: 股票代碼
:param include_realtime_price: 是否含實時股價
:return:
"""
# 獲取曆史股價
df = ts.get_hist_data(code)
df = df[['close']]
df['date'] = df.index
if include_realtime_price:
df_today = ts.get_today_all()
df_code = df_today[df_today['code']==code]
df_code = df_code[['trade']]
df_code['date'] = GetNowDate()
df_code.rename(columns={'trade': 'close'}, inplace=True)
df = pd.concat([df, df_code], ignore_index=True)
df.sort(columns='date', inplace=True)
df = df.drop_duplicates(['date'])
df.index = range(len(df))
print '\n'
# print df.head()
print df.tail()
return df
示例11: plot_days
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
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)
示例12: filter_stock_by_average_pe
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_today_all [as 別名]
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_roe_and_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('\n%s:' % today)
print()
print('%d個公司' % data.shape[0])
print('3年市盈率中位數%.1f' % round(data['平均市盈率'].median(), 1))
print('市淨率中位數%.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, encoding='utf-8')