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,103 @@
"""
Created on 20250601
"""
import sys
import logging
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
from inquire_algo_ccnl import inquire_algo_ccnl
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [해외주식] 주문/계좌 > 해외주식 지정가체결내역조회 [해외주식-070]
##############################################################################################
# 컬럼 매핑 정의
COLUMN_MAPPING = {
'CCLD_SEQ': '체결순번',
'CCLD_BTWN': '체결시간',
'PDNO': '상품번호',
'ITEM_NAME': '종목명',
'FT_CCLD_QTY': 'FT체결수량',
'FT_CCLD_UNPR3': 'FT체결단가',
'FT_CCLD_AMT3': 'FT체결금액',
'ODNO': '주문번호',
'TRAD_DVSN_NAME': '매매구분명',
'FT_ORD_QTY': 'FT주문수량',
'FT_ORD_UNPR3': 'FT주문단가',
'ORD_TMD': '주문시각',
'SPLT_BUY_ATTR_NAME': '분할매수속성명',
'TR_CRCY': '거래통화',
'CCLD_CNT': '체결건수'
}
# 숫자형 컬럼 정의
NUMERIC_COLUMNS = []
def main():
"""
해외주식 지정가체결내역조회 테스트 함수
이 함수는 해외주식 지정가체결내역조회 API를 호출하여 결과를 출력합니다.
테스트 데이터로 case1의 파라미터를 사용합니다.
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()
trenv = ka.getTREnv()
# API 호출
logging.info("API 호출")
try:
result, result3 = inquire_algo_ccnl(cano=trenv.my_acct, acnt_prdt_cd=trenv.my_prod,)
except ValueError as e:
logging.error("에러 발생: %s" % str(e))
return
# output 결과 처리
logging.info("=== output 결과 ===")
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)
# output3 결과 처리
logging.info("=== output3 결과 ===")
logging.info("사용 가능한 컬럼: %s", result3.columns.tolist())
# 한글 컬럼명으로 변환
result3 = result3.rename(columns=COLUMN_MAPPING)
# 숫자형 컬럼 소수점 둘째자리까지 표시
for col in NUMERIC_COLUMNS:
if col in result3.columns:
result3[col] = pd.to_numeric(result3[col], errors='coerce').round(2)
logging.info("결과(output3):")
print(result3)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,127 @@
"""
Created on 20250601
"""
import sys
import time
from typing import Optional, Tuple
import logging
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [해외주식] 주문/계좌 > 해외주식 지정가체결내역조회 [해외주식-070]
##############################################################################################
# 상수 정의
API_URL = "/uapi/overseas-stock/v1/trading/inquire-algo-ccnl"
def inquire_algo_ccnl(
cano: str, # [필수] 계좌번호
acnt_prdt_cd: str, # [필수] 계좌상품코드 (ex. 01)
ord_dt: str = "", # 주문일자
ord_gno_brno: str = "", # 주문채번지점번호
odno: str = "", # 주문번호 (ex. 지정가주문번호 TTTC6058R에서 조회된 주문번호 입력)
ttlz_icld_yn: str = "", # 집계포함여부
NK200: str = "", # 연속조회키200
FK200: str = "", # 연속조회조건200
tr_cont: str = "", # 연속거래여부
dataframe: Optional[pd.DataFrame] = None, # 누적 데이터프레임
dataframe3: Optional[pd.DataFrame] = None, # 누적 데이터프레임3
depth: int = 0, # 내부 재귀깊이 (자동관리)
max_depth: int = 10 # 최대 재귀 횟수 제한
) -> Tuple[pd.DataFrame, pd.DataFrame]:
"""
해외주식 TWAP, VWAP 주문에 대한 체결내역 조회 API로 지정가 주문번호조회 API를 수행 후 조회해야합니다
Args:
cano (str): [필수] 계좌번호
acnt_prdt_cd (str): [필수] 계좌상품코드 (ex. 01)
ord_dt (str): 주문일자
ord_gno_brno (str): 주문채번지점번호
odno (str): 주문번호 (ex. 지정가주문번호 TTTC6058R에서 조회된 주문번호 입력)
ttlz_icld_yn (str): 집계포함여부
NK200 (str): 연속조회키200
FK200 (str): 연속조회조건200
tr_cont (str): 연속거래여부
dataframe (Optional[pd.DataFrame]): 누적 데이터프레임
dataframe3 (Optional[pd.DataFrame]): 누적 데이터프레임3
depth (int): 내부 재귀깊이 (자동관리)
max_depth (int): 최대 재귀 횟수 제한
Returns:
Tuple[pd.DataFrame, pd.DataFrame]: (output, output3) 체결내역 데이터
Example:
>>> result, result3 = inquire_algo_ccnl(cano=trenv.my_acct, acnt_prdt_cd=trenv.my_prod)
>>> print(result)
>>> print(result3)
"""
if cano == "":
raise ValueError("cano is required")
if acnt_prdt_cd == "":
raise ValueError("acnt_prdt_cd is required")
if depth > max_depth:
logging.warning("Max recursive depth reached.")
if dataframe is None:
dataframe = pd.DataFrame()
if dataframe3 is None:
dataframe3 = pd.DataFrame()
return dataframe, dataframe3
tr_id = "TTTS6059R" # 해외주식 지정가체결내역조회
params = {
"CANO": cano, # 계좌번호
"ACNT_PRDT_CD": acnt_prdt_cd, # 계좌상품코드
"ORD_DT": ord_dt, # 주문일자
"ORD_GNO_BRNO": ord_gno_brno, # 주문채번지점번호
"ODNO": odno, # 주문번호
"TTLZ_ICLD_YN": ttlz_icld_yn, # 집계포함여부
"CTX_AREA_NK200": NK200, # 연속조회키200
"CTX_AREA_FK200": FK200 # 연속조회조건200
}
res = ka._url_fetch(API_URL, tr_id, tr_cont, params)
if res.isOK():
current_data = pd.DataFrame(res.getBody().output)
current_data3 = pd.DataFrame(res.getBody().output3)
if dataframe is not None:
dataframe = pd.concat([dataframe, current_data], ignore_index=True)
else:
dataframe = current_data
if dataframe3 is not None:
dataframe3 = pd.concat([dataframe3, current_data3], ignore_index=True)
else:
dataframe3 = current_data3
tr_cont = res.getHeader().tr_cont
NK200 = res.getBody().ctx_area_nk200
FK200 = res.getBody().ctx_area_fk200
if tr_cont in ["M", "F"]: # 다음 페이지 존재
logging.info("Call Next page...")
ka.smart_sleep() # 시스템 안정적 운영을 위한 지연
return inquire_algo_ccnl(
cano, acnt_prdt_cd, ord_dt, ord_gno_brno, odno, ttlz_icld_yn,
NK200, FK200, "N", dataframe, dataframe3, depth + 1, max_depth
)
else:
logging.info("Data fetch complete.")
return dataframe, dataframe3
else:
res.printError(url=API_URL)
return pd.DataFrame(), pd.DataFrame()