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,89 @@
"""
Created on 20250601
"""
import logging
import sys
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
from fuopt_ccnl_notice import fuopt_ccnl_notice
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [국내선물옵션] 실시간시세 > 선물옵션 실시간체결통보[실시간-012]
##############################################################################################
COLUMN_MAPPING = {
"cust_id": "고객 ID",
"acnt_no": "계좌번호",
"oder_no": "주문번호",
"ooder_no": "원주문번호",
"seln_byov_cls": "매도매수구분",
"rctf_cls": "정정구분",
"oder_kind2": "주문종류2",
"stck_shrn_iscd": "주식 단축 종목코드",
"cntg_qty": "체결 수량",
"cntg_unpr": "체결단가",
"stck_cntg_hour": "주식 체결 시간",
"rfus_yn": "거부여부",
"cntg_yn": "체결여부",
"acpt_yn": "접수여부",
"brnc_no": "지점번호",
"oder_qty": "주문수량",
"acnt_name": "계좌명",
"cntg_isnm": "체결종목명",
"oder_cond": "주문조건",
"ord_grp": "주문그룹ID",
"ord_grpseq": "주문그룹SEQ",
"order_prc": "주문가격"
}
NUMERIC_COLUMNS = []
def main():
"""
선물옵션 실시간체결통보
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()
trenv = ka.getTREnv()
# 인증(auth_ws()) 이후에 선언
kws = ka.KISWebSocket(api_url="/tryitout")
# 조회
kws.subscribe(request=fuopt_ccnl_notice, data=[trenv.my_htsid])
# 결과 표시
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,81 @@
"""
Created on 20250601
"""
import logging
import sys
from typing import Optional, Tuple
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [국내선물옵션] 실시간시세 > 선물옵션 실시간체결통보[실시간-012]
##############################################################################################
def fuopt_ccnl_notice(
tr_type: str,
tr_key: str,
):
"""
선물옵션 실시간체결통보 API입니다.
실시간 웹소켓 연결을 통해 선물옵션 거래의 실시간 체결 통보를 수신할 수 있습니다.
주문접수, 체결, 정정, 취소 등의 거래 상태 변화를 실시간으로 통보받을 수 있습니다.
고객ID, 계좌번호, 주문번호, 체결수량, 체결단가 등의 상세 거래 정보를 포함합니다.
실전계좌와 모의투자 모두 지원됩니다.
Args:
tr_type (str): [필수] 구독 등록/해제 여부 (ex. "1": 구독, "2": 해제)
tr_key (str): [필수] 코드 (ex. dttest11)
Returns:
message (str): 메시지 데이터
Example:
>>> msg, columns = fuopt_ccnl_notice("1", trenv.my_htsid)
>>> print(msg, columns)
"""
# 필수 파라미터 검증
if tr_key == "":
raise ValueError("tr_key is required")
tr_id = "H0IFCNI0"
params = {
"tr_key": tr_key,
}
msg = ka.data_fetch(tr_id, tr_type, params)
columns = [
"cust_id",
"acnt_no",
"oder_no",
"ooder_no",
"seln_byov_cls",
"rctf_cls",
"oder_kind2",
"stck_shrn_iscd",
"cntg_qty",
"cntg_unpr",
"stck_cntg_hour",
"rfus_yn",
"cntg_yn",
"acpt_yn",
"brnc_no",
"oder_qty",
"acnt_name",
"cntg_isnm",
"oder_cond",
"ord_grp",
"ord_grpseq",
"order_prc"
]
return msg, columns