304 lines
8.2 KiB
Python
304 lines
8.2 KiB
Python
from PySide2.QtWidgets import QApplication,QMainWindow
|
|
from PySide2.QtUiTools import QUiLoader
|
|
from PySide2.QtCore import QObject, QEvent, QTimer, QCoreApplication
|
|
|
|
import sys
|
|
# from button_holder import ButtonHolder
|
|
# from slider import SliderHolder
|
|
# from rockwidget import RockWidget
|
|
from main_window import Main_window
|
|
from balance_window import Balance_window
|
|
# from test import Test
|
|
# from ui.ui_test import Ui_Test
|
|
# from second_window import Second_Window
|
|
import time
|
|
from threading import Thread
|
|
|
|
from tr.tr_master import Tr_master
|
|
# from tr.tr_sc0 import Tr_sc0
|
|
# from tr.tr_sc1 import Tr_sc1
|
|
from tr.tr_0424 import Tr_0424
|
|
from tr.tr_pending import Tr_pending
|
|
|
|
import win32com.client #이베스트 관련
|
|
import pythoncom #이베스트 관련
|
|
|
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
|
|
from apscheduler.schedulers.qt import QtScheduler
|
|
|
|
from dotenv import load_dotenv
|
|
import os
|
|
|
|
# load .env
|
|
load_dotenv()
|
|
|
|
loader=QUiLoader()
|
|
|
|
app=QApplication(sys.argv)
|
|
|
|
the_path=os.path.dirname(__file__)
|
|
os.environ['ROOT_FILE_PATH'] = the_path
|
|
|
|
|
|
|
|
#meta class conflict 나서 서브클래스로 하면 안 됨 미리 선언하고 생성자로 넘겨야됨
|
|
# class XReal_S3_:
|
|
# def __init__(self):
|
|
# super().__init__()
|
|
# self.count = 0
|
|
|
|
# def OnReceiveRealData(self, tr_code): # event handler
|
|
# """
|
|
# 이베스트 서버에서 ReceiveRealData 이벤트 받으면 실행되는 event handler
|
|
# """
|
|
# self.count += 1
|
|
# shcode = self.GetFieldData("OutBlock", "shcode")
|
|
# # price = self.GetFieldData("OutBlock", "price")
|
|
# # chetime = self.GetFieldData("OutBlock", "chetime")
|
|
|
|
# if shcode is
|
|
|
|
|
|
# #print('shcode: ',shcode)
|
|
# #print('price: ',price)
|
|
# #print('chetime: ',chetime)
|
|
# # window.set_the_stock_code(price)
|
|
|
|
# def start(self,stock_code):
|
|
# """
|
|
# 이베스트 서버에 실시간 data 요청함.
|
|
# """
|
|
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\S3_.res" # RES 파일 등록
|
|
# self.SetFieldData("InBlock", "shcode", stock_code)
|
|
# self.AdviseRealData() # 실시간데이터 요청
|
|
|
|
# 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() # 실시간데이터 요청 모두 취소
|
|
|
|
|
|
#meta class conflict 나서 서브클래스로 하면 안 됨 미리 선언하고 생성자로 넘겨야됨 끝
|
|
|
|
SHUT_DOWN_FLAG=False
|
|
|
|
# def set_shut_down_flag():
|
|
# SHUT_DOWN_FLAG=True
|
|
# #print('SHUT_DOWN_FLAG: ',SHUT_DOWN_FLAG)
|
|
|
|
|
|
|
|
tr_pending=win32com.client.DispatchWithEvents("XA_DataSet.XAQuery",Tr_pending)#미체결티알
|
|
tr_0424=win32com.client.DispatchWithEvents("XA_DataSet.XAQuery",Tr_0424)#계좌티알
|
|
|
|
|
|
balance_window=Balance_window(tr_pending)
|
|
#이베스트 로그인
|
|
STAND_BY = 0
|
|
RECEIVED = 1
|
|
|
|
class XASessionEvents:
|
|
login_state = STAND_BY
|
|
|
|
login_cnt=0
|
|
|
|
def OnLogin(self, code, msg):
|
|
XASessionEvents.login_state = RECEIVED
|
|
# time.sleep(5)
|
|
# print('로그인 결과: ',msg)
|
|
# print('로그인 결과 code: ',code)
|
|
if code=='0000':
|
|
query.single_request(tr_0424,balance_window,tr_pending)
|
|
res=self.account_info()
|
|
if res is not None:
|
|
window.show_buttons()
|
|
window.set_status_label('로그인 성공')
|
|
|
|
# tr_0424.init_get_account()
|
|
else:
|
|
self.login_cnt+=1
|
|
if self.login_cnt <5:
|
|
window.set_status_label(f'로그인 실패. 남은 회수 {self.login_cnt} / 5')
|
|
else:
|
|
window.set_status_label(f'로그인 실패. 재시도 회수를 초과했습니다')
|
|
|
|
if self.login_cnt >5:
|
|
pass
|
|
|
|
|
|
|
|
|
|
# window.set_the_text(msg)
|
|
def OnDisconnect(self, code, msg):
|
|
pass
|
|
|
|
def account_info(self):
|
|
"""
|
|
계좌 정보 조회
|
|
"""
|
|
|
|
account_no = self.GetAccountListCount()
|
|
|
|
if account_no is not None:
|
|
|
|
# print("계좌 갯수 = {0}".format(account_no))
|
|
|
|
# for i in range(account_no):
|
|
# account = self.GetAccountList(i)
|
|
# #print("계좌번호 = {0}".format(account))
|
|
|
|
|
|
self.account = self.GetAccountList(0)
|
|
os.environ['ACCOUNT'] = self.GetAccountList(0)
|
|
return 1
|
|
|
|
else:
|
|
return None
|
|
|
|
class XAQueryEvents:
|
|
query_state = STAND_BY
|
|
def OnReceiveData(self, code):
|
|
XAQueryEvents.query_state = RECEIVED
|
|
def OnReceiveMessage(self, error, nMessageCode, szMessage):
|
|
#print(szMessage)
|
|
pass
|
|
|
|
session=win32com.client.DispatchWithEvents("XA_Session.XASession",XASessionEvents)
|
|
|
|
url=os.environ.get('URL')
|
|
port=os.environ.get('PORT')
|
|
server_type=os.environ.get('SERVER_TYPE')
|
|
|
|
id=os.environ.get('ID')
|
|
pw=os.environ.get('PW')
|
|
cert=os.environ.get('CERT')
|
|
account = os.environ.get('ACCOUNT')
|
|
|
|
|
|
window=Main_window(session,balance_window)
|
|
window.show()
|
|
|
|
|
|
|
|
result=session.ConnectServer(url,port)
|
|
|
|
#이베스트 로그인 끝
|
|
|
|
|
|
#마스터 테스트
|
|
|
|
query=win32com.client.DispatchWithEvents("XA_DataSet.XAQuery",Tr_master)
|
|
|
|
|
|
|
|
# while Tr_master.query_state == False:
|
|
# pythoncom.PumpWaitingMessages()
|
|
|
|
|
|
|
|
#마스터 테스트 끝
|
|
|
|
|
|
#데몬쓰레드 테스트
|
|
|
|
|
|
|
|
#데몬쓰레드 테스트 끝
|
|
|
|
|
|
|
|
|
|
#리얼 테스트
|
|
|
|
# class XReal_S3_:
|
|
# def __init__(self):
|
|
# super().__init__()
|
|
# self.count = 0
|
|
|
|
# def OnReceiveRealData(self, tr_code): # event handler
|
|
# """
|
|
# 이베스트 서버에서 ReceiveRealData 이벤트 받으면 실행되는 event handler
|
|
# """
|
|
# self.count += 1
|
|
# shcode = self.GetFieldData("OutBlock", "shcode")
|
|
# price = self.GetFieldData("OutBlock", "price")
|
|
# chetime = self.GetFieldData("OutBlock", "chetime")
|
|
# #print('shcode: ',shcode)
|
|
# #print('price: ',price)
|
|
# #print('chetime: ',chetime)
|
|
# window.set_the_stock_code(price)
|
|
|
|
# def start(self,stock_code):
|
|
# """
|
|
# 이베스트 서버에 실시간 data 요청함.
|
|
# """
|
|
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\S3_.res" # RES 파일 등록
|
|
# self.SetFieldData("InBlock", "shcode", stock_code)
|
|
# self.AdviseRealData() # 실시간데이터 요청
|
|
|
|
# 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() # 실시간데이터 요청 모두 취소
|
|
|
|
# xreal = win32com.client.DispatchWithEvents("XA_DataSet.XAReal", XReal_S3_)
|
|
|
|
# xreal.start('005930')
|
|
|
|
# # for i in range(100):
|
|
# # #print('try: {}'.format(i))
|
|
# # pythoncom.PumpWaitingMessages()
|
|
# # await asyncio.sleep(0)
|
|
|
|
# while True:
|
|
# pythoncom.PumpWaitingMessages()
|
|
# # if xreal.count == 5:
|
|
# # xreal.add_item("003490") # 대한항공 추가
|
|
|
|
# # if xreal.count == 20:
|
|
# # xreal.remove_item("005930")
|
|
# #000660
|
|
|
|
# # if xreal.count == 30:
|
|
# # xreal.end()
|
|
# # time.sleep(10)
|
|
# # #print("---- end -----")
|
|
# # break
|
|
|
|
# # await asyncio.sleep(0)
|
|
|
|
|
|
# @app.on_event('startup')
|
|
# def init_data():
|
|
|
|
# async_scheduler = AsyncIOScheduler()
|
|
# async_scheduler.add_job(spider_batch.ping_to_db, 'cron', second='*/15',args=[app])
|
|
# async_scheduler.start()
|
|
|
|
|
|
# def yeah():
|
|
# #print('YEAH!!!!')
|
|
|
|
# scheduler = QtScheduler()
|
|
# scheduler.add_job(yeah, 'interval', seconds=5)
|
|
# scheduler.start()
|
|
|
|
|
|
app.exec_()
|
|
|