반응형
xing api -- 현재가 ; 단일 데이터 조회
환경 ; windows 10 64bit, python 3.6 32bit, xing api
** xing api 도움말 참고.
-- TR 조회시에는 XAQuery 사용한다.
RES 파일 등록하여, TR 마다 instance 만들어 사용한다.
--> 요청에 대한 결과가 오면 OnReceiveData() event handler 로 통지가 온다.
** RES 파일은 DevCenter 프로그램에서 다운받으면 된다.
** import xing_login ==> http://freeprog.tistory.com/341 을 사용함.
import win32com.client
import pythoncom
import xing_login
import win32com
class XQuery_t1101:
"""
classmethod get_instance() 를 사용하여, instance 를 만들어야함.
"""
def __init__(self):
self.is_data_received = False
def OnReceiveData(self, tr_code): # event handler
"""
이베스트 서버에서 ReceiveData 이벤트 받으면 실행되는 event handler
"""
self.is_data_received = True
name = self.GetFieldData("t1101OutBlock", "hname", 0)
price = self.GetFieldData("t1101OutBlock", "price", 0)
volume = self.GetFieldData("t1101OutBlock", "volume", 0)
print("종목; {0}".format(name))
print("현재가; {0}".format(price))
print("누적거래량; {0}".format(volume))
print("tr code ==> {0}".format(tr_code))
def single_request(self, stockcode):
self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\t1101.res" # RES 파일 등록
self.SetFieldData("t1101InBlock", "shcode", 0, stockcode) # 종목코드 설정
err_code = self.Request(False) # data 요청하기 -- 연속조회인경우만 True
if err_code < 0:
print("error... {0}".format(err_code))
@classmethod
def get_instance(cls):
# DispatchWithEvents로 instance 생성하기
xq_t1101 = win32com.client.DispatchWithEvents("XA_DataSet.XAQuery", cls)
return xq_t1101
if __name__ == "__main__":
def get_single_data():
xq_t1101 = XQuery_t1101.get_instance()
xq_t1101.single_request("005930") # 삼성전자.
while xq_t1101.is_data_received == False:
pythoncom.PumpWaitingMessages()
xsession = xing_login.XSession.get_instance()
xsession.api_login()
get_single_data()
<< 결과 창 >>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32com.client | |
import pythoncom | |
import xing_login | |
import win32com | |
class XQuery_t1101: | |
""" | |
classmethod get_instance() 를 사용하여, instance 를 만들어야함. | |
""" | |
def __init__(self): | |
self.is_data_received = False | |
def OnReceiveData(self, tr_code): # event handler | |
""" | |
이베스트 서버에서 ReceiveData 이벤트 받으면 실행되는 event handler | |
""" | |
self.is_data_received = True | |
name = self.GetFieldData("t1101OutBlock", "hname", 0) | |
price = self.GetFieldData("t1101OutBlock", "price", 0) | |
volume = self.GetFieldData("t1101OutBlock", "volume", 0) | |
print("종목; {0}".format(name)) | |
print("현재가; {0}".format(price)) | |
print("누적거래량; {0}".format(volume)) | |
print("tr code ==> {0}".format(tr_code)) | |
def single_request(self, stockcode): | |
self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\t1101.res" # RES 파일 등록 | |
self.SetFieldData("t1101InBlock", "shcode", 0, stockcode) # 종목코드 설정 | |
err_code = self.Request(False) # data 요청하기 -- 연속조회인경우만 True | |
if err_code < 0: | |
print("error... {0}".format(err_code)) | |
@classmethod | |
def get_instance(cls): | |
# DispatchWithEvents로 instance 생성하기 | |
xq_t1101 = win32com.client.DispatchWithEvents("XA_DataSet.XAQuery", cls) | |
return xq_t1101 | |
if __name__ == "__main__": | |
def get_single_data(): | |
xq_t1101 = XQuery_t1101.get_instance() | |
xq_t1101.single_request("005930") # 삼성전자. | |
while xq_t1101.is_data_received == False: | |
pythoncom.PumpWaitingMessages() | |
xsession = xing_login.XSession.get_instance() | |
xsession.api_login() | |
get_single_data() | |
반응형
'증권사 api' 카테고리의 다른 글
creon plus -- 당일 체결 data 받기 TR -- StockBid 사용 (0) | 2018.10.19 |
---|---|
xing api -- 실시간 데이터 조회 (6) | 2017.06.02 |
xing api -- 체결창 ; 반복 데이터(Occurs), 연속 데이터 조회 (2) | 2017.06.01 |
xing api -- 로그인후 증권계좌 조회하기 (2) | 2017.06.01 |
error 해결 -- U-CYBOS가 서버에 접속되어 있지 않습니다. (0) | 2015.08.16 |