키움증권 openAPI 15번 - 현재접속상태를 반환한다.

2023. 1. 17. 19:31시스템트레이딩

728x90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
from PyQt5.QtWidgets import *
from PyQt5.QAxContainer import *
from PyQt5.QtCore import *
 
class Kiwoom(QAxWidget):
    def __init__(self):
        super().__init__()
        self._create_kiwoom_instance()
        self._set_signal_slots()
 
    def _create_kiwoom_instance(self):
        self.setControl("KHOPENAPI.KHOpenAPICtrl.1")
 
    def _set_signal_slots(self):
        self.OnEventConnect.connect(self._event_connect)
 
    def comm_connect(self):
        self.dynamicCall("CommConnect()")
        self.login_event_loop = QEventLoop()
        self.login_event_loop.exec_()
 
    def _event_connect(self, err_code):
        if err_code == 0:
            print("connected")
        else:
            print("disconnected")
 
        self.login_event_loop.exit()
 
    def get_connect_state(self):
        code_list = self.dynamicCall("GetConnectState()")
        return code_list
 
if __name__ == "__main__":
    app = QApplication(sys.argv)
    kiwoom = Kiwoom()
    kiwoom.comm_connect()
 
    
    res = kiwoom.get_connect_state()
    print("res : ", res)
 
 
 
cs현재

 

현재 접속 상태를 반환한다.

결과값

728x90