initial commit

This commit is contained in:
2026-01-31 22:34:57 +09:00
commit f1301de543
875 changed files with 196598 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
"""
Created on 20250101
"""
import sys
import logging
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
from opt_price import opt_price
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [해외선물옵션] 기본시세 > 해외옵션종목현재가 [해외선물-035]
##############################################################################################
# 컬럼명 매핑
COLUMN_MAPPING = {
'proc_date': '최종처리일자',
'proc_time': '최종처리시각',
'open_price': '시가',
'high_price': '고가',
'low_price': '저가',
'last_price': '현재가',
'vol': '누적거래수량',
'prev_diff_flag': '전일대비구분',
'prev_diff_price': '전일대비가격',
'prev_diff_rate': '전일대비율',
'bid_qntt': '매수1수량',
'bid_price': '매수1호가',
'ask_qntt': '매도1수량',
'ask_price': '매도1호가',
'trst_mgn': '증거금',
'exch_cd': '거래소코드',
'crc_cd': '거래통화',
'trd_fr_date': '상장일',
'expr_date': '만기일',
'trd_to_date': '최종거래일',
'remn_cnt': '잔존일수',
'last_qntt': '체결량',
'tot_ask_qntt': '총매도잔량',
'tot_bid_qntt': '총매수잔량',
'tick_size': '틱사이즈',
'open_date': '장개시일자',
'open_time': '장개시시각',
'close_date': '장종료일자',
'close_time': '장종료시각',
'sbsnsdate': '영업일자',
'sttl_price': '정산가'
}
# 숫자형 컬럼
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:
result = opt_price(srs_cd="DXM24")
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()

View File

@@ -0,0 +1,72 @@
"""
Created on 20250101
"""
import sys
import logging
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [해외선물옵션] 기본시세 > 해외옵션종목현재가 [해외선물-035]
##############################################################################################
# 상수 정의
API_URL = "/uapi/overseas-futureoption/v1/quotations/opt-price"
def opt_price(
srs_cd: str # 종목코드
) -> pd.DataFrame:
"""
해외옵션종목현재가 API입니다.
(중요) 해외옵션시세 출력값을 해석하실 때 focode.mst(해외지수옵션 종목마스터파일), fostkcode.mst(해외주식옵션 종목마스터파일)에 있는 sCalcDesz(계산 소수점) 값을 활용하셔야 정확한 값을 받아오실 수 있습니다.
- focode.mst(해외지수옵션 종목마스터파일), (해외주식옵션 종목마스터파일) 다운로드 방법
1) focode.mst(해외지수옵션 종목마스터파일)
: 포럼 > FAQ > 종목정보 다운로드(해외) - 해외지수옵션 클릭하여 다운로드 후
Github의 헤더정보(https://github.com/koreainvestment/open-trading-api/blob/main/stocks_info/해외옵션정보.h)를 참고하여 해석
2) fostkcode.mst(해외주식옵션 종목마스터파일)
: 포럼 > FAQ > 종목정보 다운로드(해외) - 해외주식옵션 클릭하여 다운로드 후
Github의 헤더정보(https://github.com/koreainvestment/open-trading-api/blob/main/stocks_info/해외주식옵션정보.h)를 참고하여 해석
- 소수점 계산 시, focode.mst(해외지수옵션 종목마스터파일), fostkcode.mst(해외주식옵션 종목마스터파일)의 sCalcDesz(계산 소수점) 값 참고
EX) focode.mst 파일의 sCalcDesz(계산 소수점) 값
품목코드 OES 계산소수점 -2 → 시세 7525 수신 시 75.25 로 해석
품목코드 O6E 계산소수점 -4 → 시세 54.0 수신 시 0.0054 로 해석
Args:
srs_cd (str): [필수] 종목코드
Returns:
pd.DataFrame: 해외옵션종목현재가 데이터
Example:
>>> df = opt_price(srs_cd="DXM24")
>>> print(df)
"""
if srs_cd == "":
raise ValueError("srs_cd is required")
tr_id = "HHDFO55010000" # 해외옵션종목현재가
params = {
"SRS_CD": srs_cd # 종목코드
}
res = ka._url_fetch(API_URL, tr_id, "", params)
if res.isOK():
current_data = pd.DataFrame(res.getBody().output1, index=[0])
return current_data
else:
res.printError(url=API_URL)
return pd.DataFrame()