initial commit
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
"""
|
||||
Created on 20250601
|
||||
"""
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
from display_board_top import display_board_top
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내선물옵션] 기본시세 > 국내선물 기초자산 시세[국내선물-021]
|
||||
##############################################################################################
|
||||
|
||||
COLUMN_MAPPING = {
|
||||
'unas_prpr': '기초자산 현재가',
|
||||
'unas_prdy_vrss': '기초자산 전일 대비',
|
||||
'unas_prdy_vrss_sign': '기초자산 전일 대비 부호',
|
||||
'unas_prdy_ctrt': '기초자산 전일 대비율',
|
||||
'unas_acml_vol': '기초자산 누적 거래량',
|
||||
'hts_kor_isnm': 'HTS 한글 종목명',
|
||||
'futs_prpr': '선물 현재가',
|
||||
'futs_prdy_vrss': '선물 전일 대비',
|
||||
'prdy_vrss_sign': '전일 대비 부호',
|
||||
'futs_prdy_ctrt': '선물 전일 대비율',
|
||||
'hts_rmnn_dynu': 'HTS 잔존 일수'
|
||||
}
|
||||
|
||||
NUMERIC_COLUMNS = []
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
국내선물 기초자산 시세 조회 테스트 함수
|
||||
|
||||
이 함수는 국내선물 기초자산 시세 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()
|
||||
|
||||
logging.info("=== 국내선물 기초자산 시세 조회 ===")
|
||||
try:
|
||||
output1, output2 = display_board_top(fid_cond_mrkt_div_code="F", fid_input_iscd="101W09")
|
||||
except ValueError as e:
|
||||
logging.error("에러 발생: %s" % str(e))
|
||||
return
|
||||
|
||||
# output1 처리
|
||||
logging.info("=== output1 결과 ===")
|
||||
logging.info("사용 가능한 컬럼: %s", output1.columns.tolist())
|
||||
|
||||
# 컬럼명 한글 변환
|
||||
|
||||
output1 = output1.rename(columns=COLUMN_MAPPING)
|
||||
|
||||
# 숫자형 컬럼 소수점 둘째자리까지 표시
|
||||
|
||||
for col in NUMERIC_COLUMNS:
|
||||
if col in output1.columns:
|
||||
output1[col] = pd.to_numeric(output1[col], errors='coerce').round(2)
|
||||
|
||||
logging.info("결과:")
|
||||
print(output1)
|
||||
|
||||
# output2 처리
|
||||
logging.info("=== output2 결과 ===")
|
||||
logging.info("사용 가능한 컬럼: %s", output2.columns.tolist())
|
||||
|
||||
# 컬럼명 한글 변환
|
||||
output2 = output2.rename(columns=COLUMN_MAPPING)
|
||||
|
||||
# 숫자형 컬럼 소수점 둘째자리까지 표시
|
||||
for col in NUMERIC_COLUMNS:
|
||||
if col in output2.columns:
|
||||
output2[col] = pd.to_numeric(output2[col], errors='coerce').round(2)
|
||||
|
||||
logging.info("결과:")
|
||||
print(output2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,79 @@
|
||||
"""
|
||||
Created on 20250601
|
||||
"""
|
||||
|
||||
import sys
|
||||
import logging
|
||||
from typing import Tuple
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내선물옵션] 기본시세 > 국내선물 기초자산 시세[국내선물-021]
|
||||
##############################################################################################
|
||||
|
||||
# 상수 정의
|
||||
API_URL = "/uapi/domestic-futureoption/v1/quotations/display-board-top"
|
||||
|
||||
def display_board_top(
|
||||
fid_cond_mrkt_div_code: str, # [필수] 조건 시장 분류 코드 (ex. F)
|
||||
fid_input_iscd: str, # [필수] 입력 종목코드 (ex. 101V06)
|
||||
fid_cond_mrkt_div_code1: str = "", # 조건 시장 분류 코드
|
||||
fid_cond_scr_div_code: str = "", # 조건 화면 분류 코드
|
||||
fid_mtrt_cnt: str = "", # 만기 수
|
||||
fid_cond_mrkt_cls_code: str = "" # 조건 시장 구분 코드
|
||||
) -> Tuple[pd.DataFrame, pd.DataFrame]:
|
||||
"""
|
||||
국내선물 기초자산 시세 API입니다.
|
||||
한국투자 HTS(eFriend Plus) > [0503] 선물옵션 종합시세(Ⅰ) 화면의 "상단 바" 기능을 API로 개발한 사항입니다.
|
||||
|
||||
Args:
|
||||
fid_cond_mrkt_div_code (str): [필수] 조건 시장 분류 코드 (ex. F)
|
||||
fid_input_iscd (str): [필수] 입력 종목코드 (ex. 101V06)
|
||||
fid_cond_mrkt_div_code1 (str): 조건 시장 분류 코드
|
||||
fid_cond_scr_div_code (str): 조건 화면 분류 코드
|
||||
fid_mtrt_cnt (str): 만기 수
|
||||
fid_cond_mrkt_cls_code (str): 조건 시장 구분 코드
|
||||
|
||||
Returns:
|
||||
Tuple[pd.DataFrame, pd.DataFrame]: (output1, output2) 데이터프레임 튜플
|
||||
|
||||
Example:
|
||||
>>> output1, output2 = display_board_top(fid_cond_mrkt_div_code="F", fid_input_iscd="101W09")
|
||||
>>> print(output1)
|
||||
>>> print(output2)
|
||||
"""
|
||||
|
||||
if fid_cond_mrkt_div_code == "":
|
||||
raise ValueError("fid_cond_mrkt_div_code is required (e.g. 'F')")
|
||||
|
||||
if fid_input_iscd == "":
|
||||
raise ValueError("fid_input_iscd is required (e.g. '101W09')")
|
||||
|
||||
tr_id = "FHPIF05030000"
|
||||
|
||||
params = {
|
||||
"FID_COND_MRKT_DIV_CODE": fid_cond_mrkt_div_code,
|
||||
"FID_INPUT_ISCD": fid_input_iscd,
|
||||
"FID_COND_MRKT_DIV_CODE1": fid_cond_mrkt_div_code1,
|
||||
"FID_COND_SCR_DIV_CODE": fid_cond_scr_div_code,
|
||||
"FID_MTRT_CNT": fid_mtrt_cnt,
|
||||
"FID_COND_MRKT_CLS_CODE": fid_cond_mrkt_cls_code
|
||||
}
|
||||
|
||||
res = ka._url_fetch(API_URL, tr_id, "", params)
|
||||
|
||||
if res.isOK():
|
||||
output1 = pd.DataFrame(res.getBody().output1, index=[0])
|
||||
output2 = pd.DataFrame(res.getBody().output2)
|
||||
|
||||
return output1, output2
|
||||
else:
|
||||
res.printError(url=API_URL)
|
||||
return pd.DataFrame(), pd.DataFrame()
|
||||
Reference in New Issue
Block a user