initial commit

This commit is contained in:
2026-02-04 00:16:34 +09:00
commit ae11528dd9
867 changed files with 209640 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
import logging
import sys
import pandas as pd
sys.path.extend(['../..', '.']) # kis_auth 파일 경로 추가
import kis_auth as ka
from profit_asset_index import profit_asset_index
# 로깅 설정
logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
##############################################################################################
# [국내주식] 순위분석 > 국내주식 수익자산지표 순위[v1_국내주식-090]
##############################################################################################
COLUMN_MAPPING = {
'data_rank': '데이터 순위',
'hts_kor_isnm': 'HTS 한글 종목명',
'prdy_vrss_sign': '전일 대비 부호',
'mksc_shrn_iscd': '유가증권 단축 종목코드',
'stck_prpr': '주식 현재가',
'prdy_vrss': '전일 대비',
'prdy_ctrt': '전일 대비율',
'acml_vol': '누적 거래량',
'sale_totl_prfi': '매출 총 이익',
'bsop_prti': '영업 이익',
'op_prfi': '경상 이익',
'thtr_ntin': '당기순이익',
'total_aset': '자산총계',
'total_lblt': '부채총계',
'total_cptl': '자본총계',
'stac_month': '결산 월',
'stac_month_cls_code': '결산 월 구분 코드',
'iqry_csnu': '조회 건수'
}
NUMERIC_COLUMNS = []
def main():
"""
[국내주식] 순위분석
국내주식 수익자산지표 순위[v1_국내주식-090]
국내주식 수익자산지표 순위 테스트 함수
Parameters:
- fid_cond_mrkt_div_code (str): 조건 시장 분류 코드 (시장구분코드 (주식 J))
- fid_trgt_cls_code (str): 대상 구분 코드 (0:전체)
- fid_cond_scr_div_code (str): 조건 화면 분류 코드 (Unique key( 20173 ))
- fid_input_iscd (str): 입력 종목코드 (0000:전체, 0001:거래소, 1001:코스닥, 2001:코스피200)
- fid_div_cls_code (str): 분류 구분 코드 (0:전체)
- fid_input_price_1 (str): 입력 가격1 (입력값 없을때 전체 (가격 ~))
- fid_input_price_2 (str): 입력 가격2 (입력값 없을때 전체 (~ 가격))
- fid_vol_cnt (str): 거래량 수 (입력값 없을때 전체 (거래량 ~))
- fid_input_option_1 (str): 입력 옵션1 (회계연도 (2023))
- fid_input_option_2 (str): 입력 옵션2 (0: 1/4분기 , 1: 반기, 2: 3/4분기, 3: 결산)
- fid_rank_sort_cls_code (str): 순위 정렬 구분 코드 (0:매출이익 1:영업이익 2:경상이익 3:당기순이익 4:자산총계 5:부채총계 6:자본총계)
- fid_blng_cls_code (str): 소속 구분 코드 (0:전체)
- fid_trgt_exls_cls_code (str): 대상 제외 구분 코드 (0:전체)
Returns:
- DataFrame: 국내주식 수익자산지표 순위 결과
Example:
>>> df = profit_asset_index(fid_cond_mrkt_div_code="J", fid_trgt_cls_code="0", fid_cond_scr_div_code="20173", fid_input_iscd="0000", fid_div_cls_code="0", fid_input_price_1="", fid_input_price_2="", fid_vol_cnt="", fid_input_option_1="2023", fid_input_option_2="0", fid_rank_sort_cls_code="0", fid_blng_cls_code="0", fid_trgt_exls_cls_code="0")
"""
# pandas 출력 옵션 설정
pd.set_option('display.max_columns', None) # 모든 컬럼 표시
pd.set_option('display.width', None) # 출력 너비 제한 해제
pd.set_option('display.max_rows', None) # 모든 행 표시
# 토큰 발급
ka.auth()
# API 호출
result = profit_asset_index(
fid_cond_mrkt_div_code="J", # 조건 시장 분류 코드,
fid_trgt_cls_code="0", # 대상 구분 코드,
fid_cond_scr_div_code="20173", # 조건 화면 분류 코드,
fid_input_iscd="0000", # 입력 종목코드,
fid_div_cls_code="0", # 분류 구분 코드,
fid_input_price_1="", # 입력 가격1,
fid_input_price_2="", # 입력 가격2,
fid_vol_cnt="", # 거래량 수,
fid_input_option_1="2023", # 입력 옵션1,
fid_input_option_2="0", # 입력 옵션2,
fid_rank_sort_cls_code="0", # 순위 정렬 구분 코드,
fid_blng_cls_code="0", # 소속 구분 코드,
fid_trgt_exls_cls_code="0", # 대상 제외 구분 코드
)
# 컬럼명 출력
print("\n=== 사용 가능한 컬럼 목록 ===")
print(result.columns.tolist())
# 한글 컬럼명으로 변환
result = result.rename(columns=COLUMN_MAPPING)
for col in NUMERIC_COLUMNS:
if col in result.columns:
result[col] = pd.to_numeric(result[col], errors='coerce').round(2)
# 결과 출력
print("\n=== 국내주식 수익자산지표 순위 결과 ===")
print(result)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,169 @@
# DOMSTK_RANK - 국내주식 수익자산지표 순위
# Generated by KIS API Generator (Single API Mode)
import logging
import sys
import time
from typing import Optional
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
# 로깅 설정
logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
##############################################################################################
# [국내주식] 순위분석 > 국내주식 수익자산지표 순위[v1_국내주식-090]
##############################################################################################
# 상수 정의
API_URL = "/uapi/domestic-stock/v1/ranking/profit-asset-index"
def profit_asset_index(
fid_cond_mrkt_div_code: str, # 조건 시장 분류 코드
fid_trgt_cls_code: str, # 대상 구분 코드
fid_cond_scr_div_code: str, # 조건 화면 분류 코드
fid_input_iscd: str, # 입력 종목코드
fid_div_cls_code: str, # 분류 구분 코드
fid_input_price_1: str, # 입력 가격1
fid_input_price_2: str, # 입력 가격2
fid_vol_cnt: str, # 거래량 수
fid_input_option_1: str, # 입력 옵션1
fid_input_option_2: str, # 입력 옵션2
fid_rank_sort_cls_code: str, # 순위 정렬 구분 코드
fid_blng_cls_code: str, # 소속 구분 코드
fid_trgt_exls_cls_code: str, # 대상 제외 구분 코드
tr_cont: str = "", # 연속 거래 여부
dataframe: Optional[pd.DataFrame] = None # 누적 데이터프레임
) -> Optional[pd.DataFrame]:
"""
[국내주식] 순위분석
국내주식 수익자산지표 순위[v1_국내주식-090]
국내주식 수익자산지표 순위 API를 호출하여 DataFrame으로 반환합니다.
Args:
fid_cond_mrkt_div_code (str): 조건 시장 분류 코드 (필수) (J:KRX, NX:NXT)
fid_trgt_cls_code (str): 대상 구분 코드 (필수)
fid_cond_scr_div_code (str): 조건 화면 분류 코드 (필수)
fid_input_iscd (str): 입력 종목코드 (필수)
fid_div_cls_code (str): 분류 구분 코드 (필수)
fid_input_price_1 (str): 입력 가격1 (필수)
fid_input_price_2 (str): 입력 가격2 (필수)
fid_vol_cnt (str): 거래량 수 (필수)
fid_input_option_1 (str): 입력 옵션1 (필수)
fid_input_option_2 (str): 입력 옵션2 (필수)
fid_rank_sort_cls_code (str): 순위 정렬 구분 코드 (필수)
fid_blng_cls_code (str): 소속 구분 코드 (필수)
fid_trgt_exls_cls_code (str): 대상 제외 구분 코드 (필수)
tr_cont (str): 연속 거래 여부 (옵션)
dataframe (Optional[pd.DataFrame]): 누적 데이터프레임 (옵션)
Returns:
Optional[pd.DataFrame]: 국내주식 수익자산지표 순위 데이터
Example:
>>> df = profit_asset_index(
... fid_cond_mrkt_div_code="J",
... fid_trgt_cls_code="0",
... fid_cond_scr_div_code="20173",
... fid_input_iscd="0000",
... fid_div_cls_code="0",
... fid_input_price_1="",
... fid_input_price_2="",
... fid_vol_cnt="",
... fid_input_option_1="2023",
... fid_input_option_2="0",
... fid_rank_sort_cls_code="0",
... fid_blng_cls_code="0",
... fid_trgt_exls_cls_code="0"
... )
>>> print(df)
"""
# 필수 파라미터 검증
if fid_cond_mrkt_div_code != "J":
raise ValueError("조건 시장 분류 코드 확인요망!!!")
if fid_trgt_cls_code != "0":
raise ValueError("대상 구분 코드 확인요망!!!")
if fid_cond_scr_div_code != "20173":
raise ValueError("조건 화면 분류 코드 확인요망!!!")
if fid_input_iscd not in ["0000", "0001", "1001", "2001"]:
raise ValueError("입력 종목코드 확인요망!!!")
if fid_div_cls_code != "0":
raise ValueError("분류 구분 코드 확인요망!!!")
if fid_input_option_1 != "2023":
raise ValueError("입력 옵션1 확인요망!!!")
if fid_input_option_2 not in ["0", "1", "2", "3"]:
raise ValueError("입력 옵션2 확인요망!!!")
if fid_rank_sort_cls_code not in ["0", "1", "2", "3", "4", "5", "6"]:
raise ValueError("순위 정렬 구분 코드 확인요망!!!")
if fid_blng_cls_code != "0":
raise ValueError("소속 구분 코드 확인요망!!!")
if fid_trgt_exls_cls_code != "0":
raise ValueError("대상 제외 구분 코드 확인요망!!!")
tr_id = "FHPST01730000"
params = {
"fid_cond_mrkt_div_code": fid_cond_mrkt_div_code,
"fid_trgt_cls_code": fid_trgt_cls_code,
"fid_cond_scr_div_code": fid_cond_scr_div_code,
"fid_input_iscd": fid_input_iscd,
"fid_div_cls_code": fid_div_cls_code,
"fid_input_price_1": fid_input_price_1,
"fid_input_price_2": fid_input_price_2,
"fid_vol_cnt": fid_vol_cnt,
"fid_input_option_1": fid_input_option_1,
"fid_input_option_2": fid_input_option_2,
"fid_rank_sort_cls_code": fid_rank_sort_cls_code,
"fid_blng_cls_code": fid_blng_cls_code,
"fid_trgt_exls_cls_code": fid_trgt_exls_cls_code,
}
# API 호출
res = ka._url_fetch(API_URL, tr_id, tr_cont, params)
if res.isOK():
# 응답 데이터 처리
if hasattr(res.getBody(), 'output'):
current_data = pd.DataFrame(res.getBody().output)
else:
current_data = pd.DataFrame()
# 데이터프레임 병합
if dataframe is not None:
dataframe = pd.concat([dataframe, current_data], ignore_index=True)
else:
dataframe = current_data
# 연속 거래 여부 확인
tr_cont = res.getHeader().tr_cont
if tr_cont == "M":
print("Call Next")
ka.smart_sleep()
return profit_asset_index(
fid_cond_mrkt_div_code,
fid_trgt_cls_code,
fid_cond_scr_div_code,
fid_input_iscd,
fid_div_cls_code,
fid_input_price_1,
fid_input_price_2,
fid_vol_cnt,
fid_input_option_1,
fid_input_option_2,
fid_rank_sort_cls_code,
fid_blng_cls_code,
fid_trgt_exls_cls_code,
"N", dataframe
)
else:
print("The End")
return dataframe
else:
# 오류 처리
res.printError(API_URL)
return pd.DataFrame()