"대신증권 종목정보"의 두 판 사이의 차이
DB CAFE
(새 문서: == 종목정보 예제 == <source lang=python> import win32com.client # 연결 여부 체크 objCpCybos = win32com.client.Dispatch("CpUtil.CpCybos") bConnect = objCpCybos.IsConne...) |
|||
34번째 줄: | 34번째 줄: | ||
print("거래소 + 코스닥 종목코드 ",len(codeList) + len(codeList2)) | print("거래소 + 코스닥 종목코드 ",len(codeList) + len(codeList2)) | ||
</source> | </source> | ||
+ | == 주식 일자별 조회 == | ||
+ | <source lang=python> | ||
+ | import win32com.client | ||
+ | |||
+ | def ReqeustData(obj): | ||
+ | # 데이터 요청 | ||
+ | obj.BlockRequest() | ||
+ | |||
+ | # 통신 결과 확인 | ||
+ | rqStatus = obj.GetDibStatus() | ||
+ | rqRet = obj.GetDibMsg1() | ||
+ | print("통신상태", rqStatus, rqRet) | ||
+ | if rqStatus != 0: | ||
+ | return False | ||
+ | |||
+ | # 일자별 정보 데이터 처리 | ||
+ | count = obj.GetHeaderValue(1) # 데이터 개수 | ||
+ | for i in range(count): | ||
+ | date = obj.GetDataValue(0, i) # 일자 | ||
+ | open = obj.GetDataValue(1, i) # 시가 | ||
+ | high = obj.GetDataValue(2, i) # 고가 | ||
+ | low = obj.GetDataValue(3, i) # 저가 | ||
+ | close = obj.GetDataValue(4, i) # 종가 | ||
+ | diff = obj.GetDataValue(5, i) # 종가 | ||
+ | vol = obj.GetDataValue(6, i) # 종가 | ||
+ | print(date, open, high, low, close, diff, vol) | ||
+ | |||
+ | return True | ||
+ | |||
+ | |||
+ | |||
+ | # 연결 여부 체크 | ||
+ | objCpCybos = win32com.client.Dispatch("CpUtil.CpCybos") | ||
+ | bConnect = objCpCybos.IsConnect | ||
+ | if (bConnect == 0): | ||
+ | print("PLUS가 정상적으로 연결되지 않음. ") | ||
+ | exit() | ||
+ | |||
+ | |||
+ | # 일자별 object 구하기 | ||
+ | objStockWeek = win32com.client.Dispatch("DsCbo1.StockWeek") | ||
+ | objStockWeek.SetInputValue(0, 'A005930') #종목 코드 - 삼성전자 | ||
+ | |||
+ | # 최초 데이터 요청 | ||
+ | ret = ReqeustData(objStockWeek) | ||
+ | if ret == False: | ||
+ | exit() | ||
+ | |||
+ | |||
+ | # 연속 데이터 요청 | ||
+ | # 예제는 5번만 연속 통신 하도록 함. | ||
+ | NextCount = 1 | ||
+ | while objStockWeek.Continue: #연속 조회처리 | ||
+ | NextCount+=1; | ||
+ | if (NextCount > 5): | ||
+ | break | ||
+ | ret = ReqeustData(objStockWeek) | ||
+ | if ret == False: | ||
+ | exit() | ||
+ | </source> |
2020년 9월 8일 (화) 23:12 판
thumb_up 추천메뉴 바로가기
- DBA { Oracle DBA 명령어 > DBA 초급 과정 > DBA 고급 과정 }
- 튜닝 { 오라클 튜닝 목록 }
- 모델링 { 데이터 모델링 가이드 }
1 종목정보 예제[편집]
import win32com.client
# 연결 여부 체크
objCpCybos = win32com.client.Dispatch("CpUtil.CpCybos")
bConnect = objCpCybos.IsConnect
if (bConnect == 0):
print("PLUS가 정상적으로 연결되지 않음. ")
exit()
# 종목코드 리스트 구하기
objCpCodeMgr = win32com.client.Dispatch("CpUtil.CpCodeMgr")
codeList = objCpCodeMgr.GetStockListByMarket(1) #거래소
codeList2 = objCpCodeMgr.GetStockListByMarket(2) #코스닥
print("거래소 종목코드", len(codeList))
for i, code in enumerate(codeList):
secondCode = objCpCodeMgr.GetStockSectionKind(code)
name = objCpCodeMgr.CodeToName(code)
stdPrice = objCpCodeMgr.GetStockStdPrice(code)
print(i, code, secondCode, stdPrice, name)
print("코스닥 종목코드", len(codeList2))
for i, code in enumerate(codeList2):
secondCode = objCpCodeMgr.GetStockSectionKind(code)
name = objCpCodeMgr.CodeToName(code)
stdPrice = objCpCodeMgr.GetStockStdPrice(code)
print(i, code, secondCode, stdPrice, name)
print("거래소 + 코스닥 종목코드 ",len(codeList) + len(codeList2))
2 주식 일자별 조회[편집]
import win32com.client
def ReqeustData(obj):
# 데이터 요청
obj.BlockRequest()
# 통신 결과 확인
rqStatus = obj.GetDibStatus()
rqRet = obj.GetDibMsg1()
print("통신상태", rqStatus, rqRet)
if rqStatus != 0:
return False
# 일자별 정보 데이터 처리
count = obj.GetHeaderValue(1) # 데이터 개수
for i in range(count):
date = obj.GetDataValue(0, i) # 일자
open = obj.GetDataValue(1, i) # 시가
high = obj.GetDataValue(2, i) # 고가
low = obj.GetDataValue(3, i) # 저가
close = obj.GetDataValue(4, i) # 종가
diff = obj.GetDataValue(5, i) # 종가
vol = obj.GetDataValue(6, i) # 종가
print(date, open, high, low, close, diff, vol)
return True
# 연결 여부 체크
objCpCybos = win32com.client.Dispatch("CpUtil.CpCybos")
bConnect = objCpCybos.IsConnect
if (bConnect == 0):
print("PLUS가 정상적으로 연결되지 않음. ")
exit()
# 일자별 object 구하기
objStockWeek = win32com.client.Dispatch("DsCbo1.StockWeek")
objStockWeek.SetInputValue(0, 'A005930') #종목 코드 - 삼성전자
# 최초 데이터 요청
ret = ReqeustData(objStockWeek)
if ret == False:
exit()
# 연속 데이터 요청
# 예제는 5번만 연속 통신 하도록 함.
NextCount = 1
while objStockWeek.Continue: #연속 조회처리
NextCount+=1;
if (NextCount > 5):
break
ret = ReqeustData(objStockWeek)
if ret == False:
exit()