현재가, 종목 기본정보, 일별 주가, 차트 데이터, 순위 정보를 조회하는 방법을 안내합니다.
현재가, 등락률, 재무지표(PER·PBR·EPS·ROE), 시가총액을 한번에 가져옵니다.
from kiwoompy import KiwoomClient
client = KiwoomClient(env="demo", appkey="...", secretkey="...")
info = client.query.get_stock_info("005930") # 삼성전자
print(f"종목명: {info.stk_nm}")
print(f"현재가: {info.cur_prc}원")
print(f"등락률: {info.flu_rt}%")
print(f"시가: {info.open_pric}원")
print(f"고가: {info.high_pric}원")
print(f"저가: {info.low_pric}원")
print(f"거래량: {info.trde_qty}주")
print(f"시가총액: {info.mac}원")
print(f"PER: {info.per}")
print(f"PBR: {info.pbr}")
print(f"EPS: {info.eps}원")
print(f"ROE: {info.roe}%")
print(f"52주 최고: {info.oyr_hgst}원")
print(f"52주 최저: {info.oyr_lwst}원")
현재가·호가·예상체결가 등을 포함한 종합 시세를 조회합니다.
summary = client.query.get_market_summary("005930")
print(f"현재가: {summary.cur_prc}원 ({summary.flu_rt}%)")
print(f"전일종가: {summary.pred_close_pric}원")
print(f"예상체결가: {summary.exp_cntr_pric}원 / {summary.exp_cntr_qty}주")
print(f"총매수잔량: {summary.tot_buy_req}주")
print(f"총매도잔량: {summary.tot_sel_req}주")
print(f"조회시각: {summary.date} {summary.tm}")
여러 종목의 현재가를 한 번에 조회합니다. 종목코드를 |로 구분합니다.
watchlist = client.query.get_watchlist_info("005930|000660|035720")
for item in watchlist.items:
print(f"{item.stk_nm}({item.stk_cd}): {item.cur_prc}원 ({item.flu_rt}%)")
시장별 전체 상장 종목 코드와 이름을 조회합니다.
# 코스피 종목 리스트
kospi = client.query.get_stock_list(market_type="kospi")
for item in kospi.items:
print(f"{item.stk_cd}: {item.stk_nm}")
# 코스닥 종목 리스트
kosdaq = client.query.get_stock_list(market_type="kosdaq")
지원하는 market_type 값: "kospi", "kosdaq", "etf", "elw", "konex", "gold" 등
특정 날짜 기준으로 일별 주가와 투자자별 순매수 데이터를 조회합니다.
daily = client.query.get_daily_prices(
stock_code="005930",
query_date="20240101",
display_type="qty", # "qty": 수량, "amount": 금액
)
for item in daily.items:
print(f"{item.dt}: 시{item.open_pric} 고{item.high_pric} 저{item.low_pric} 종{item.close_pric} 거래량{item.trde_qty}")
tick_chart = client.query.get_stock_tick_chart(
stock_code="005930",
tick_scope="3", # "1" / "3" / "5" / "10" / "30"
adjusted="adjusted", # "adjusted": 수정주가, "raw": 원주가
)
for candle in tick_chart.items[:5]:
print(f"시간: {candle.cntr_tm} 종가: {candle.cur_prc} 거래량: {candle.trde_qty}")
min_chart = client.query.get_stock_min_chart(
stock_code="005930",
min_scope="5", # "1" / "3" / "5" / "10" / "15" / "30" / "45" / "60"
adjusted="adjusted",
)
for candle in min_chart.items[:10]:
print(f"{candle.cntr_tm}: {candle.open_pric}/{candle.high_pric}/{candle.low_pric}/{candle.cur_prc} 거래량:{candle.trde_qty}")
day_chart = client.query.get_stock_day_chart(
stock_code="005930",
base_date="20240101", # 기준일자 (YYYYMMDD)
adjusted="adjusted",
)
for candle in day_chart.items[:20]:
print(f"{candle.dt}: 종가 {candle.cur_prc}원 거래량 {candle.trde_qty}주")
# 주봉
week_chart = client.query.get_stock_week_chart("005930", base_date="20240101")
# 월봉
month_chart = client.query.get_stock_month_chart("005930", base_date="20240101")
# 연봉
year_chart = client.query.get_stock_year_chart("005930", base_date="20240101")
surge = client.query.get_trade_qty_surge(
market="kospi", # "all" / "kospi" / "kosdaq"
exchange="krx", # "krx" / "nxt" / "all"
sort_type="surge_qty", # "surge_qty" / "surge_ratio"
stock_cond="0",
trade_qty_cond="0",
credit_cond="0",
)
for item in surge.items[:10]:
print(f"{item.stk_nm}: 거래량 {item.trde_qty}주")
price_change = client.query.get_price_change_upper(
market="kospi",
exchange="krx",
sort_type="rise_ratio", # "rise_ratio" / "rise_gap" / "fall_ratio" / "fall_gap" / "flat"
stock_cond="0",
trade_qty_cond="0",
credit_cond="0",
trade_amt="0",
)
for item in price_change.items[:10]:
print(f"{item.stk_nm}: {item.flu_rt}% 현재가 {item.cur_prc}원")
장중 투자자별(외국인·기관·개인 등) 순매수 상위 종목을 조회합니다.
investor = client.query.get_intraday_investor_trading(
market_type="kospi",
investor_type="foreign", # "foreign" / "institution" / "trust" / ...
exchange="all",
)
for item in investor.items[:10]:
print(f"{item.stk_nm}: 순매수 {item.netbuy_qty}주")