98 lines
3.6 KiB
Python
98 lines
3.6 KiB
Python
|
|
# from tr.tr_0424 import Tr_0424
|
|
# tr_0424=Tr_0424()
|
|
import os
|
|
|
|
class Tr_sc1:
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def OnReceiveRealData(self,code): # event handler
|
|
"""
|
|
이베스트 서버에서 ReceiveRealData 이벤트 받으면 실행되는 event handler
|
|
"""
|
|
# self.count += 1
|
|
# #print('yeah')
|
|
# #print('자기소개2: ',dir(self))
|
|
stock_code = self.GetFieldData("OutBlock", "Isuno")[3:-3]
|
|
stock_name = self.GetFieldData("OutBlock", "Isunm")
|
|
# chetime = self.GetFieldData("OutBlock", "chetime")
|
|
ordno = self.GetFieldData("OutBlock", "ordno")#주문번호
|
|
volume = int(self.GetFieldData("OutBlock", "execqty"))
|
|
#1 매도 2 매수
|
|
side = int(self.GetFieldData("OutBlock", "bnstp"))
|
|
contract_price = int(self.GetFieldData("OutBlock", "execprc"))
|
|
|
|
|
|
|
|
|
|
if len(stock_code) > 10:
|
|
stock_code=stock_code[3:-3]
|
|
|
|
|
|
if (stock_code is not None and
|
|
stock_name is not None and
|
|
volume is not None and
|
|
side is not None and
|
|
contract_price is not None):
|
|
|
|
|
|
self.process_balance_change_echo(stock_code,volume,side,contract_price,stock_name,ordno)
|
|
|
|
|
|
# open = int(self.GetFieldData("OutBlock", "open"))
|
|
# drate = float(self.GetFieldData("OutBlock", "drate"))
|
|
# #print('코스닥 코드: ',stock_code)
|
|
# # #print('drate: ',drate)
|
|
# # #print('chetime: ',chetime)
|
|
# # chetime = self.GetFieldData("OutBlock", "chetime")
|
|
# volume = int(self.GetFieldData("OutBlock", "cvolume"))#cvolume이 체결거래량이고 그냥 볼륨은 누적거래량임
|
|
# accu_volume = int(self.GetFieldData("OutBlock", "volume"))#누적거래대금
|
|
# value = int(self.GetFieldData("OutBlock", "value"))#누적거래대금
|
|
# side = self.GetFieldData("OutBlock", "cgubun")
|
|
|
|
#print('스톡코드: ',stock_code)
|
|
#print('stock_name: ',stock_name)
|
|
#print('volume: ',volume)
|
|
#print('side: ',side)
|
|
#print('contract_price: ',contract_price)
|
|
|
|
|
|
|
|
def initialize_process_balance_change(self,process_balance_change):
|
|
#print('k3 initialize_process_balance_change @#@#@#@#@#@#@#')
|
|
self.process_balance_change=process_balance_change
|
|
|
|
def start(self,process_balance_change_echo):
|
|
self.process_balance_change_echo=process_balance_change_echo
|
|
#print('체결 리얼 스타트: ')
|
|
#print('자기소개 체결: ',dir(self))
|
|
|
|
"""
|
|
이베스트 서버에 실시간 data 요청함.
|
|
"""
|
|
|
|
|
|
the_path=os.environ.get('ROOT_FILE_PATH')
|
|
# self.ResFileName = the_path+"\\Res\\SC1.res"
|
|
# self.LoadFromResFile = the_path+"\\Res\\SC1.res"
|
|
|
|
self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\SC1.res" # RES 파일 등록
|
|
# self.SetFieldData("InBlock", "shcode", stock_code)
|
|
self.AdviseRealData() # 실시간데이터 요청
|
|
# self.AdviseLinkFromHTS() # 실시간데이터 요청
|
|
#print('체결 리얼 스타트 끝: ')
|
|
|
|
def add_item(self, stockcode):
|
|
# 실시간데이터 요청 종목 추가
|
|
self.SetFieldData("InBlock", "shcode", stockcode)
|
|
|
|
self.AdviseRealData()
|
|
|
|
def remove_item(self, stockcode):
|
|
# stockcode 종목만 실시간데이터 요청 취소
|
|
self.UnadviseRealDataWithKey(stockcode)
|
|
|
|
def end(self):
|
|
self.UnadviseRealData() # 실시간데이터 요청 모두 취소
|