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,165 @@
import sys
import logging
import pandas as pd
sys.path.extend(['..', '.'])
import kis_auth as ka
from elw_functions import *
# 로깅 설정
logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# 인증
ka.auth()
trenv = ka.getTREnv()
##############################################################################################
# [국내주식] ELW시세 - ELW 비교대상종목조회[국내주식-183]
##############################################################################################
df = compare_stocks(fid_cond_scr_div_code="11517", fid_input_iscd="005930")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 종목검색[국내주식-166]
##############################################################################################
df = cond_search(fid_cond_mrkt_div_code="W", fid_cond_scr_div_code="11510", fid_rank_sort_cls_code="0", fid_input_cnt_1="100")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 만기예정/만기종목[국내주식-184]
##############################################################################################
df = expiration_stocks(fid_cond_mrkt_div_code="W", fid_cond_scr_div_code="11547", fid_input_date_1="20240402", fid_input_date_2="20240408", fid_div_cls_code="2", fid_etc_cls_code="", fid_unas_input_iscd="000000", fid_input_iscd_2="00000", fid_blng_cls_code="0", fid_input_option_1="")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 지표순위[국내주식-169]
##############################################################################################
df = indicator(fid_cond_mrkt_div_code="W", fid_cond_scr_div_code="20279", fid_unas_input_iscd="000000", fid_input_iscd="00000", fid_div_cls_code="0", fid_input_price_1="", fid_input_price_2="", fid_input_vol_1="", fid_input_vol_2="", fid_rank_sort_cls_code="0", fid_blng_cls_code="0")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 투자지표추이(체결)[국내주식-172]
##############################################################################################
df = indicator_trend_ccnl(fid_cond_mrkt_div_code="W", fid_input_iscd="58J297")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 투자지표추이(일별)[국내주식-173]
##############################################################################################
df = indicator_trend_daily(fid_cond_mrkt_div_code="W", fid_input_iscd="57K281")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 투자지표추이(분별)[국내주식-174]
##############################################################################################
df = indicator_trend_minute(fid_cond_mrkt_div_code="W", fid_input_iscd="58J297", fid_hour_cls_code="60", fid_pw_data_incu_yn="N")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW LP매매추이 [국내주식-182]
##############################################################################################
df1, df2 = lp_trade_trend(fid_cond_mrkt_div_code="W", fid_input_iscd="52K577")
print(df1)
print(df2)
##############################################################################################
# [국내주식] ELW시세 - ELW 신규상장종목[국내주식-181]
##############################################################################################
df = newly_listed(fid_cond_mrkt_div_code="W", fid_cond_scr_div_code="11548", fid_div_cls_code="02", fid_unas_input_iscd="000000", fid_input_iscd_2="00003", fid_input_date_1="20240402", fid_blng_cls_code="0")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 당일급변종목[국내주식-171]
##############################################################################################
df = quick_change(fid_cond_mrkt_div_code="W", fid_cond_scr_div_code="20287", fid_unas_input_iscd="000000", fid_input_iscd="00000", fid_mrkt_cls_code="A", fid_input_price_1="", fid_input_price_2="", fid_input_vol_1="", fid_input_vol_2="", fid_hour_cls_code="1", fid_input_hour_1="", fid_input_hour_2="", fid_rank_sort_cls_code="1", fid_blng_cls_code="0")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 민감도 순위[국내주식-170]
##############################################################################################
df = sensitivity(fid_cond_mrkt_div_code="W", fid_cond_scr_div_code="20285", fid_unas_input_iscd="000000", fid_input_iscd="00000", fid_div_cls_code="0", fid_input_price_1="", fid_input_price_2="", fid_input_vol_1="", fid_input_vol_2="", fid_rank_sort_cls_code="0", fid_input_rmnn_dynu_1="", fid_input_date_1="", fid_blng_cls_code="0")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 민감도 추이(체결)[국내주식-175]
##############################################################################################
df = sensitivity_trend_ccnl(fid_cond_mrkt_div_code="W", fid_input_iscd="58J297")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 민감도 추이(일별)[국내주식-176]
##############################################################################################
df = sensitivity_trend_daily(fid_cond_mrkt_div_code="W", fid_input_iscd="58J438")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 기초자산 목록조회[국내주식-185]
##############################################################################################
df = udrl_asset_list(fid_cond_scr_div_code="11541", fid_rank_sort_cls_code="0", fid_input_iscd="00000")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 기초자산별 종목시세[국내주식-186]
##############################################################################################
df = udrl_asset_price(fid_cond_mrkt_div_code="W", fid_cond_scr_div_code="11541", fid_mrkt_cls_code="A", fid_input_iscd="00000", fid_unas_input_iscd="005930", fid_vol_cnt="1000", fid_trgt_exls_cls_code="0", fid_input_price_1="1000", fid_input_price_2="5000", fid_input_vol_1="100", fid_input_vol_2="1000", fid_input_rmnn_dynu_1="30", fid_input_rmnn_dynu_2="90", fid_option="0", fid_input_option_1="", fid_input_option_2="")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 상승률순위[국내주식-167]
##############################################################################################
df = updown_rate(fid_cond_mrkt_div_code="W", fid_cond_scr_div_code="20277", fid_unas_input_iscd="000000", fid_input_iscd="00000", fid_input_rmnn_dynu_1="0", fid_div_cls_code="0", fid_input_price_1="", fid_input_price_2="", fid_input_vol_1="", fid_input_vol_2="", fid_input_date_1="", fid_rank_sort_cls_code="0", fid_blng_cls_code="0", fid_input_date_2="")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 변동성추이(체결)[국내주식-177]
##############################################################################################
df = volatility_trend_ccnl(fid_cond_mrkt_div_code="W", fid_input_iscd="58J297")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 변동성추이(일별)[국내주식-178]
##############################################################################################
df = volatility_trend_daily(fid_cond_mrkt_div_code="W", fid_input_iscd="58J297")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 변동성추이(분별)[국내주식-179]
##############################################################################################
df = volatility_trend_minute(fid_cond_mrkt_div_code="W", fid_input_iscd="58J297", fid_hour_cls_code="60", fid_pw_data_incu_yn="N")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 변동성추이(틱)[국내주식-180]
##############################################################################################
df = volatility_trend_tick(fid_cond_mrkt_div_code="W", fid_input_iscd="58J297")
print(df)
##############################################################################################
# [국내주식] ELW시세 - ELW 거래량순위[국내주식-168]
##############################################################################################
df = volume_rank(fid_cond_mrkt_div_code="W", fid_cond_scr_div_code="20278", fid_unas_input_iscd="000000", fid_input_iscd="00000", fid_input_rmnn_dynu_1="", fid_div_cls_code="0", fid_input_price_1="0", fid_input_price_2="100000", fid_input_vol_1="0", fid_input_vol_2="1000000", fid_input_date_1="20250101", fid_rank_sort_cls_code="0", fid_blng_cls_code="0", fid_input_iscd_2="0000", fid_input_date_2="")
print(df)

View File

@@ -0,0 +1,46 @@
import sys
import logging
import pandas as pd
sys.path.extend(['..', '.'])
import kis_auth as ka
from elw_functions_ws import *
# 로깅 설정
logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# 인증
ka.auth()
ka.auth_ws()
trenv = ka.getTREnv()
# 웹소켓 선언
kws = ka.KISWebSocket(api_url="/tryitout")
##############################################################################################
# [국내주식] 실시간시세 - ELW 실시간호가[실시간-062]
##############################################################################################
kws.subscribe(request=elw_asking_price, data=["57LA24", "57L739", "57L650", "57L966", "52L181", "57LB38"])
##############################################################################################
# [국내주식] 실시간시세 - ELW 실시간체결가[실시간-061]
##############################################################################################
kws.subscribe(request=elw_ccnl, data=["57LA24", "57L739", "57L650", "57L966", "52L181", "57LB38"])
##############################################################################################
# [국내주식] 실시간시세 - ELW 실시간예상체결[실시간-063]
##############################################################################################
kws.subscribe(request=elw_exp_ccnl, data=["57LA24", "57L739", "57L650", "57L966", "52L181", "57LB38"])
# 시작
def on_result(ws, tr_id, result, data_info):
print(result)
kws.start(on_result=on_result)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,307 @@
import logging
import sys
sys.path.extend(['..', '.'])
import kis_auth as ka
# 로깅 설정
logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
##############################################################################################
# [국내주식] 실시간시세 - ELW 실시간호가[실시간-062]
##############################################################################################
def elw_asking_price(
tr_type: str,
tr_key: str,
) -> tuple[dict, list[str]]:
"""
ELW 실시간호가[H0EWASP0]
ELW 실시간 호가 정보를 실시간으로 구독하는 웹소켓 API입니다.
Args:
tr_type (str): [필수] 구독 등록("1") 또는 해제("0") 여부를 나타냅니다.
tr_key (str): [필수] 종목코드. 빈 문자열일 수 없습니다.
Returns:
message (dict): 실시간 데이터 구독에 대한 응답 메시지.
columns (list[str]): 실시간 데이터의 컬럼 정보.
Raises:
ValueError: tr_key가 빈 문자열인 경우 발생합니다.
Example:
>>> msg, columns = elw_asking_price("1", "005930")
>>> print(msg, columns)
[참고자료]
종목코드 마스터파일 파이썬 정제코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/tree/main/stocks_info
"""
# 필수 파라미터 검증
if not tr_key:
raise ValueError("tr_key is required and cannot be an empty string")
tr_id = "H0EWASP0"
params = {
"tr_key": tr_key,
}
# 데이터 구독 요청
msg = ka.data_fetch(tr_id, tr_type, params)
# 응답 데이터 컬럼 정보
columns = [
"mksc_shrn_iscd",
"bsop_hour",
"hour_cls_code",
"askp1",
"askp2",
"askp3",
"askp4",
"askp5",
"askp6",
"askp7",
"askp8",
"askp9",
"askp10",
"bidp1",
"bidp2",
"bidp3",
"bidp4",
"bidp5",
"bidp6",
"bidp7",
"bidp8",
"bidp9",
"bidp10",
"askp_rsqn1",
"askp_rsqn2",
"askp_rsqn3",
"askp_rsqn4",
"askp_rsqn5",
"askp_rsqn6",
"askp_rsqn7",
"askp_rsqn8",
"askp_rsqn9",
"askp_rsqn10",
"bidp_rsqn1",
"bidp_rsqn2",
"bidp_rsqn3",
"bidp_rsqn4",
"bidp_rsqn5",
"bidp_rsqn6",
"bidp_rsqn7",
"bidp_rsqn8",
"bidp_rsqn9",
"bidp_rsqn10",
"total_askp_rsqn",
"total_bidp_rsqn",
"antc_cnpr",
"antc_cnqn",
"antc_cntg_vrss_sign",
"antc_cntg_vrss",
"antc_cntg_prdy_ctrt",
"lp_askp_rsqn1",
"lp_askp_rsqn2",
"lp_askp_rsqn3",
"lp_bidp_rsqn4",
"lp_askp_rsqn4",
"lp_bidp_rsqn5",
"lp_askp_rsqn5",
"lp_bidp_rsqn6",
"lp_askp_rsqn6",
"lp_bidp_rsqn7",
"lp_askp_rsqn7",
"lp_askp_rsqn8",
"lp_bidp_rsqn8",
"lp_askp_rsqn9",
"lp_bidp_rsqn9",
"lp_askp_rsqn10",
"lp_bidp_rsqn10",
"lp_bidp_rsqn1",
"lp_total_askp_rsqn",
"lp_bidp_rsqn2",
"lp_total_bidp_rsqn",
"lp_bidp_rsqn3",
"antc_vol",
]
return msg, columns
##############################################################################################
# [국내주식] 실시간시세 - ELW 실시간체결가[실시간-061]
##############################################################################################
def elw_ccnl(
tr_type: str,
tr_key: str,
) -> tuple[dict, list[str]]:
"""
ELW 실시간체결가[H0EWCNT0] 구독 함수
ELW 실시간체결가 API를 통해 실시간 데이터를 구독합니다.
Args:
tr_type (str): [필수] 구독 등록("1") 또는 해제("0") 여부를 나타냅니다.
tr_key (str): [필수] 종목코드를 입력합니다. 빈 문자열이 아니어야 합니다.
Returns:
message (dict): 메시지 데이터
columns (list[str]): 실시간 데이터의 컬럼 정보
Example:
>>> msg, columns = elw_ccnl("1", "005930")
>>> print(msg, columns)
[참고자료]
종목코드 마스터파일 파이썬 정제코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/tree/main/stocks_info
"""
# 필수 파라미터 검증
if not tr_key:
raise ValueError("tr_key는 필수 입력값입니다.")
tr_id = "H0EWCNT0"
params = {
"tr_key": tr_key,
}
# 데이터 구독 요청
msg = ka.data_fetch(tr_id, tr_type, params)
# 응답 데이터 컬럼 정보
columns = [
"mksc_shrn_iscd", "stck_cntg_hour", "stck_prpr", "prdy_vrss_sign",
"prdy_vrss", "prdy_ctrt", "wghn_avrg_stck_prc", "stck_oprc",
"stck_hgpr", "stck_lwpr", "askp1", "bidp1", "cntg_vol", "acml_vol",
"acml_tr_pbmn", "seln_cntg_csnu", "shnu_cntg_csnu", "ntby_cntg_csnu",
"cttr", "seln_cntg_smtn", "shnu_cntg_smtn", "cntg_cls_code",
"shnu_rate", "prdy_vol_vrss_acml_vol_rate", "oprc_hour",
"oprc_vrss_prpr_sign", "oprc_vrss_prpr", "hgpr_hour",
"hgpr_vrss_prpr_sign", "hgpr_vrss_prpr", "lwpr_hour",
"lwpr_vrss_prpr_sign", "lwpr_vrss_prpr", "bsop_date",
"new_mkop_cls_code", "trht_yn", "askp_rsqn1", "bidp_rsqn1",
"total_askp_rsqn", "total_bidp_rsqn", "tmvl_val", "prit", "prmm_val",
"gear", "prls_qryr_rate", "invl_val", "prmm_rate", "cfp", "lvrg_val",
"delta", "gama", "vega", "theta", "rho", "hts_ints_vltl", "hts_thpr",
"vol_tnrt", "prdy_smns_hour_acml_vol", "prdy_smns_hour_acml_vol_rate",
"apprch_rate", "lp_hvol", "lp_hldn_rate", "lp_ntby_qty"
]
return msg, columns
##############################################################################################
# [국내주식] 실시간시세 - ELW 실시간예상체결[실시간-063]
##############################################################################################
def elw_exp_ccnl(
tr_type: str,
tr_key: str,
) -> tuple[dict, list[str]]:
"""
ELW 실시간예상체결[H0EWANC0]
ELW 실시간예상체결 API입니다. 이 함수는 웹소켓을 통해 실시간 데이터를 구독합니다.
Args:
tr_type (str): [필수] 구독 등록("1") 또는 해제("0") 여부를 나타냅니다.
tr_key (str): [필수] 종목코드. 빈 문자열일 수 없습니다.
Returns:
message (dict): 메시지 데이터
columns (list[str]): 응답 데이터의 컬럼 정보
Raises:
ValueError: tr_key가 빈 문자열인 경우 발생합니다.
Example:
>>> msg, columns = elw_exp_ccnl("1", "005930")
>>> print(msg, columns)
[참고자료]
종목코드 마스터파일 파이썬 정제코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/tree/main/stocks_info
"""
# 필수 파라미터 검증
if not tr_key:
raise ValueError("tr_key is required and cannot be an empty string")
tr_id = "H0EWANC0"
params = {
"tr_key": tr_key,
}
# 데이터 구독 요청
msg = ka.data_fetch(tr_id, tr_type, params)
# 응답 데이터의 컬럼 정보
columns = [
"mksc_shrn_iscd",
"stck_cntg_hour",
"stck_prpr",
"prdy_vrss_sign",
"prdy_vrss",
"prdy_ctrt",
"wghn_avrg_stck_prc",
"stck_oprc",
"stck_hgpr",
"stck_lwpr",
"askp1",
"bidp1",
"cntg_vol",
"acml_vol",
"acml_tr_pbmn",
"seln_cntg_csnu",
"shnu_cntg_csnu",
"ntby_cntg_csnu",
"cttr",
"seln_cntg_smtn",
"shnu_cntg_smtn",
"cntg_cls_code",
"shnu_rate",
"prdy_vol_vrss_acml_vol_rate",
"oprc_hour",
"oprc_vrss_prpr_sign",
"oprc_vrss_prpr",
"hgpr_hour",
"hgpr_vrss_prpr_sign",
"hgpr_vrss_prpr",
"lwpr_hour",
"lwpr_vrss_prpr_sign",
"lwpr_vrss_prpr",
"bsop_date",
"new_mkop_cls_code",
"trht_yn",
"askp_rsqn1",
"bidp_rsqn1",
"total_askp_rsqn",
"total_bidp_rsqn",
"tmvl_val",
"prit",
"prmm_val",
"gear",
"prls_qryr_rate",
"invl_val",
"prmm_rate",
"cfp",
"lvrg_val",
"delta",
"gama",
"vega",
"theta",
"rho",
"hts_ints_vltl",
"hts_thpr",
"vol_tnrt",
"lp_hvol",
"lp_hldn_rate",
]
return msg, columns