fix:修改tushare接口为vip接口,需要5000积分以上。

This commit is contained in:
2026-08-03 16:41:14 +08:00
parent 7a5a109b4f
commit b9e288b0a6
2 changed files with 13 additions and 13 deletions
+12 -12
View File
@@ -313,7 +313,7 @@ def import_daily_for_stock(ts_code: str, start_date: str, end_date: str, conn) -
pro = get_ts_pro() pro = get_ts_pro()
def fetch(): def fetch():
return pro.daily( return pro.daily_vip(
ts_code=ts_code, ts_code=ts_code,
start_date=start_date.replace("-", ""), start_date=start_date.replace("-", ""),
end_date=end_date.replace("-", ""), end_date=end_date.replace("-", ""),
@@ -371,7 +371,7 @@ def import_daily_by_date(
): ):
""" """
按交易日批量导入日线行情 (高效模式) 按交易日批量导入日线行情 (高效模式)
使用 pro.daily(trade_date='YYYYMMDD') 一次性拉取全市场当日数据 使用 pro.daily_vip(trade_date='YYYYMMDD') 一次性拉取全市场当日数据
大幅减少 API 调用次数: 约250交易日/年 × 16年 ≈ 4000次 (原来需要 5000股票 × 16年 = 80000次) 大幅减少 API 调用次数: 约250交易日/年 × 16年 ≈ 4000次 (原来需要 5000股票 × 16年 = 80000次)
参数: 参数:
@@ -462,7 +462,7 @@ def import_daily_by_date(
td_str = td.strftime("%Y%m%d") if hasattr(td, "strftime") else str(td).replace("-", "") td_str = td.strftime("%Y%m%d") if hasattr(td, "strftime") else str(td).replace("-", "")
def fetch(): def fetch():
return pro.daily(trade_date=td_str) return pro.daily_vip(trade_date=td_str)
df = fetch_with_retry(fetch, max_retries=3) df = fetch_with_retry(fetch, max_retries=3)
if df is None or df.empty: if df is None or df.empty:
@@ -565,7 +565,7 @@ def import_daily_basic(
kwargs["trade_date"] = trade_date.replace("-", "") kwargs["trade_date"] = trade_date.replace("-", "")
def fetch(): def fetch():
return pro.daily_basic(**kwargs) return pro.daily_basic_vip(**kwargs)
df = fetch_with_retry(fetch, max_retries=2) df = fetch_with_retry(fetch, max_retries=2)
if df is None or df.empty: if df is None or df.empty:
@@ -631,7 +631,7 @@ def import_daily_basic_by_date(
pro = get_ts_pro() pro = get_ts_pro()
def fetch_daily_basic(): def fetch_daily_basic():
return pro.daily_basic(trade_date=td) return pro.daily_basic_vip(trade_date=td)
df = fetch_with_retry(fetch_daily_basic, max_retries=3) df = fetch_with_retry(fetch_daily_basic, max_retries=3)
if df is not None and not df.empty: if df is not None and not df.empty:
@@ -685,7 +685,7 @@ def import_adj_factor(
kwargs["ts_code"] = ts_code kwargs["ts_code"] = ts_code
def fetch(): def fetch():
return pro.adj_factor(**kwargs) return pro.adj_factor_vip(**kwargs)
df = fetch_with_retry(fetch, max_retries=2) df = fetch_with_retry(fetch, max_retries=2)
if df is None or df.empty: if df is None or df.empty:
@@ -770,10 +770,10 @@ def import_financial_statements(
for i, ts_code in enumerate(stock_list, 1): for i, ts_code in enumerate(stock_list, 1):
for table_name, fetch_method in [ for table_name, fetch_method in [
("income", pro.income), ("income", pro.income_vip),
("balancesheet", pro.balancesheet), ("balancesheet", pro.balancesheet_vip),
("cashflow", pro.cashflow), ("cashflow", pro.cashflow_vip),
("fina_indicator", pro.fina_indicator), ("fina_indicator", pro.fina_indicator_vip),
]: ]:
try: try:
if table_name == "fina_indicator": if table_name == "fina_indicator":
@@ -855,7 +855,7 @@ def import_index_daily(
for idx_code in index_codes: for idx_code in index_codes:
try: try:
def fetch(): def fetch():
return pro.index_daily( return pro.index_daily_vip(
ts_code=idx_code, ts_code=idx_code,
start_date=start_date.replace("-", ""), start_date=start_date.replace("-", ""),
end_date=end_date.replace("-", ""), end_date=end_date.replace("-", ""),
@@ -1268,7 +1268,7 @@ def resume_daily_by_date(
td_compact = td_str.replace("-", "") td_compact = td_str.replace("-", "")
def fetch(): def fetch():
return pro.daily(trade_date=td_compact) return pro.daily_vip(trade_date=td_compact)
df = fetch_with_retry(fetch, max_retries=3) df = fetch_with_retry(fetch, max_retries=3)
if df is None or df.empty: if df is None or df.empty:
+1 -1
View File
@@ -260,7 +260,7 @@
"---\n", "---\n",
"## Step 4: 导入日线行情 (核心表,最耗时)\n", "## Step 4: 导入日线行情 (核心表,最耗时)\n",
"\n", "\n",
"> **新版改进:** 按交易日循环拉取全市场数据 `pro.daily(trade_date='20180810')`\n", "> **新版改进:** 按交易日循环拉取全市场数据 `pro.daily_vip(trade_date='20180810')`VIP接口)\n",
"> API 调用从 ~80,000次 (5000只×16年) 降至 ~4,000次 (250交易日×16年),速度提升约 **20倍**。\n", "> API 调用从 ~80,000次 (5000只×16年) 降至 ~4,000次 (250交易日×16年),速度提升约 **20倍**。\n",
"\n", "\n",
"### 4.1 按年批量导入 (推荐)\n", "### 4.1 按年批量导入 (推荐)\n",