6626070
2997924

FI01, Financial data collection

Back to the previous pagepage management
List of posts to read before reading this article


Contents


Stock Information

pandas-datareader : API URL

$ pip install pandas-datareader
import pandas_datareader.data as web

df = web.DataReader('005380', 'naver', start='2020-01-01', end='2020-06-30')
df.tail()

finance-datareader : API URL Github, github wiki userguide

$ pip install finance-datareader
import FinanceDataReader as fdr
#df_krx = fdr.StockListing('KRX')
#df_sp500 = fdr.StockListing('S&P500')

df = fdr.DataReader('001250', '2018')
df.head()





Real time stock data from KRX

from urllib.request import urlopen
from bs4 import BeautifulSoup
import time
import pandas as pd

def get_sise(stock_code, try_cnt):
    try:
        url="http://asp1.krx.co.kr/servlet/krx.asp.XMLSiseEng?code={}".format(stock_code)
        req=urlopen(url)
        result=req.read()
        xmlsoup=BeautifulSoup(result,"lxml-xml")
        stock = xmlsoup.find("TBL_StockInfo")
        stock_df=pd.DataFrame(stock.attrs, index=[0])
        stock_df=stock_df.applymap(lambda x: x.replace(",",""))
        print(stock_df, end='\n')
        return stock_df

    except HTTPError as e:
        logging.warning(e)
        if try_cnt>=3:
            return None
        else:
            get_sise(stock_code,try_cnt=+1)

stock_code=['005930']
for s in stock_code:
    temp=get_sise(s,1)
    time.sleep(0.5)





Ebestsec Sing API

blog





List of posts followed by this article


Reference


OUTPUT