sync_stock / test_stock_basic.py
superxu520's picture
"feat:add-tushare-adapter-with-dual-token"
c4a2fde
# -*- coding: utf-8 -*-
"""
测试 stock_basic 接口返回的数据
"""
import tushare as ts
import pandas as pd
import time
TOKEN = "432d609bd03a0283be53b058912cc563eeb5f24092b53f3dcfd2e358"
ts.set_token(TOKEN)
pro = ts.pro_api()
print("=" * 80)
print("Tushare stock_basic - 详细数据测试")
print("=" * 80)
# 等待避免限流
time.sleep(65)
print("\n1. 获取股票基础信息...")
try:
df = pro.stock_basic(exchange='', list_status='L',
fields='ts_code,symbol,name,area,industry,fullname,enname,cnspell,market,exchange,curr_type,list_status,list_date,delist_date,is_hs')
print(f"\n总股票数: {len(df)}")
print(f"\n数据列(字段):")
for i, col in enumerate(df.columns, 1):
print(f" {i}. {col}")
print(f"\n\n前5条数据示例:")
print(df.head().to_string(index=False))
print(f"\n\n数据统计:")
print(f" - 沪市股票: {len(df[df['exchange']=='SSE'])}")
print(f" - 深市股票: {len(df[df['exchange']=='SZSE'])}")
print(f" - 北交所: {len(df[df['exchange']=='BSE'])}")
print(f" - 行业数量: {df['industry'].nunique()}")
print(f" - 地区数量: {df['area'].nunique()}")
print(f"\n\n行业分布(前10):")
print(df['industry'].value_counts().head(10).to_string())
print(f"\n\n地区分布(前10):")
print(df['area'].value_counts().head(10).to_string())
print(f"\n\n上市日期范围:")
print(f" 最早: {df['list_date'].min()}")
print(f" 最晚: {df['list_date'].max()}")
except Exception as e:
print(f"ERROR: {e}")
print("\n" + "=" * 80)