initial commit
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
"""
|
||||
Created on 20250115
|
||||
"""
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
from nav_comparison_time_trend import nav_comparison_time_trend
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내주식] 기본시세 > NAV 비교추이(분)[v1_국내주식-070]
|
||||
##############################################################################################
|
||||
|
||||
# 컬럼명 매핑
|
||||
COLUMN_MAPPING = {
|
||||
'bsop_hour': '영업 시간',
|
||||
'nav': 'NAV',
|
||||
'nav_prdy_vrss_sign': 'NAV 전일 대비 부호',
|
||||
'nav_prdy_vrss': 'NAV 전일 대비',
|
||||
'nav_prdy_ctrt': 'NAV 전일 대비율',
|
||||
'nav_vrss_prpr': 'NAV 대비 현재가',
|
||||
'dprt': '괴리율',
|
||||
'stck_prpr': '주식 현재가',
|
||||
'prdy_vrss': '전일 대비',
|
||||
'prdy_vrss_sign': '전일 대비 부호',
|
||||
'prdy_ctrt': '전일 대비율',
|
||||
'acml_vol': '누적 거래량',
|
||||
'cntg_vol': '체결 거래량'
|
||||
}
|
||||
|
||||
# 숫자형 컬럼
|
||||
NUMERIC_COLUMNS = ['NAV 전일 대비', 'NAV 전일 대비율', '전일 대비', '전일 대비율']
|
||||
|
||||
def main():
|
||||
"""
|
||||
NAV 비교추이(분) 조회 테스트 함수
|
||||
|
||||
이 함수는 NAV 비교추이(분) API를 호출하여 결과를 출력합니다.
|
||||
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
|
||||
# pandas 출력 옵션 설정
|
||||
pd.set_option('display.max_columns', None) # 모든 컬럼 표시
|
||||
pd.set_option('display.width', None) # 출력 너비 제한 해제
|
||||
pd.set_option('display.max_rows', None) # 모든 행 표시
|
||||
|
||||
# 인증 토큰 발급
|
||||
ka.auth()
|
||||
|
||||
# case1 조회
|
||||
logging.info("API 호출")
|
||||
try:
|
||||
result = nav_comparison_time_trend(fid_cond_mrkt_div_code="E", fid_input_iscd="069500", fid_hour_cls_code="60")
|
||||
except ValueError as e:
|
||||
logging.error("에러 발생: %s", str(e))
|
||||
return
|
||||
|
||||
logging.info("사용 가능한 컬럼: %s", 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)
|
||||
|
||||
logging.info("결과:")
|
||||
print(result)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,73 @@
|
||||
"""
|
||||
Created on 20250115
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내주식] 기본시세 > NAV 비교추이(분)[v1_국내주식-070]
|
||||
##############################################################################################
|
||||
|
||||
# 상수 정의
|
||||
API_URL = "/uapi/etfetn/v1/quotations/nav-comparison-time-trend"
|
||||
|
||||
def nav_comparison_time_trend(
|
||||
fid_cond_mrkt_div_code: str, # [필수] 조건시장분류코드 (ex. E)
|
||||
fid_input_iscd: str, # [필수] 입력종목코드 (ex. 123456)
|
||||
fid_hour_cls_code: str # [필수] 시간구분코드 (ex. 60:1분,180:3분,...,7200:120분)
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
NAV 비교추이(분) API입니다.
|
||||
한국투자 HTS(eFriend Plus) > [0244] ETF/ETN 비교추이(NAV/IIV) 좌측 화면 "분별" 비교추이 기능을 API로 개발한 사항으로, 해당 화면을 참고하시면 기능을 이해하기 쉽습니다.
|
||||
실전계좌의 경우, 한 번의 호출에 최근 30건까지 확인 가능합니다.
|
||||
|
||||
Args:
|
||||
fid_cond_mrkt_div_code (str): [필수] 조건시장분류코드 (ex. E)
|
||||
fid_input_iscd (str): [필수] 입력종목코드 (ex. 123456)
|
||||
fid_hour_cls_code (str): [필수] 시간구분코드 (ex. 60:1분,180:3분,...,7200:120분)
|
||||
|
||||
Returns:
|
||||
pd.DataFrame: NAV 비교추이(분) 데이터
|
||||
|
||||
Example:
|
||||
>>> df = nav_comparison_time_trend("E", "069500", "60")
|
||||
>>> print(df)
|
||||
"""
|
||||
|
||||
# 필수 파라미터 검증
|
||||
if fid_cond_mrkt_div_code == "" or fid_cond_mrkt_div_code is None:
|
||||
raise ValueError("fid_cond_mrkt_div_code is required (e.g. 'E')")
|
||||
|
||||
if fid_input_iscd == "" or fid_input_iscd is None:
|
||||
raise ValueError("fid_input_iscd is required (e.g. '123456')")
|
||||
|
||||
if fid_hour_cls_code == "" or fid_hour_cls_code is None:
|
||||
raise ValueError("fid_hour_cls_code is required (e.g. '60:1분,180:3분,...,7200:120분')")
|
||||
|
||||
tr_id = "FHPST02440100"
|
||||
|
||||
params = {
|
||||
"FID_COND_MRKT_DIV_CODE": fid_cond_mrkt_div_code,
|
||||
"FID_INPUT_ISCD": fid_input_iscd,
|
||||
"FID_HOUR_CLS_CODE": fid_hour_cls_code
|
||||
}
|
||||
|
||||
res = ka._url_fetch(API_URL, tr_id, "", params)
|
||||
|
||||
if res.isOK():
|
||||
# output (array) -> pd.DataFrame
|
||||
current_data = pd.DataFrame(res.getBody().output)
|
||||
return current_data
|
||||
else:
|
||||
res.printError(url=API_URL)
|
||||
return pd.DataFrame()
|
||||
Reference in New Issue
Block a user