본문 바로가기

생활/대신증권API

[Cybos plus] 종목코드로 현재가, per, eps, 최근분기년월 가져오기

#code의 [현재가,per,eps,최근분기년월] 리턴
def per_eps_lastym(code):
    # Create Object
    instMarketEye = win32com.client.Dispatch("CpSysDib.MarketEye")

    # SetInputValue
    instMarketEye.SetInputValue(0, (4, 67, 70, 111))
    instMarketEye.SetInputValue(1, code)

    # BlockRequest
    instMarketEye.BlockRequest()

    #현재가
    price_now = instMarketEye.GetDataValue(0, 0)
    per = instMarketEye.GetDataValue(1, 0)
    eps=instMarketEye.GetDataValue(2, 0)
    #최근분기년월
    last_year_month = instMarketEye.GetDataValue(3, 0)

    return [price_now,per,eps,last_year_month]

print(per_eps_lastym('A003540'))