initial commit
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
"""
|
||||
Created on 20250601
|
||||
"""
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
from inquire_time_dailychartprice import inquire_time_dailychartprice
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내주식] 기본시세 > 주식일별분봉조회 [국내주식-213]
|
||||
##############################################################################################
|
||||
|
||||
|
||||
COLUMN_MAPPING = {
|
||||
'prdy_vrss': '전일 대비',
|
||||
'prdy_vrss_sign': '전일 대비 부호',
|
||||
'prdy_ctrt': '전일 대비율',
|
||||
'stck_prdy_clpr': '주식 전일 종가',
|
||||
'acml_vol': '누적 거래량',
|
||||
'acml_tr_pbmn': '누적 거래 대금',
|
||||
'hts_kor_isnm': 'HTS 한글 종목명',
|
||||
'stck_prpr': '주식 현재가',
|
||||
'stck_bsop_date': '주식 영업 일자',
|
||||
'stck_cntg_hour': '주식 체결 시간',
|
||||
'stck_prpr': '주식 현재가',
|
||||
'stck_oprc': '주식 시가2',
|
||||
'stck_hgpr': '주식 최고가',
|
||||
'stck_lwpr': '주식 최저가',
|
||||
'cntg_vol': '체결 거래량',
|
||||
'acml_tr_pbmn': '누적 거래 대금'
|
||||
}
|
||||
|
||||
NUMERIC_COLUMNS = ['전일 대비', '전일 대비율']
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
주식일별분봉조회 테스트 함수
|
||||
|
||||
이 함수는 주식일별분봉조회 API를 호출하여 결과를 출력합니다.
|
||||
테스트 데이터로 삼성전자(005930)를 사용합니다.
|
||||
|
||||
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()
|
||||
|
||||
# case1 테스트
|
||||
logging.info("=== case1 테스트 ===")
|
||||
try:
|
||||
result1, result2 = inquire_time_dailychartprice(
|
||||
fid_cond_mrkt_div_code="J",
|
||||
fid_input_iscd="005930",
|
||||
fid_input_hour_1="130000",
|
||||
fid_input_date_1="20241023"
|
||||
)
|
||||
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,94 @@
|
||||
"""
|
||||
Created on 20250601
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
from typing import Optional, Tuple
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내주식] 기본시세 > 주식일별분봉조회 [국내주식-213]
|
||||
##############################################################################################
|
||||
|
||||
# 상수 정의
|
||||
API_URL = "/uapi/domestic-stock/v1/quotations/inquire-time-dailychartprice"
|
||||
|
||||
def inquire_time_dailychartprice(
|
||||
fid_cond_mrkt_div_code: str, # 시장 분류 코드
|
||||
fid_input_iscd: str, # 종목코드
|
||||
fid_input_hour_1: str, # 입력 시간1
|
||||
fid_input_date_1: str, # 입력 날짜1
|
||||
fid_pw_data_incu_yn: str = "N", # 과거 데이터 포함 여부
|
||||
fid_fake_tick_incu_yn: str = "" # 허봉 포함 여부
|
||||
) -> Tuple[pd.DataFrame, pd.DataFrame]:
|
||||
"""
|
||||
주식일별분봉조회 API입니다.
|
||||
|
||||
실전계좌의 경우, 한 번의 호출에 최대 120건까지 확인 가능하며,
|
||||
FID_INPUT_DATE_1, FID_INPUT_HOUR_1 이용하여 과거일자 분봉조회 가능합니다.
|
||||
|
||||
※ 과거 분봉 조회 시, 당사 서버에서 보관하고 있는 만큼의 데이터만 확인이 가능합니다. (최대 1년 분봉 보관)
|
||||
|
||||
Args:
|
||||
fid_cond_mrkt_div_code (str): [필수] 시장 분류 코드 (ex. J:주식,NX:NXT,UN:통합)
|
||||
fid_input_iscd (str): [필수] 종목코드 (ex. 123456)
|
||||
fid_input_hour_1 (str): [필수] 입력 시간1 (ex. 130000)
|
||||
fid_input_date_1 (str): [필수] 입력 날짜1 (ex. 20241023)
|
||||
fid_pw_data_incu_yn (str): 과거 데이터 포함 여부 (기본값: "N")
|
||||
fid_fake_tick_incu_yn (str): 허봉 포함 여부 (기본값: "")
|
||||
|
||||
Returns:
|
||||
Tuple[pd.DataFrame, pd.DataFrame]: (output1 데이터, output2 데이터)
|
||||
|
||||
Example:
|
||||
>>> output1, output2 = inquire_time_dailychartprice("J", "005930", "130000", "20241023")
|
||||
>>> print(output1)
|
||||
>>> print(output2)
|
||||
"""
|
||||
|
||||
# 필수 파라미터 검증
|
||||
if fid_cond_mrkt_div_code == "":
|
||||
raise ValueError("fid_cond_mrkt_div_code is required (e.g. 'J', 'NX', 'UN')")
|
||||
|
||||
if fid_input_iscd == "":
|
||||
raise ValueError("fid_input_iscd is required (e.g. '123456')")
|
||||
|
||||
if fid_input_hour_1 == "":
|
||||
raise ValueError("fid_input_hour_1 is required (e.g. '130000')")
|
||||
|
||||
if fid_input_date_1 == "":
|
||||
raise ValueError("fid_input_date_1 is required (e.g. '20241023')")
|
||||
|
||||
tr_id = "FHKST03010230"
|
||||
|
||||
params = {
|
||||
"FID_COND_MRKT_DIV_CODE": fid_cond_mrkt_div_code,
|
||||
"FID_INPUT_ISCD": fid_input_iscd,
|
||||
"FID_INPUT_HOUR_1": fid_input_hour_1,
|
||||
"FID_INPUT_DATE_1": fid_input_date_1,
|
||||
"FID_PW_DATA_INCU_YN": fid_pw_data_incu_yn,
|
||||
"FID_FAKE_TICK_INCU_YN": fid_fake_tick_incu_yn
|
||||
}
|
||||
|
||||
res = ka._url_fetch(API_URL, tr_id, "", params)
|
||||
|
||||
if res.isOK():
|
||||
# output1 (object) -> DataFrame
|
||||
output1 = pd.DataFrame([res.getBody().output1])
|
||||
|
||||
# output2 (array) -> DataFrame
|
||||
output2 = pd.DataFrame(res.getBody().output2)
|
||||
|
||||
return output1, output2
|
||||
else:
|
||||
res.printError(url=API_URL)
|
||||
return pd.DataFrame(), pd.DataFrame()
|
||||
Reference in New Issue
Block a user