#!/usr/bin/env python3 """ 测试日线数据API """ import akshare as ak import pandas as pd import sys print("测试AKShare日线数据API...") print(f"AKShare版本: {ak.__version__}") # 测试不同的参数格式 test_cases = [ {"symbol": "sh000001", "name": "上证指数-sh格式"}, {"symbol": "sz000001", "name": "平安银行-sz格式"}, {"symbol": "000001", "name": "平安银行-纯代码"}, ] for test in test_cases: print(f"\n{'='*60}") print(f"测试: {test['name']} - {test['symbol']}") print(f"{'='*60}") try: df = ak.stock_zh_a_daily( symbol=test['symbol'], start_date="20240101", end_date="20241231", adjust="hfq" ) if df is not None and not df.empty: print(f"✅ 成功! 获取到 {len(df)} 条记录") print(f"列名: {list(df.columns)}") print(f"前5行:\n{df.head()}") else: print(f"❌ 失败! 返回空数据") except Exception as e: print(f"❌ 异常: {e}") # 尝试新接口 print(f"\n{'='*60}") print("尝试新接口: stock_zh_a_hist") print(f"{'='*60}") try: df = ak.stock_zh_a_hist( symbol="000001", period="daily", start_date="20240101", end_date="20241231", adjust="hfq" ) if df is not None and not df.empty: print(f"✅ 成功! 获取到 {len(df)} 条记录") print(f"列名: {list(df.columns)}") print(f"前5行:\n{df.head()}") except Exception as e: print(f"❌ 异常: {e}")