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,84 @@
"""
Created on 20250601
"""
import sys
import logging
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
from program_trade_by_stock import program_trade_by_stock
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [국내주식] 시세분석 > 종목별 프로그램매매추이(체결)[v1_국내주식-044]
##############################################################################################
COLUMN_MAPPING = {
'bsop_hour': '영업 시간',
'stck_prpr': '주식 현재가',
'prdy_vrss': '전일 대비',
'prdy_vrss_sign': '전일 대비 부호',
'prdy_ctrt': '전일 대비율',
'acml_vol': '누적 거래량',
'whol_smtn_seln_vol': '전체 합계 매도 거래량',
'whol_smtn_shnu_vol': '전체 합계 매수2 거래량',
'whol_smtn_ntby_qty': '전체 합계 순매수 수량',
'whol_smtn_seln_tr_pbmn': '전체 합계 매도 거래 대금',
'whol_smtn_shnu_tr_pbmn': '전체 합계 매수2 거래 대금',
'whol_smtn_ntby_tr_pbmn': '전체 합계 순매수 거래 대금',
'whol_ntby_vol_icdc': '전체 순매수 거래량 증감',
'whol_ntby_tr_pbmn_icdc': '전체 순매수 거래 대금 증감'
}
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()
# 종목별 프로그램매매추이 조회
logging.info("=== 종목별 프로그램매매추이(체결) 조회 ===")
try:
result = program_trade_by_stock(fid_cond_mrkt_div_code="J", fid_input_iscd="005930")
except ValueError as e:
logging.error("에러 발생: %s" % str(e))
return
logging.info("사용 가능한 컬럼: %s", result.columns.tolist())
# 컬럼명 한글 변환 및 데이터 출력
result = result.rename(columns=COLUMN_MAPPING)
# 숫자형 컬럼 소수점 둘째자리까지 표시 (메타데이터에 number 자료형 명시 없음)
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)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,66 @@
"""
Created on 20250601
"""
import sys
import logging
import pandas as pd
sys.path.extend(['../..', '.'])
import kis_auth as ka
# 로깅 설정
logging.basicConfig(level=logging.INFO)
##############################################################################################
# [국내주식] 시세분석 > 종목별 프로그램매매추이(체결)[v1_국내주식-044]
##############################################################################################
# 상수 정의
API_URL = "/uapi/domestic-stock/v1/quotations/program-trade-by-stock"
def program_trade_by_stock(
fid_cond_mrkt_div_code: str, # [필수] 조건 시장 분류 코드 (ex. J:KRX,NX:NXT,UN:통합)
fid_input_iscd: str # [필수] 종목코드 (ex. 123456)
) -> pd.DataFrame:
"""
국내주식 종목별 프로그램매매추이(체결) API입니다.
한국투자 HTS(eFriend Plus) > [0465] 종목별 프로그램 매매추이 화면(혹은 한국투자 MTS > 국내 현재가 > 기타수급 > 프로그램) 의 기능을 API로 개발한 사항으로, 해당 화면을 참고하시면 기능을 이해하기 쉽습니다.
Args:
fid_cond_mrkt_div_code (str): [필수] 조건 시장 분류 코드 (ex. J:KRX,NX:NXT,UN:통합)
fid_input_iscd (str): [필수] 종목코드 (ex. 123456)
Returns:
pd.DataFrame: 종목별 프로그램매매추이 데이터
Example:
>>> df = program_trade_by_stock(fid_cond_mrkt_div_code="J", fid_input_iscd="005930")
>>> print(df)
"""
if fid_cond_mrkt_div_code == "":
raise ValueError("fid_cond_mrkt_div_code is required (ex. J:KRX,NX:NXT,UN:통합)")
if fid_input_iscd == "":
raise ValueError("fid_input_iscd is required (ex. 123456)")
tr_id = "FHPPG04650101" # 종목별 프로그램매매추이(체결)
params = {
"FID_COND_MRKT_DIV_CODE": fid_cond_mrkt_div_code, # 조건 시장 분류 코드
"FID_INPUT_ISCD": fid_input_iscd # 종목코드
}
res = ka._url_fetch(API_URL, tr_id, "", params)
if res.isOK():
current_data = pd.DataFrame(res.getBody().output)
logging.info("Data fetch complete.")
return current_data
else:
res.printError(url=API_URL)
return pd.DataFrame()