"""시가총액 backfill: per-ticker get_market_cap_by_date 재시도""" import sqlite3, time from pykrx import stock conn = sqlite3.connect("data/edf.db") # 샘플 5개로 정확한 API 동작 확인 tickers = ["005930", "000660", "005380", "035720", "068270"] for tk in tickers: print(f"\n=== {tk} ===") # Method 1: get_market_cap_by_date (fromdate, todate, ticker) try: cap = stock.get_market_cap_by_date("20250301", "20250307", tk) time.sleep(0.3) print(f" cap_by_date: {len(cap)} rows") if len(cap) > 0: print(f" columns: {list(cap.columns)}") print(cap.tail(2)) except Exception as e: print(f" cap_by_date ERROR: {e}") # Method 2: get_market_fundamental_by_date try: fund = stock.get_market_fundamental_by_date("20250301", "20250307", tk) time.sleep(0.3) print(f" fundamental: {len(fund)} rows, columns: {list(fund.columns)}") except Exception as e: print(f" fundamental ERROR: {e}") # Method 3: get_exhaustive_info try: cap = stock.get_market_cap_by_ticker("20250307") time.sleep(0.3) if tk in cap.index: print(f" cap_by_ticker: 시총={cap.loc[tk, '시가총액']:,.0f}, 주식수={cap.loc[tk, '상장주식수']:,}") else: print(f" cap_by_ticker: {tk} not found, total rows={len(cap)}") break # 한번만 호출 (전체 시장 데이터) except Exception as e: print(f" cap_by_ticker ERROR: {e}")