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,130 @@
"""
Created on 20250601
"""
import sys
import logging
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
from inquire_daily_fuopchartprice import inquire_daily_fuopchartprice
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [국내선물옵션] 기본시세 > 선물옵션기간별시세(일/주/월/년)[v1_국내선물-008]
##############################################################################################
COLUMN_MAPPING = {
'futs_prdy_vrss': '전일 대비',
'prdy_vrss_sign': '전일 대비 부호',
'futs_prdy_ctrt': '선물 전일 대비율',
'futs_prdy_clpr': '선물 전일 종가',
'acml_vol': '누적 거래량',
'acml_tr_pbmn': '누적 거래 대금',
'hts_kor_isnm': 'HTS 한글 종목명',
'futs_prpr': '현재가',
'futs_shrn_iscd': '단축 종목코드',
'prdy_vol': '전일 거래량',
'futs_mxpr': '상한가',
'futs_llam': '하한가',
'futs_oprc': '시가',
'futs_hgpr': '최고가',
'futs_lwpr': '최저가',
'futs_prdy_oprc': '전일 시가',
'futs_prdy_hgpr': '전일 최고가',
'futs_prdy_lwpr': '전일 최저가',
'futs_askp': '매도호가',
'futs_bidp': '매수호가',
'basis': '베이시스',
'kospi200_nmix': 'KOSPI200 지수',
'kospi200_prdy_vrss': 'KOSPI200 전일 대비',
'kospi200_prdy_ctrt': 'KOSPI200 전일 대비율',
'kospi200_prdy_vrss_sign': '전일 대비 부호',
'hts_otst_stpl_qty': 'HTS 미결제 약정 수량',
'otst_stpl_qty_icdc': '미결제 약정 수량 증감',
'tday_rltv': '당일 체결강도',
'hts_thpr': 'HTS 이론가',
'dprt': '괴리율',
'stck_bsop_date': '영업 일자',
'futs_prpr': '현재가',
'futs_oprc': '시가',
'futs_hgpr': '최고가',
'futs_lwpr': '최저가',
'acml_vol': '누적 거래량',
'acml_tr_pbmn': '누적 거래 대금',
'mod_yn': '변경 여부'
}
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()
# case1 조회
logging.info("=== case1 조회 ===")
try:
output1, output2 = inquire_daily_fuopchartprice(
fid_cond_mrkt_div_code="F",
fid_input_iscd="101W09",
fid_input_date_1="20250301",
fid_input_date_2="20250810",
fid_period_div_code="D",
env_dv="real"
)
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()

View File

@@ -0,0 +1,109 @@
"""
Created on 20250601
"""
import sys
from typing import Tuple
import logging
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [국내선물옵션] 기본시세 > 선물옵션기간별시세(일/주/월/년)[v1_국내선물-008]
##############################################################################################
# 상수 정의
API_URL = "/uapi/domestic-futureoption/v1/quotations/inquire-daily-fuopchartprice"
def inquire_daily_fuopchartprice(
fid_cond_mrkt_div_code: str, # FID 조건 시장 분류 코드
fid_input_iscd: str, # 종목코드
fid_input_date_1: str, # 조회 시작일자
fid_input_date_2: str, # 조회 종료일자
fid_period_div_code: str, # 기간분류코드
env_dv: str # 실전모의구분
) -> Tuple[pd.DataFrame, pd.DataFrame]:
"""
(지수)선물옵션 기간별시세 데이터(일/주/월/년) 조회 (최대 100건 조회)
실전계좌의 경우, 한 번의 호출에 최대 100건까지 확인 가능하며, 이후의 값은 연속조회를 통해 확인하실 수 있습니다.
모의계좌의 경우, 한 번의 호출에 최대 100건까지 확인 가능하며, 이후의 값은 연속조회를 통해 확인하실 수 있습니다.
Args:
fid_cond_mrkt_div_code (str): [필수] FID 조건 시장 분류 코드 (ex. F: 지수선물, O: 지수옵션)
fid_input_iscd (str): [필수] 종목코드 (ex. 101W09)
fid_input_date_1 (str): [필수] 조회 시작일자 (ex. 20220301)
fid_input_date_2 (str): [필수] 조회 종료일자 (ex. 20220810)
fid_period_div_code (str): [필수] 기간분류코드 (ex. D: 일봉, W: 주봉)
env_dv (str): [필수] 실전모의구분 (ex. real:실전, demo:모의)
Returns:
Tuple[pd.DataFrame, pd.DataFrame]: (기본정보, 차트데이터) 튜플
Example:
>>> output1, output2 = inquire_daily_fuopchartprice(
... fid_cond_mrkt_div_code="F",
... fid_input_iscd="101W09",
... fid_input_date_1="20250301",
... fid_input_date_2="20250810",
... fid_period_div_code="D",
... env_dv="real"
... )
>>> print(output1)
>>> print(output2)
"""
# 필수 파라미터 검증
if fid_cond_mrkt_div_code == "":
raise ValueError("fid_cond_mrkt_div_code is required (e.g. 'F: 지수선물, O: 지수옵션')")
if fid_input_iscd == "":
raise ValueError("fid_input_iscd is required (e.g. '101W09')")
if fid_input_date_1 == "":
raise ValueError("fid_input_date_1 is required (e.g. '20250301')")
if fid_input_date_2 == "":
raise ValueError("fid_input_date_2 is required (e.g. '20250810')")
if fid_period_div_code == "":
raise ValueError("fid_period_div_code is required (e.g. 'D: 일봉, W: 주봉')")
if env_dv == "":
raise ValueError("env_dv is required (e.g. 'real:실전, demo:모의')")
# tr_id 설정
if env_dv == "real":
tr_id = "FHKIF03020100"
elif env_dv == "demo":
tr_id = "FHKIF03020100"
else:
raise ValueError("env_dv can only be 'real' or 'demo'")
params = {
"FID_COND_MRKT_DIV_CODE": fid_cond_mrkt_div_code,
"FID_INPUT_ISCD": fid_input_iscd,
"FID_INPUT_DATE_1": fid_input_date_1,
"FID_INPUT_DATE_2": fid_input_date_2,
"FID_PERIOD_DIV_CODE": fid_period_div_code
}
res = ka._url_fetch(API_URL, tr_id, "", params)
if res.isOK():
# output1: object -> DataFrame (1행)
output1_data = pd.DataFrame([res.getBody().output1])
# output2: array -> DataFrame (여러행)
output2_data = pd.DataFrame(res.getBody().output2)
return output1_data, output2_data
else:
res.printError(url=API_URL)
return pd.DataFrame(), pd.DataFrame()