이하영

open api connection

# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/proj.iml" filepath="$PROJECT_DIR$/.idea/proj.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
from PyQt5.QtWidgets import *
from PyQt5.QAxContainer import *
from PyQt5.QtCore import *
from pandas import DataFrame
import time
import sys
import logging.handlers
# set formatter object
formatter = logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s > %(message)s')
logger = logging.getLogger("crumbs")
logger.setLevel(logging.DEBUG)
# set handler object
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(formatter)
logger.addHandler(streamHandler)
TR_REQ_TIME_INTERVAL = 0.2
class OpenApi(QAxWidget):
def __init__(self):
super().__init__()
# event_loop list
self.login_event_loop=None
self._get_instance()
self._event_slot()
self.comm_connect()
self.account_info()
# get ocx controller for kioom open api
def _get_instance(self):
try:
self.setControl("KHOPENAPI.KHOpenAPICtrl.1")
except Exception as e:
logger.critical(e)
# deal events for using open api
def _event_slot(self):
try:
self.OnEventConnect.connect(self.login_slot)
except Exception as e:
logger.critical(e)
# if login event success, return errCode=0
def login_slot(self,errCode):
try:
if errCode==0:
logger.debug("connected")
else:
logger.debug("failed to connect. err_code : "+errCode)
self.login_event_loop.exit()
except Exception as e:
logger.critical(e)
# try login
def comm_connect(self):
try:
self.dynamicCall("CommConnect()")
self.login_event_loop = QEventLoop() # wait for login complete
self.login_event_loop.exec_()
except Exception as e:
logger.critical(e)
# get user account information
def get_login_info(self,tag):
try:
ret=self.dynamicCall("GetLoginInfo(QString)",tag)
return ret
except Exception as e:
logger.critical(e)
# print user account information
def account_info(self):
try:
account_number=self.get_login_info("ACCNO")
self.account_no=account_number.split(";")[0]
logger.debug("계좌번호 : "+self.account_no)
except AttributeError as e:
logger.critical(e)
if __name__ == "__main__":
app = QApplication(sys.argv)
OpenApi()
\ No newline at end of file