파이썬

키움증권 OpenAPI 당황스러움

by nanumi posted Sep 06, 2021
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

키움증권 OpenAPI 당황스러움

 

API로 호가를 가져오는 과정에서

 

매수6번째의 호가에서 계속 오류가 난다.

코딩 소스를 아무리 들여다봐도 감이 오지 않았다.

 

그런데, TR목록에서 황당한 일이...?

다른 호가는 매수X차선호가 인데 

6번째는 매수6우선호가이다.

 

6번만 차선이 아닌 우선이었다.

수정완료로 정상처리됨.

아~~~ 피곤하네.

 

1.png

 

 

        if sRQName == "호가":
            s_ho0 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매도최우선호가")
#            s_ho1 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매도1차선호가")
            s_ho2 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매도2차선호가")
            s_ho3 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매도3차선호가")
            s_ho4 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매도4차선호가")
            s_ho5 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매도5차선호가")
            s_ho6 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매도6차선호가")
            s_ho7 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매도7차선호가")
            s_ho8 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매도8차선호가")
            s_ho9 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매도9차선호가")
            s_ho10 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매도10차선호가")

            b_ho0 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매수최우선호가")
#            b_ho1 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매수1차선호가")
            b_ho2 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매수2차선호가")
            b_ho3 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매수3차선호가")
            b_ho4 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매수4차선호가")
            b_ho5 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매수5차선호가")
            b_ho6 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매수6우선호가")
            b_ho7 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매수7차선호가")
            b_ho8 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매수8차선호가")
            b_ho9 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매수9차선호가")
            b_ho10 = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "매수10차선호가")

            print("매도1 : %s     매수1 : %s" % (s_ho0.strip(), b_ho0.strip()))
            #print("매도1 : %s     매수1 : %s" % (s_ho1.strip(), b_ho1.strip()))  ## 1호가는 출력안됨. 최우선이 1번으로 중복되어서 그런가?
            print("매도2 : %s     매수2 : %s" % (s_ho2.strip(), b_ho2.strip()))
            print("매도3 : %s     매수3 : %s" % (s_ho3.strip(), b_ho3.strip()))
            print("매도4 : %s     매수4 : %s" % (s_ho4.strip(), b_ho4.strip()))
            print("매도5 : %s     매수5 : %s" % (s_ho5.strip(), b_ho5.strip()))
            print("매도6 : %s     매수6 : %s" % (s_ho6.strip(), b_ho6.strip()))
            print("매도7 : %s     매수7 : %s" % (s_ho7.strip(), b_ho7.strip()))
            print("매도8 : %s     매수8 : %s" % (s_ho8.strip(), b_ho8.strip()))
            print("매도9 : %s     매수9 : %s" % (s_ho9.strip(), b_ho9.strip()))
            print("매도10 : %s     매수10 : %s" % (s_ho10.strip(), b_ho10.strip()))

#            data_ho = { '매도호가' :{'매도1호가': abs(int(s_ho0.strip())), '매도2호가': abs(int(s_ho2.strip())), '매도3호가': abs(int(s_ho3.strip())), '매도4호가': abs(int(s_ho4.strip())), '매도5호가': abs(int(s_ho5.strip())),'매도6호가': abs(int(s_ho6.strip())),'매도7호가': abs(int(s_ho7.strip())),'매도8호가': abs(int(s_ho8.strip())),'매도9호가': abs(int(s_ho9.strip())),'매도10호가': abs(int(s_ho10.strip()))},'매수호가' :{'매수1호가': abs(int(b_ho0.strip())), '매수2호가': abs(int(b_ho2.strip())), '매수3호가': abs(int(b_ho3.strip())), '매수4호가': abs(int(b_ho4.strip())), '매수5호가': abs(int(b_ho5.strip())),'매수6호가': abs(int(b_ho6.strip())),'매수7호가': abs(int(b_ho7.strip())),'매수8호가': abs(int(b_ho8.strip())),'매수9호가': abs(int(b_ho9.strip())),'매수10호가': abs(int(b_ho10.strip()))}}
#            print(data_ho.keys(),data_ho.values())

            data_ho = { '매도호가' :
                            {'매도1호가': abs(int(s_ho0.strip())),
                             '매도2호가': abs(int(s_ho2.strip())),
                             '매도3호가': abs(int(s_ho3.strip())),
                             '매도4호가': abs(int(s_ho4.strip())),
                             '매도5호가': abs(int(s_ho5.strip())),
                             '매도6호가': abs(int(s_ho6.strip())),
                             '매도7호가': abs(int(s_ho7.strip())),
                             '매도8호가': abs(int(s_ho8.strip())),
                             '매도9호가': abs(int(s_ho9.strip())),
                             '매도10호가': abs(int(s_ho10.strip()))
                             },
                        '매수호가' :
                            {'매수1호가': abs(int(b_ho0.strip())),
                             '매수2호가': abs(int(b_ho2.strip())),
                             '매수3호가': abs(int(b_ho3.strip())),
                             '매수4호가': abs(int(b_ho4.strip())),
                             '매수5호가': abs(int(b_ho5.strip())),
                             '매수6호가': abs(int(b_ho6.strip())),
                             '매수7호가': abs(int(b_ho7.strip())),
                             '매수8호가': abs(int(b_ho8.strip())),
                             '매수9호가': abs(int(b_ho9.strip())),
                             '매수10호가': abs(int(b_ho10.strip()))}}
            print(data_ho.keys(),data_ho.values())