initial commit
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
"""
|
||||
Created on 20250601
|
||||
"""
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
from inquire_daily_amount_fee import inquire_daily_amount_fee
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내선물옵션] 주문/계좌 > 선물옵션기간약정수수료일별[v1_국내선물-017]
|
||||
##############################################################################################
|
||||
|
||||
COLUMN_MAPPING = {
|
||||
'ord_dt': '주문일자',
|
||||
'pdno': '상품번호',
|
||||
'item_name': '종목명',
|
||||
'sll_agrm_amt': '매도약정금액',
|
||||
'sll_fee': '매도수수료',
|
||||
'buy_agrm_amt': '매수약정금액',
|
||||
'buy_fee': '매수수수료',
|
||||
'tot_fee_smtl': '총수수료합계',
|
||||
'trad_pfls': '매매손익',
|
||||
'futr_agrm': '선물약정',
|
||||
'futr_agrm_amt': '선물약정금액',
|
||||
'futr_agrm_amt_smtl': '선물약정금액합계',
|
||||
'futr_sll_fee_smtl': '선물매도수수료합계',
|
||||
'futr_buy_fee_smtl': '선물매수수수료합계',
|
||||
'futr_fee_smtl': '선물수수료합계',
|
||||
'opt_agrm': '옵션약정',
|
||||
'opt_agrm_amt': '옵션약정금액',
|
||||
'opt_agrm_amt_smtl': '옵션약정금액합계',
|
||||
'opt_sll_fee_smtl': '옵션매도수수료합계',
|
||||
'opt_buy_fee_smtl': '옵션매수수수료합계',
|
||||
'opt_fee_smtl': '옵션수수료합계',
|
||||
'prdt_futr_agrm': '상품선물약정',
|
||||
'prdt_fuop': '상품선물옵션',
|
||||
'prdt_futr_evlu_amt': '상품선물평가금액',
|
||||
'futr_fee': '선물수수료',
|
||||
'opt_fee': '옵션수수료',
|
||||
'fee': '수수료',
|
||||
'sll_agrm_amt': '매도약정금액',
|
||||
'buy_agrm_amt': '매수약정금액',
|
||||
'agrm_amt_smtl': '약정금액합계',
|
||||
'sll_fee': '매도수수료',
|
||||
'buy_fee': '매수수수료',
|
||||
'fee_smtl': '수수료합계',
|
||||
'trad_pfls_smtl': '매매손익합계'
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
# case1 조회
|
||||
logging.info("=== case1 조회 ===")
|
||||
try:
|
||||
result1, result2 = inquire_daily_amount_fee(
|
||||
cano=trenv.my_acct,
|
||||
acnt_prdt_cd=trenv.my_prod,
|
||||
inqr_strt_day="20240401",
|
||||
inqr_end_day="20240625"
|
||||
)
|
||||
except ValueError as e:
|
||||
logging.error("에러 발생: %s" % str(e))
|
||||
return
|
||||
|
||||
# output1 블록
|
||||
logging.info("=== output1 결과 ===")
|
||||
logging.info("사용 가능한 컬럼: %s", result1.columns.tolist())
|
||||
|
||||
# 컬럼명 한글 변환 및 데이터 출력
|
||||
result1 = result1.rename(columns=COLUMN_MAPPING)
|
||||
|
||||
# 숫자형 컬럼 소수점 둘째자리까지 표시
|
||||
for col in NUMERIC_COLUMNS:
|
||||
if col in result1.columns:
|
||||
result1[col] = pd.to_numeric(result1[col], errors='coerce').round(2)
|
||||
|
||||
logging.info("결과:")
|
||||
print(result1)
|
||||
|
||||
# output2 블록
|
||||
logging.info("=== output2 결과 ===")
|
||||
logging.info("사용 가능한 컬럼: %s", result2.columns.tolist())
|
||||
|
||||
# 컬럼명 한글 변환 및 데이터 출력
|
||||
result2 = result2.rename(columns=COLUMN_MAPPING)
|
||||
|
||||
# 숫자형 컬럼 소수점 둘째자리까지 표시
|
||||
for col in NUMERIC_COLUMNS:
|
||||
if col in result2.columns:
|
||||
result2[col] = pd.to_numeric(result2[col], errors='coerce').round(2)
|
||||
|
||||
logging.info("결과:")
|
||||
print(result2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -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)
|
||||
|
||||
##############################################################################################
|
||||
# [국내선물옵션] 주문/계좌 > 선물옵션기간약정수수료일별[v1_국내선물-017]
|
||||
##############################################################################################
|
||||
|
||||
# 상수 정의
|
||||
API_URL = "/uapi/domestic-futureoption/v1/trading/inquire-daily-amount-fee"
|
||||
|
||||
def inquire_daily_amount_fee(
|
||||
cano: str, # [필수] 종합계좌번호
|
||||
acnt_prdt_cd: str, # [필수] 계좌상품코드 (ex. 03)
|
||||
inqr_strt_day: str, # [필수] 조회시작일 (ex. 20240401)
|
||||
inqr_end_day: str, # [필수] 조회종료일 (ex. 20240625)
|
||||
FK200: str = "", # 연속조회검색조건200
|
||||
NK200: str = "", # 연속조회키200
|
||||
tr_cont: str = "", # 연속거래여부
|
||||
dataframe1: Optional[pd.DataFrame] = None, # 누적 데이터프레임1
|
||||
dataframe2: Optional[pd.DataFrame] = None, # 누적 데이터프레임2
|
||||
depth: int = 0, # 내부 재귀깊이 (자동관리)
|
||||
max_depth: int = 10 # 최대 재귀 횟수 제한
|
||||
) -> Tuple[pd.DataFrame, pd.DataFrame]:
|
||||
"""
|
||||
선물옵션기간약정수수료일별 API입니다.
|
||||
|
||||
Args:
|
||||
cano (str): [필수] 종합계좌번호
|
||||
acnt_prdt_cd (str): [필수] 계좌상품코드 (ex. 03)
|
||||
inqr_strt_day (str): [필수] 조회시작일 (ex. 20240401)
|
||||
inqr_end_day (str): [필수] 조회종료일 (ex. 20240625)
|
||||
FK200 (str): 연속조회검색조건200
|
||||
NK200 (str): 연속조회키200
|
||||
tr_cont (str): 연속거래여부
|
||||
dataframe1 (Optional[pd.DataFrame]): 누적 데이터프레임1
|
||||
dataframe2 (Optional[pd.DataFrame]): 누적 데이터프레임2
|
||||
depth (int): 내부 재귀깊이 (자동관리)
|
||||
max_depth (int): 최대 재귀 횟수 제한
|
||||
|
||||
Returns:
|
||||
Tuple[pd.DataFrame, pd.DataFrame]: 선물옵션기간약정수수료일별 데이터 (output1, output2)
|
||||
|
||||
Example:
|
||||
>>> df1, df2 = inquire_daily_amount_fee(cano=trenv.my_acct, acnt_prdt_cd=trenv.my_prod, inqr_strt_day="20240401", inqr_end_day="20240625")
|
||||
>>> print(df1)
|
||||
>>> print(df2)
|
||||
"""
|
||||
|
||||
if cano == "":
|
||||
raise ValueError("cano is required")
|
||||
|
||||
if acnt_prdt_cd == "":
|
||||
raise ValueError("acnt_prdt_cd is required")
|
||||
|
||||
if inqr_strt_day == "":
|
||||
raise ValueError("inqr_strt_day is required")
|
||||
|
||||
if inqr_end_day == "":
|
||||
raise ValueError("inqr_end_day is required")
|
||||
|
||||
if depth > max_depth:
|
||||
logging.warning("Max recursive depth reached.")
|
||||
if dataframe1 is None:
|
||||
dataframe1 = pd.DataFrame()
|
||||
if dataframe2 is None:
|
||||
dataframe2 = pd.DataFrame()
|
||||
return dataframe1, dataframe2
|
||||
|
||||
tr_id = "CTFO6119R" # 선물옵션기간약정수수료일별
|
||||
|
||||
params = {
|
||||
"CANO": cano, # 종합계좌번호
|
||||
"ACNT_PRDT_CD": acnt_prdt_cd, # 계좌상품코드
|
||||
"INQR_STRT_DAY": inqr_strt_day, # 조회시작일
|
||||
"INQR_END_DAY": inqr_end_day, # 조회종료일
|
||||
"CTX_AREA_FK200": FK200, # 연속조회검색조건200
|
||||
"CTX_AREA_NK200": NK200 # 연속조회키200
|
||||
}
|
||||
|
||||
res = ka._url_fetch(API_URL, tr_id, tr_cont, params)
|
||||
|
||||
if res.isOK():
|
||||
# output1 (array) 처리
|
||||
current_data1 = pd.DataFrame(res.getBody().output1)
|
||||
if dataframe1 is not None:
|
||||
dataframe1 = pd.concat([dataframe1, current_data1], ignore_index=True)
|
||||
else:
|
||||
dataframe1 = current_data1
|
||||
|
||||
# output2 (object) 처리
|
||||
current_data2 = pd.DataFrame([res.getBody().output2])
|
||||
if dataframe2 is not None:
|
||||
dataframe2 = pd.concat([dataframe2, current_data2], ignore_index=True)
|
||||
else:
|
||||
dataframe2 = current_data2
|
||||
|
||||
tr_cont = res.getHeader().tr_cont
|
||||
FK200 = res.getBody().ctx_area_fk200
|
||||
NK200 = res.getBody().ctx_area_nk200
|
||||
|
||||
if tr_cont in ["M", "F"]: # 다음 페이지 존재
|
||||
logging.info("Call Next page...")
|
||||
ka.smart_sleep() # 시스템 안정적 운영을 위한 지연
|
||||
return inquire_daily_amount_fee(
|
||||
cano, acnt_prdt_cd, inqr_strt_day, inqr_end_day, FK200, NK200, "N", dataframe1, dataframe2, depth + 1, max_depth
|
||||
)
|
||||
else:
|
||||
logging.info("Data fetch complete.")
|
||||
return dataframe1, dataframe2
|
||||
else:
|
||||
res.printError(url=API_URL)
|
||||
return pd.DataFrame(), pd.DataFrame()
|
||||
Reference in New Issue
Block a user