initial commit
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
"""
|
||||
Created on 20250601
|
||||
"""
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
from exp_price_trend import exp_price_trend
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내선물옵션] 기본시세 > 선물옵션 일중예상체결추이[국내선물-018]
|
||||
##############################################################################################
|
||||
|
||||
COLUMN_MAPPING = {
|
||||
'hts_kor_isnm': '영업 시간',
|
||||
'futs_antc_cnpr': '업종 지수 현재가',
|
||||
'antc_cntg_vrss_sign': '업종 지수 전일 대비',
|
||||
'futs_antc_cntg_vrss': '전일 대비 부호',
|
||||
'antc_cntg_prdy_ctrt': '업종 지수 전일 대비율',
|
||||
'futs_sdpr': '누적 거래 대금',
|
||||
'stck_cntg_hour': '주식체결시간',
|
||||
'futs_antc_cnpr': '선물예상체결가',
|
||||
'antc_cntg_vrss_sign': '예상체결대비부호',
|
||||
'futs_antc_cntg_vrss': '선물예상체결대비',
|
||||
'antc_cntg_prdy_ctrt': '예상체결전일대비율'
|
||||
}
|
||||
|
||||
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 = exp_price_trend(fid_input_iscd="101W09", fid_cond_mrkt_div_code="F")
|
||||
except ValueError as e:
|
||||
logging.error("에러 발생: %s" % str(e))
|
||||
return
|
||||
|
||||
# output1 결과 처리
|
||||
logging.info("사용 가능한 컬럼 (output1): %s", result1.columns.tolist())
|
||||
|
||||
# 컬럼명 한글 변환 및 데이터 출력 (output1)
|
||||
result1 = result1.rename(columns=COLUMN_MAPPING)
|
||||
|
||||
# 숫자형 컬럼 소수점 둘째자리까지 표시 (output1)
|
||||
for col in NUMERIC_COLUMNS:
|
||||
if col in result1.columns:
|
||||
result1[col] = pd.to_numeric(result1[col], errors='coerce').round(2)
|
||||
|
||||
logging.info("결과 (output1):")
|
||||
print(result1)
|
||||
|
||||
# output2 결과 처리
|
||||
logging.info("사용 가능한 컬럼 (output2): %s", result2.columns.tolist())
|
||||
|
||||
# 컬럼명 한글 변환 및 데이터 출력 (output2)
|
||||
result2 = result2.rename(columns=COLUMN_MAPPING)
|
||||
|
||||
# 숫자형 컬럼 소수점 둘째자리까지 표시 (output2)
|
||||
for col in NUMERIC_COLUMNS:
|
||||
if col in result2.columns:
|
||||
result2[col] = pd.to_numeric(result2[col], errors='coerce').round(2)
|
||||
|
||||
logging.info("결과 (output2):")
|
||||
print(result2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
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)
|
||||
|
||||
##############################################################################################
|
||||
# [국내선물옵션] 기본시세 > 선물옵션 일중예상체결추이[국내선물-018]
|
||||
##############################################################################################
|
||||
|
||||
# 상수 정의
|
||||
API_URL = "/uapi/domestic-futureoption/v1/quotations/exp-price-trend"
|
||||
|
||||
def exp_price_trend(
|
||||
fid_input_iscd: str, # [필수] 입력 종목코드 (ex. 101V06)
|
||||
fid_cond_mrkt_div_code: str # [필수] 조건 시장 분류 코드 (ex. F)
|
||||
) -> Tuple[pd.DataFrame, pd.DataFrame]:
|
||||
"""
|
||||
선물옵션 일중예상체결추이 API입니다.
|
||||
한국투자 HTS(eFriend Plus) > [0548] 선물옵션 예상체결추이 화면의 기능을 API로 개발한 사항입니다.
|
||||
|
||||
Args:
|
||||
fid_input_iscd (str): [필수] 입력 종목코드 (ex. 101V06)
|
||||
fid_cond_mrkt_div_code (str): [필수] 조건 시장 분류 코드 (ex. F)
|
||||
|
||||
Returns:
|
||||
Tuple[pd.DataFrame, pd.DataFrame]: (output1, output2) 데이터프레임 튜플
|
||||
|
||||
Example:
|
||||
>>> df1, df2 = exp_price_trend(fid_input_iscd="101W09", fid_cond_mrkt_div_code="F")
|
||||
>>> print(df1)
|
||||
>>> print(df2)
|
||||
"""
|
||||
|
||||
if fid_input_iscd == "":
|
||||
raise ValueError("fid_input_iscd is required (e.g. '101W09')")
|
||||
|
||||
if fid_cond_mrkt_div_code == "":
|
||||
raise ValueError("fid_cond_mrkt_div_code is required (e.g. 'F')")
|
||||
|
||||
tr_id = "FHPIF05110100" # 선물옵션 일중예상체결추이
|
||||
|
||||
params = {
|
||||
"FID_INPUT_ISCD": fid_input_iscd, # 입력 종목코드
|
||||
"FID_COND_MRKT_DIV_CODE": fid_cond_mrkt_div_code # 조건 시장 분류 코드
|
||||
}
|
||||
|
||||
res = ka._url_fetch(API_URL, tr_id, "", params)
|
||||
|
||||
if res.isOK():
|
||||
# output1은 object 타입이므로 단일 행 DataFrame
|
||||
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()
|
||||
Reference in New Issue
Block a user