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,74 @@
"""
Created on 20250601
"""
import logging
import sys
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
from futures_exp_ccnl import futures_exp_ccnl
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [국내선물옵션] 실시간시세 > 주식선물 실시간예상체결 [실시간-031]
##############################################################################################
COLUMN_MAPPING = {
"futs_shrn_iscd": "선물단축종목코드",
"bsop_hour": "영업시간",
"antc_cnpr": "예상체결가",
"antc_cntg_vrss": "예상체결대비",
"antc_cntg_vrss_sign": "예상체결대비부호",
"antc_cntg_prdy_ctrt": "예상체결전일대비율",
"antc_mkop_cls_code": "예상장운영구분코드",
"antc_cnqn": "예상체결수량"
}
NUMERIC_COLUMNS = []
def main():
"""
[국내선물옵션] 실시간시세 > 주식선물 실시간예상체결 [실시간-031]
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()
ka.auth_ws()
# 인증(auth_ws()) 이후에 선언
kws = ka.KISWebSocket(api_url="/tryitout")
# 조회
kws.subscribe(request=futures_exp_ccnl, data=["111W07"])
# 결과 표시
def on_result(ws, tr_id: str, result: pd.DataFrame, data_map: dict):
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)
kws.start(on_result=on_result)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,64 @@
"""
Created on 20250601
"""
import logging
import sys
sys.path.extend(['../..', '.'])
import kis_auth as ka
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [국내선물옵션] 실시간시세 > 주식선물 실시간예상체결 [실시간-031]
##############################################################################################
def futures_exp_ccnl(
tr_type: str,
tr_key: str,
) -> (dict, list[str]):
"""
[국내선물옵션] 실시간시세 > 주식선물 실시간예상체결 [실시간-031]
Args:
tr_type (str): [필수] 등록/해제
tr_key (str): [필수] 종목코드
Returns:
message (dict): 메시지 데이터
columns (list[str]): 컬럼 정보
Example:
>>> msg, columns = futures_exp_ccnl("1", "111W07")
>>> print(msg, columns)
"""
# 필수 파라미터 검증
if tr_type == "":
raise ValueError("tr_type is required")
if tr_key == "":
raise ValueError("tr_key is required")
tr_id = "H0ZFANC0"
params = {
"tr_key": tr_key,
}
msg = ka.data_fetch(tr_id, tr_type, params)
columns = [
"futs_shrn_iscd",
"bsop_hour",
"antc_cnpr",
"antc_cntg_vrss",
"antc_cntg_vrss_sign",
"antc_cntg_prdy_ctrt",
"antc_mkop_cls_code",
"antc_cnqn"
]
return msg, columns