initial commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
"""
|
||||
Created on 20250601
|
||||
"""
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
from tradprt_byamt import tradprt_byamt
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내주식] 시세분석 > 국내주식 체결금액별 매매비중 [국내주식-192]
|
||||
##############################################################################################
|
||||
|
||||
COLUMN_MAPPING = {
|
||||
'prpr_name': '가격명',
|
||||
'smtn_avrg_prpr': '합계 평균가격',
|
||||
'acml_vol': '합계 거래량',
|
||||
'whol_ntby_qty_rate': '합계 순매수비율',
|
||||
'ntby_cntg_csnu': '합계 순매수건수',
|
||||
'seln_cnqn_smtn': '매도 거래량',
|
||||
'whol_seln_vol_rate': '매도 거래량비율',
|
||||
'seln_cntg_csnu': '매도 건수',
|
||||
'shnu_cnqn_smtn': '매수 거래량',
|
||||
'whol_shun_vol_rate': '매수 거래량비율',
|
||||
'shnu_cntg_csnu': '매수 건수'
|
||||
}
|
||||
|
||||
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:
|
||||
result = tradprt_byamt(fid_cond_mrkt_div_code="J", fid_cond_scr_div_code="11119", 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()
|
||||
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
Created on 20250601
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내주식] 시세분석 > 국내주식 체결금액별 매매비중 [국내주식-192]
|
||||
##############################################################################################
|
||||
|
||||
# 상수 정의
|
||||
API_URL = "/uapi/domestic-stock/v1/quotations/tradprt-byamt"
|
||||
|
||||
def tradprt_byamt(
|
||||
fid_cond_mrkt_div_code: str, # [필수] 조건 시장 분류 코드 (ex. J)
|
||||
fid_cond_scr_div_code: str, # [필수] 조건화면분류코드 (ex. 11119)
|
||||
fid_input_iscd: str # [필수] 입력 종목코드 (ex. 123456)
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
국내주식 체결금액별 매매비중 API입니다.
|
||||
한국투자 HTS(eFriend Plus) > [0135] 체결금액별 매매비중 화면의 "상단 표" 기능을 API로 개발한 사항으로, 해당 화면을 참고하시면 기능을 이해하기 쉽습니다.
|
||||
|
||||
Args:
|
||||
fid_cond_mrkt_div_code (str): [필수] 조건 시장 분류 코드 (J:KRX, NX:NXT)
|
||||
fid_cond_scr_div_code (str): [필수] 조건화면분류코드 (ex. 11119)
|
||||
fid_input_iscd (str): [필수] 입력 종목코드 (ex. 123456)
|
||||
|
||||
Returns:
|
||||
pd.DataFrame: 국내주식 체결금액별 매매비중 데이터
|
||||
|
||||
Example:
|
||||
>>> df = tradprt_byamt("J", "11119", "005930")
|
||||
>>> print(df)
|
||||
"""
|
||||
|
||||
if fid_cond_mrkt_div_code == "":
|
||||
raise ValueError("fid_cond_mrkt_div_code is required (e.g. 'J')")
|
||||
|
||||
if fid_cond_scr_div_code == "":
|
||||
raise ValueError("fid_cond_scr_div_code is required (e.g. '11119')")
|
||||
|
||||
if fid_input_iscd == "":
|
||||
raise ValueError("fid_input_iscd is required (e.g. '123456')")
|
||||
|
||||
tr_id = "FHKST111900C0"
|
||||
|
||||
params = {
|
||||
"FID_COND_MRKT_DIV_CODE": fid_cond_mrkt_div_code,
|
||||
"FID_COND_SCR_DIV_CODE": fid_cond_scr_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)
|
||||
return current_data
|
||||
else:
|
||||
res.printError(url=API_URL)
|
||||
return pd.DataFrame()
|
||||
Reference in New Issue
Block a user