파이썬 API 이용한 키움증권 정보 가져 오는 소스 인데요
-
게시물 수정 , 삭제는 로그인 필요
from PyQt5.QAxContainer import *
from PyQt5.QtCore import *
from config.errorCode import *
class Kiwoom(QAxWidget):
def __init__(self):
super().__init__()
print("Kiwoom 클래스 입니다.")
#### 이벤트 루프 모음
self.login_event_loop = None
self.detail_account_info_event_loop = None
self.detail_account_info_event_loop_2 = None
#####################
#### 변수 모음
self.account_num = None
예수금 = 0 # 예수금 변수
#####################
self.get_ocx_instance()
self.event_slots()
self.signal_login_commConnect()
self.get_account_info()
self.detail_account_info() #예수금 가져오는 것
self.detail_account_mystock() #계좌평가 잔고내역 요청
def get_ocx_instance(self):
self.setControl("KHOPENAPI.KHOpenAPICtrl.1")
def event_slots(self):
self.OnEventConnect.connect(self.login_slot)
self.OnReceiveTrData.connect(self.trdata_slot)
def signal_login_commConnect(self):
self.dynamicCall("CommConnect()")
self.login_event_loop = QEventLoop()
self.login_event_loop.exec_()
def login_slot(self, errCode):
print(errors(errCode))
self.login_event_loop.exit()
def get_account_info(self):
account_list = self.dynamicCall("GetLoginInfo(String)", "ACCNO")
self.account_num = account_list.split(';')[0]
print("\n나의 보유 계좌번호 %s" % self.account_num)
def detail_account_info(self):
# 예수금 가져오는 부분
self.dynamicCall("SetInputValue(String, String)", "계좌번호", self.account_num)
self.dynamicCall("SetInputValue(String, String)", "비밀번호", "0000")
self.dynamicCall("SetInputValue(String, String)", "비밀번호입력매체구분", "00")
self.dynamicCall("SetInputValue(String, String)", "조회구분", "2")
self.dynamicCall("CommRqData(String, String, int, String)", "예수금상세현황요청", "opw00001", "0", "2000")
self.detail_account_info_event_loop = QEventLoop()
self.detail_account_info_event_loop.exec_()
def detail_account_mystock(self, sPrevNext="0"):
# 계좌평가 잔고 내역 요청
self.dynamicCall("SetInputValue(String, String)", "계좌번호", self.account_num)
self.dynamicCall("SetInputValue(String, String)", "비밀번호", "0000")
self.dynamicCall("SetInputValue(String, String)", "비밀번호입력매체구분", "00")
self.dynamicCall("SetInputValue(String, String)", "조회구분", "2")
self.dynamicCall("CommRqData(String, String, int, String)", "계좌평가잔고내역요청", "opw00018", sPrevNext, "2000")
self.detail_account_info_event_loop_2 = QEventLoop()
self.detail_account_info_event_loop_2.exec_()
def trdata_slot(self, sScrNo, sRQName, sTrCode, sRecordName, sPrevNext):
# sScrno : 스크린번호
# sRQName : 내가 요청 했을 때 지은 이름
# sTrCode : 요청 id, tr코드
# sRecordName : 사용 안함
# sPrevNext : 다음 페이지가 있는지
if sRQName == "예수금상세현황요청":
예수금 = self.dynamicCall("GetCommData(String, String, int, String)", sTrCode, sRQName, 0, "예수금")
print("예수금 : {0:,} 원".format(int(예수금)))
예수금 = int(예수금)
출금가능금액 = self.dynamicCall("GetCommData(String, String, int, String)", sTrCode, sRQName, 0, "출금가능금액")
print("출금가능금액 : {0:,} 원".format(int(출금가능금액)))
self.detail_account_info_event_loop.exit()
elif sRQName == "계좌평가잔고내역요청":
총매입금액 = self.dynamicCall("GetCommData(String, String, int, String)", sTrCode, sRQName, 0, "총매입금액")
print("\n총매입금액 : {0:,} 원".format(int(총매입금액)))
총수익률 = self.dynamicCall("GetCommData(String, String, int, String)", sTrCode, sRQName, 0, "총수익률(%)")
print("총수익률(%) : {0:+.2f} %".format((float(총수익률))))
self.detail_account_info_event_loop_2.exit()
--------------------------------
D+2 에 있는 예수금을 가져 오고 싶거든요
어디 부분을 어떻게 수정 해야 할지 모르겠어요
좀 알려 주세요
#파이썬 api #파이썬 api 호출 #파이썬 api 만들기 #파이썬 api 서버 구축 #파이썬 api 데이터 가져오기 #파이썬 api 호출 예제 #파이썬 api 사용법 #파이썬 api json 파싱 #파이썬 api란 #파이썬 api 서버