Skip to content

Commit 4bf17fb

Browse files
authored
Merge pull request #264 from seohyunjun/feat/237-add-pdf-ticker-info
get_etf_portfolio_deposit_file 구성종목명 추가 (Closes #237)
2 parents 7870bea + ee9a331 commit 4bf17fb

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

pykrx/website/krx/etx/wrap.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,27 @@ def get_etf_portfolio_deposit_file(date: str, ticker: str) -> DataFrame:
210210
211211
Returns:
212212
DataFrame:
213-
계약수 금액 비중
213+
구성종목명 계약수 금액 시가총액 비중
214214
티커
215-
005930 8175.0 694875000 16.531250
216-
000660 972.0 126360000 2.949219
217-
051910 80.0 77120000 1.849609
218-
035420 219.0 65809500 1.570312
215+
0724F1 ADOBE SYSTEMS INC 12.22 0 0 0.0
216+
2079K3 ALPHABET INC-CL A 61.55 0 0 0.0
217+
2079K1 ALPHABET INC-CL C 57.21 0 0 0.0
218+
255371 AMERICAN ELECTRIC POWER 15.61 0 0 0.0
219219
"""
220220

221221
isin = get_etx_isin(ticker)
222222
df = PDF().fetch(date, isin)
223-
df = df[["COMPST_ISU_CD", "COMPST_ISU_CU1_SHRS", "VALU_AMT", "COMPST_RTO"]]
224-
df.columns = ["티커", "계약수", "금액", "비중"]
223+
df = df[
224+
[
225+
"COMPST_ISU_CD",
226+
"COMPST_ISU_NM",
227+
"COMPST_ISU_CU1_SHRS",
228+
"VALU_AMT",
229+
"COMPST_AMT",
230+
"COMPST_RTO",
231+
]
232+
]
233+
df.columns = ["티커", "구성종목명", "계약수", "금액", "시가총액", "비중"]
225234

226235
# NOTE: 웹 서버가 COMPST_ISU_CD에 ISIN과 축향형을 혼합해서 반환한다. Why?
227236
df["티커"] = df["티커"].apply(lambda x: x[3:9] if len(x) > 6 else x)
@@ -231,7 +240,14 @@ def get_etf_portfolio_deposit_file(date: str, ticker: str) -> DataFrame:
231240
# - empty string은 int, float로 형변환 불가
232241
# -> 이 문제를 해결하기 위해 '-' 문자는 0으로 치환
233242
df = df.replace(r"\-$", "0", regex=True)
234-
df = df.astype({"계약수": np.float64, "금액": np.int64, "비중": np.float32})
243+
df = df.astype(
244+
{
245+
"계약수": np.float64,
246+
"금액": np.int64,
247+
"시가총액": np.int64,
248+
"비중": np.float32,
249+
}
250+
)
235251
df = df[(df.T != 0).any()]
236252
return df
237253

tests/integration/test_etf_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ class TestEtfPdf:
148148
@pytest.mark.vcr
149149
def test_with_business_day(self):
150150
df = stock.get_etf_portfolio_deposit_file("152100", "20210402")
151-
temp = df.iloc[0:5, 0] == np.array([8140.0, 968.0, 218.0, 79.0, 89.0])
151+
temp = df.iloc[0:5, 1] == np.array([8140.0, 968.0, 218.0, 79.0, 89.0])
152152
assert temp.sum() == 5
153153

154154
@pytest.mark.vcr
155155
def test_with_negative_value(self):
156156
df = stock.get_etf_portfolio_deposit_file("114800", "20210402")
157-
assert df.iloc[1, 0] == pytest.approx(-3.58)
157+
assert df.iloc[1, 1] == pytest.approx(-3.58)
158158

159159

160160
class TestEtfTradingvolumeValue:

0 commit comments

Comments
 (0)