Files
real_view/测试sina.py
2025-07-28 12:15:45 +08:00

38 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import tushare as ts
# 从环境变量读取Token需提前设置环境变量TUSHARE_TOKEN
ts.set_token('9343e641869058684afeadfcfe7fd6684160852e52e85332a7734c8d')
pro = ts.pro_api()
try:
# 定义股票代码列表,提升可维护性
# sina数据
# 东财数据
df1 = ts.realtime_list(src='dc')
# sina数据
df2 = ts.realtime_list(src='sina')
stock_codes = ['300296.SZ', '300328.SZ']
# dc_df = ts.realtime_list(src='dc')
df = ts.realtime_quote(ts_code=','.join(stock_codes))
print(df)
# 检查数据有效性
if not df.empty:
print("所有列名:", df.columns.tolist())
# 根据实际列名调整(假设列名为小写)
required_columns = ['HIGH', 'LOW', 'PRICE']
if all(col in df.columns for col in required_columns):
print(df[required_columns])
print(df['HIGH'])
else:
print("列名不匹配,请检查数据源列名格式")
else:
print("获取数据失败返回空DataFrame")
except Exception as e:
print(f"发生错误: {str(e)}")