본문 바로가기

xingAPI

[xingApi, 파이썬] 업종전체조회 하기

 

GitHub - mujomboy/xingProject

Contribute to mujomboy/xingProject development by creating an account on GitHub.

github.com

 

 

 

[Git] Github 에 있는 파이썬 프로젝트 파이참(PyCharm) 으로 가져오기

1. 파이참에 GitHub Repository URL 연결하기 파이참을 열어 줍니다... 만약 파이참을 열었는데 바로 프로젝트가 오픈 되었다면... 프로젝트를 닫아 주세요. Get From VCS 버튼을 클릭해 줍니다. URL 입력 후

bysik1109.tistory.com

 

 

 

  • 업종전체조회 [t8424] 클래스
더보기
import os.path
import sys

import pythoncom
import win32com.client

from event.query import QueryEvents
from event.session import SessionEvents



# 세션 객체 요청 및 객체 생성
session = win32com.client.DispatchWithEvents("XA_Session.XASession", SessionEvents)

url = 'demo.ebestsec.co.kr'  # 모의 투자
# url = 'hts.ebestsec.co.kr'  # 실제 투자

session.ConnectServer(url, 200001)
session.Login("아이디", "비번", "", 0, 0)

while SessionEvents.state == "":
    # 로그인 상태 변경 메시지 채크
    pythoncom.PumpWaitingMessages()


# 쿼리 이벤트 객체 가져오기
query = win32com.client.DispatchWithEvents("XA_DataSet.XAQuery", QueryEvents)

# 해당 업종전체조회에 해당되는 t8424.res 파일이 있는 경로 가져오기
resfile_path = "C:\\Users\\bysik\\PycharmProjects\\xingProject\\res\\t8424.res"

# 조회 시 입력 파라미터 타입 명 t8424InBlock
inblock = "%sInBlock" % "t8424"
# 조회 시 리턴 파라미터 타입 명 t8424InBlock
outblock = "%sOutBlock" % "t8424"

# 경로를 통해 res 파일를 로드.
query.LoadFromResFile(resfile_path)
# 입력 파리미터를 초기화 합니다.
query.SetFieldData(inblock, "gubun1", 0, '')
# 조회 요청
query.Request(0)

while not QueryEvents.state:
    # 응답 대기
    pythoncom.PumpWaitingMessages()

# 응답이 왔으므로 응답 대기 관련 state 값 초기화
QueryEvents.state = not QueryEvents.state

for i in range(query.GetBlockCount(outblock)):
    # 리턴 데이터 추출
    name = query.GetFieldData(outblock, "hname", i).strip()
    code = query.GetFieldData(outblock, "upcode", i).strip()
    print(name, code)





# 세션 클래스
class SessionEvents:

    state = ""
    msg = ""

    def OnLogin(self, code, msg):
        SessionEvents.state = code
        SessionEvents.msg = msg

    def OnLogout(self):
        print("OnLogout")

    def OnDisconnect(self):
        print("OnDisconnect")



# 쿼리 클래스
class QueryEvents:

    state = False
    code = ""

    error = ""
    msgCode = ""
    msg = ""

    def OnReceiveData(self, code):
        QueryEvents.code = code
        QueryEvents.state = True

    def OnReceiveMessage(self, error, msgCode, msg):
        QueryEvents.error = error
        QueryEvents.msgCode = msgCode
        QueryEvents.msg = msg

 

 

 

업종 조회 데이터