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,132 @@
"""
Created on 20250601
"""
import sys
import logging
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
from inquire_time_fuopchartprice import inquire_time_fuopchartprice
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [국내선물옵션] 기본시세 > 선물옵션 분봉조회[v1_국내선물-012]
##############################################################################################
COLUMN_MAPPING = {
'futs_prdy_vrss': '선물 전일 대비',
'prdy_vrss_sign': '전일 대비 부호',
'futs_prdy_ctrt': '선물 전일 대비율',
'futs_prdy_clpr': '선물 전일 종가',
'prdy_nmix': '전일 지수',
'acml_vol': '누적 거래량',
'acml_tr_pbmn': '누적 거래 대금',
'hts_kor_isnm': 'HTS 한글 종목명',
'futs_prpr': '선물 현재가',
'futs_shrn_iscd': '선물 단축 종목코드',
'prdy_vol': '전일 거래량',
'futs_mxpr': '선물 상한가',
'futs_llam': '선물 하한가',
'futs_oprc': '선물 시가2',
'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': 'KOSPI200 전일 대비 부호',
'hts_otst_stpl_qty': 'HTS 미결제 약정 수량',
'otst_stpl_qty_icdc': '미결제 약정 수량 증감',
'tday_rltv': '당일 체결강도',
'hts_thpr': 'HTS 이론가',
'dprt': '괴리율',
'stck_bsop_date': '주식 영업 일자',
'stck_cntg_hour': '주식 체결 시간',
'futs_prpr': '선물 현재가',
'futs_oprc': '선물 시가2',
'futs_hgpr': '선물 최고가',
'futs_lwpr': '선물 최저가',
'cntg_vol': '체결 거래량',
'acml_tr_pbmn': '누적 거래 대금'
}
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:
result1, result2 = inquire_time_fuopchartprice(
fid_cond_mrkt_div_code="F",
fid_input_iscd="101T12",
fid_hour_cls_code="60",
fid_pw_data_incu_yn="Y",
fid_fake_tick_incu_yn="N",
fid_input_date_1="20230901",
fid_input_hour_1="100000"
)
except ValueError as e:
logging.error("에러 발생: %s" % str(e))
return
# output1 처리
logging.info("=== output1 결과 ===")
logging.info("사용 가능한 컬럼: %s", result1.columns.tolist())
# 컬럼명 한글 변환
result1 = result1.rename(columns=COLUMN_MAPPING)
# 숫자형 컬럼 소수점 둘째자리까지 표시
for col in NUMERIC_COLUMNS:
if col in result1.columns:
result1[col] = pd.to_numeric(result1[col], errors='coerce').round(2)
logging.info("결과:")
print(result1)
# output2 처리
logging.info("=== output2 결과 ===")
logging.info("사용 가능한 컬럼: %s" % result2.columns.tolist())
# 컬럼명 한글 변환
result2 = result2.rename(columns=COLUMN_MAPPING)
# 숫자형 컬럼 소수점 둘째자리까지 표시
for col in NUMERIC_COLUMNS:
if col in result2.columns:
result2[col] = pd.to_numeric(result2[col], errors='coerce').round(2)
logging.info("결과:")
print(result2)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,104 @@
"""
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_국내선물-012]
##############################################################################################
# 상수 정의
API_URL = "/uapi/domestic-futureoption/v1/quotations/inquire-time-fuopchartprice"
def inquire_time_fuopchartprice(
fid_cond_mrkt_div_code: str, # FID 조건 시장 분류 코드 (F: 지수선물, O: 지수옵션)
fid_input_iscd: str, # FID 입력 종목코드 (101T12)
fid_hour_cls_code: str, # FID 시간 구분 코드 (30: 30초, 60: 1분)
fid_pw_data_incu_yn: str, # FID 과거 데이터 포함 여부 (Y:과거, N: 당일)
fid_fake_tick_incu_yn: str, # FID 허봉 포함 여부 (N)
fid_input_date_1: str, # FID 입력 날짜1 (20230901)
fid_input_hour_1: str # FID 입력 시간1 (100000)
) -> Tuple[pd.DataFrame, pd.DataFrame]:
"""
선물옵션 분봉조회 API입니다.
실전계좌의 경우, 한 번의 호출에 최대 102건까지 확인 가능하며,
FID_INPUT_DATE_1(입력날짜), FID_INPUT_HOUR_1(입력시간)을 이용하여 다음 조회 가능합니다.
Args:
fid_cond_mrkt_div_code (str): [필수] FID 조건 시장 분류 코드 (ex. F: 지수선물, O: 지수옵션)
fid_input_iscd (str): [필수] FID 입력 종목코드 (ex. 101T12)
fid_hour_cls_code (str): [필수] FID 시간 구분 코드 (ex. 30: 30초, 60: 1분)
fid_pw_data_incu_yn (str): [필수] FID 과거 데이터 포함 여부 (ex. Y:과거, N: 당일)
fid_fake_tick_incu_yn (str): [필수] FID 허봉 포함 여부 (ex. N)
fid_input_date_1 (str): [필수] FID 입력 날짜1 (ex. 20230901)
fid_input_hour_1 (str): [필수] FID 입력 시간1 (ex. 100000)
Returns:
Tuple[pd.DataFrame, pd.DataFrame]: 선물옵션 분봉 데이터 (output1, output2)
Example:
>>> df1, df2 = inquire_time_fuopchartprice("F", "101T12", "60", "Y", "N", "20230901", "100000")
>>> print(df1)
>>> print(df2)
"""
# 필수 파라미터 검증
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. '101T12')")
if fid_hour_cls_code == "":
raise ValueError("fid_hour_cls_code is required (e.g. '30: 30초, 60: 1분')")
if fid_pw_data_incu_yn == "":
raise ValueError("fid_pw_data_incu_yn is required (e.g. 'Y:과거, N: 당일')")
if fid_fake_tick_incu_yn == "":
raise ValueError("fid_fake_tick_incu_yn is required (e.g. 'N')")
if fid_input_date_1 == "":
raise ValueError("fid_input_date_1 is required (e.g. '20230901')")
if fid_input_hour_1 == "":
raise ValueError("fid_input_hour_1 is required (e.g. '100000')")
tr_id = "FHKIF03020200" # 선물옵션 분봉조회
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,
"FID_PW_DATA_INCU_YN": fid_pw_data_incu_yn,
"FID_FAKE_TICK_INCU_YN": fid_fake_tick_incu_yn,
"FID_INPUT_DATE_1": fid_input_date_1,
"FID_INPUT_HOUR_1": fid_input_hour_1
}
res = ka._url_fetch(API_URL, tr_id, "", params)
if res.isOK():
# output1: object array -> DataFrame
output1_data = pd.DataFrame(res.getBody().output1, index=[0])
# output2: array -> DataFrame
output2_data = pd.DataFrame(res.getBody().output2)
logging.info("Data fetch complete.")
return output1_data, output2_data
else:
res.printError(url=API_URL)
return pd.DataFrame(), pd.DataFrame()