소프트웨어 개발/Python

파이썬 시작, Xing API 이용하기 (8) - 쿼리날리기

늘근이 2015. 4. 19. 21:33

이제 거의다 왔다. 쿼리를이용해 실제로 거래를 걸어보고 가상 계좌랑 연결해보는 절차만 거쳐보면 된다.

이게 완성되면 파이썬-장고로 빠르게 구축하든지, 아니면 스칼라-플레이프레임워크로 구축하든지,

이도저도 안되면 C샵이나 다른 것들을 이용할수 있을 것이다.

어차피 윈도우 화면을 구성하는데는 상당히 힘이들고 귀찮다.

스칼라를 이용할수만 있다면 참 좋을텐데 쉽지는 않을듯 보인다.

 

 

import pythoncom
import win32com.client

class XASessionEvents:

    logInState = 0

    def OnLogin(self, code, msg):
        print("OnLogin method is called")
        print(str(code))
        print(str(msg))
        if str(code) == '0000':
            XASessionEvents.logInState = 1

    def OnLogout(self):
        print("OnLogout method is called")

    def OnDisconnect(self):
        print("OnDisconnect method is called")

class XAQueryEvents:
    queryState = 0
    def OnReceiveData(self, szTrCode):
        print("ReceiveData")
        XAQueryEvents.queryState = 1
    def OnReceiveMessage(self, systemError, mesageCode, message):
        print("ReceiveMessage")

if __name__ == "__main__":
    print("initiating")
    server_addr = "hts.etrade.co.kr"
    server_port = 20001
    server_type = 0
    user_id = "kohry"
    user_pass = ""
    user_certificate_pass = ""

    inXASession = win32com.client.DispatchWithEvents("XA_Session.XASession", XASessionEvents)
    inXASession.ConnectServer(server_addr, server_port)
    inXASession.Login(user_id, user_pass, user_certificate_pass, server_type, 0)
   
    while XASessionEvents.logInState == 0:
        pythoncom.PumpWaitingMessages()

    nCount = inXASession.GetAccountListCount()
    print("number of account",nCount)

    for i in range(nCount):
        print("Account: %d - %s" % (i, inXASession.GetAccountList(i)))


inXAQuery = win32com.client.DispatchWithEvents("XA_DataSet.XAQuery", XAQueryEvents)
inXAQuery.LoadFromResFile("C:\\eBest\\xingAPI\\Res\\t1102.res")
inXAQuery.SetFieldData('t1102InBlock', 'shcode', 0, '000150')
inXAQuery.Request(0)

while XAQueryEvents.queryState == 0:   
    pythoncom.PumpWaitingMessages()

name = inXAQuery.GetFieldData('t1102OutBlock', 'hname', 0)
price = inXAQuery.GetFieldData('t1102OutBlock', 'price', 0)
print("name: ", name)
print("price: ", price)
XAQueryEvents.queryState = 0

 

중요한것은 res파일들을 다 긁어와야한다는 것이다. devcenter에 그걸 제공하니 다 다운로드 받는다.

 

 

 

'소프트웨어 개발 > Python' 카테고리의 다른 글

성능 튜닝  (0) 2015.04.26
파이썬 코드  (0) 2015.04.26
Django 구조 파악하기  (0) 2015.04.25
Django 를 이용해 웹에 데이터 뿌려주기  (0) 2015.04.22
Django 윈도우 설치  (0) 2015.04.22