■ get_market_ohlcv_by_date 함수를 사용해 특정 기간에서 특정 종목의 일별 시가/고가/저가/종가/거래량/등략률 리스트를 구하는 방법을 보여준다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import time import pandas as pd from pykrx import stock fromDate = "20240603" toDate = "20240605" tickerList = stock.get_market_ticker_list() targetDataFrame = pd.DataFrame() for ticker in tickerList[:4]: temporaryDataFrame = stock.get_market_ohlcv_by_date(fromdate = fromDate, todate = toDate, ticker = ticker) temporaryDataFrame = temporaryDataFrame.assign(종목코드 = ticker, 종목명 = stock.get_market_ticker_name(ticker)) targetDataFrame = pd.concat([targetDataFrame, temporaryDataFrame], axis = 0) time.sleep(1) targetDataFrame = targetDataFrame.reset_index() print(targetDataFrame) """ 날짜 시가 고가 저가 종가 거래량 등락률 종목코드 종목명 0 2024-06-03 4830 4860 4795 4835 116202 0.207254 095570 AJ네트웍스 1 2024-06-04 4835 4860 4760 4780 113354 -1.137539 095570 AJ네트웍스 2 2024-06-05 4775 4850 4690 4755 161625 -0.523013 095570 AJ네트웍스 3 2024-06-03 15100 15130 14600 15080 3236 -0.132450 006840 AK홀딩스 4 2024-06-04 15080 15180 14910 15050 2825 -0.198939 006840 AK홀딩스 5 2024-06-05 15100 15100 14900 15000 1737 -0.332226 006840 AK홀딩스 6 2024-06-03 3575 3690 3575 3680 123946 3.081232 027410 BGF 7 2024-06-04 3640 3680 3610 3625 78611 -1.494565 027410 BGF 8 2024-06-05 3625 3635 3560 3580 153447 -1.241379 027410 BGF 9 2024-06-03 117700 119300 116800 118700 40602 1.888412 282330 BGF리테일 10 2024-06-04 117600 119600 117500 118700 23479 0.000000 282330 BGF리테일 11 2024-06-05 118700 120200 116900 117000 49524 -1.432182 282330 BGF리테일 """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
certifi==2024.6.2 charset-normalizer==3.3.2 contourpy==1.2.1 cycler==0.12.1 DateTime==5.5 Deprecated==1.2.14 fonttools==4.53.0 idna==3.7 kiwisolver==1.4.5 matplotlib==3.9.0 multipledispatch==1.0.0 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 pykrx==1.0.45 pyparsing==3.1.2 python-dateutil==2.9.0.post0 pytz==2024.1 requests==2.32.3 six==1.16.0 tzdata==2024.1 urllib3==2.2.2 wrapt==1.16.0 xlrd==2.0.1 zope.interface==6.4.post2 |
※ pip install pykrx 명령을 실행했다.