initial commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
"""
|
||||
Created on 20250601
|
||||
"""
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
from psearch_title import psearch_title
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내주식] 시세분석 > 종목조건검색 목록조회[국내주식-038]
|
||||
##############################################################################################
|
||||
|
||||
COLUMN_MAPPING = {
|
||||
'user_id': 'HTS ID',
|
||||
'seq': '조건키값',
|
||||
'grp_nm': '그룹명',
|
||||
'condition_nm': '조건명'
|
||||
}
|
||||
|
||||
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:
|
||||
result = psearch_title(user_id=trenv.my_htsid)
|
||||
except ValueError as e:
|
||||
logging.error("에러 발생: %s" % str(e))
|
||||
return
|
||||
|
||||
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)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,67 @@
|
||||
"""
|
||||
Created on 20250601
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.extend(['../..', '.'])
|
||||
import kis_auth as ka
|
||||
|
||||
# 로깅 설정
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
##############################################################################################
|
||||
# [국내주식] 시세분석 > 종목조건검색 목록조회[국내주식-038]
|
||||
##############################################################################################
|
||||
|
||||
# 상수 정의
|
||||
API_URL = "/uapi/domestic-stock/v1/quotations/psearch-title"
|
||||
|
||||
def psearch_title(
|
||||
user_id: str # [필수] 사용자 HTS ID (ex. U:업종)
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
[국내주식] 시세분석 > 종목조건검색 목록조회[국내주식-038]
|
||||
HTS(efriend Plus) [0110] 조건검색에서 등록 및 서버저장한 나의 조건 목록을 확인할 수 있는 API입니다.
|
||||
종목조건검색 목록조회 API(/uapi/domestic-stock/v1/quotations/psearch-title)의 output인 'seq'을 종목조건검색조회 API(/uapi/domestic-stock/v1/quotations/psearch-result)의 input으로 사용하시면 됩니다.
|
||||
|
||||
※ 시스템 안정성을 위해 API로 제공되는 조건검색 결과의 경우 조건당 100건으로 제한을 둔 점 양해 부탁드립니다.
|
||||
|
||||
※ [0110] 화면의 '대상변경' 설정사항은 HTS [0110] 사용자 조건검색 화면에만 적용됨에 유의 부탁드립니다.
|
||||
|
||||
※ '조회가 계속 됩니다. (다음을 누르십시오.)' 오류 발생 시 해결방법
|
||||
→ HTS(efriend Plus) [0110] 조건검색 화면에서 조건을 등록하신 후, 왼쪽 하단의 "사용자조건 서버저장" 클릭하셔서 등록한 조건들을 서버로 보낸 후 다시 API 호출 시도 부탁드립니다.
|
||||
|
||||
Args:
|
||||
user_id (str): [필수] 사용자 HTS ID (ex. U:업종)
|
||||
|
||||
Returns:
|
||||
pd.DataFrame: 종목조건검색 목록 데이터
|
||||
|
||||
Example:
|
||||
>>> df = psearch_title(user_id=trenv.my_htsid)
|
||||
>>> print(df)
|
||||
"""
|
||||
|
||||
if user_id == "":
|
||||
raise ValueError("user_id is required (e.g. 'U:업종')")
|
||||
|
||||
tr_id = "HHKST03900300" # 종목조건검색 목록조회
|
||||
|
||||
params = {
|
||||
"user_id": user_id # 사용자 HTS ID
|
||||
}
|
||||
|
||||
res = ka._url_fetch(API_URL, tr_id, "", params)
|
||||
|
||||
if res.isOK():
|
||||
current_data = pd.DataFrame(res.getBody().output2)
|
||||
logging.info("Data fetch complete.")
|
||||
return current_data
|
||||
else:
|
||||
res.printError(url=API_URL)
|
||||
return pd.DataFrame()
|
||||
Reference in New Issue
Block a user