(Python을 이용한 Quant 투자) 나만의 HTS만들기 : 실시간 개요창

Posted by : at

Category : Python



import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QWidget

class OverviewWidget(QWidget):
    def __init__(self, parent=None, ticker="BTC"):
        super().__init__(parent)
        uic.loadUi("overview.ui", self)

if __name__ == "__main__":
    import sys
    from PyQt5.QtWidgets import QApplication
    app = QApplication(sys.argv)
    ob = OverviewWidget()
    ob.show()
    exit(app.exec_())


import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import Qt, QDateTime, QThread, pyqtSignal
from pybithumb import WebSocketManager

class OverViewWorker(QThread):
    dataSent = pyqtSignal(int, float, float, int, float, int, float, int)

    def __init__(self, ticker):
        super().__init__()
        self.ticker = ticker
        self.alive = True

    def run(self):
        wm = WebSocketManager("ticker", [f"{self.ticker}_KRW"], ["24H"])
        while self.alive:
            data = wm.get()
            self.dataSent.emit(int  (data['content']['closePrice'    ]),
                               float(data['content']['chgRate'       ]),
                               float(data['content']['volume'        ]),
                               int  (data['content']['highPrice'     ]),
                               float(data['content']['value'         ]),
                               int  (data['content']['lowPrice'      ]),
                               float(data['content']['volumePower'   ]),
                               int  (data['content']['prevClosePrice']))

class OverviewWidget(QWidget):
    def __init__(self, parent=None, ticker="BTC"):
        super().__init__(parent)
        uic.loadUi("overview.ui", self)

if __name__ == "__main__":
    import sys
    from PyQt5.QtWidgets import QApplication
    app = QApplication(sys.argv)
    ob = OverviewWidget()
    ob.show()
    exit(app.exec_())

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import Qt, QDateTime, QThread, pyqtSignal
from pybithumb import WebSocketManager

class OverViewWorker(QThread):
    dataSent = pyqtSignal(int, float, float, int, float, int, float, int)

    def __init__(self, ticker):
        super().__init__()
        self.ticker = ticker
        self.alive = True

    def run(self):
        wm = WebSocketManager("ticker", [f"{self.ticker}_KRW"], ["24H"])
        while self.alive:
            data = wm.get()
            self.dataSent.emit(int  (data['content']['closePrice'    ]),
                               float(data['content']['chgRate'       ]),
                               float(data['content']['volume'        ]),
                               int  (data['content']['highPrice'     ]),
                               float(data['content']['value'         ]),
                               int  (data['content']['lowPrice'      ]),
                               float(data['content']['volumePower'   ]),
                               int  (data['content']['prevClosePrice']))

class OverviewWidget(QWidget):
    def __init__(self, parent=None, ticker="BTC"):
        super().__init__(parent)
        uic.loadUi("overview.ui", self)
        self.ticker = ticker
        
        self.ovw = OverViewWorker(ticker)
        self.ovw.dataSent.connect(self.fillData)
        self.ovw.start()

    def fillData(self, currPrice, chgRate, volume, highPrice, value, lowPrice, volumePower, prevClosePrice):
        self.label_1.setText(f"{currPrice:,}")
        self.label_2.setText(f"{chgRate:+.2f}%")
        self.label_4.setText(f"{volume:.4f} {self.ticker}")
        self.label_6.setText(f"{highPrice:,}")
        self.label_8.setText(f"{value/100000000:,.1f} 억")
        self.label_10.setText(f"{lowPrice:,}")
        self.label_12.setText(f"{volumePower:.2f}%")
        self.label_14.setText(f"{prevClosePrice:,}")

if __name__ == "__main__":
    import sys
    from PyQt5.QtWidgets import QApplication
    app = QApplication(sys.argv)
    ob = OverviewWidget()
    ob.show()
    exit(app.exec_())


import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import Qt, QDateTime, QThread, pyqtSignal
from pybithumb import WebSocketManager

class OverViewWorker(QThread):
    data24Sent = pyqtSignal(int, float, int, float, int, int)
    dataMidSent = pyqtSignal(int, float, float)

    def __init__(self, ticker):
        super().__init__()
        self.ticker = ticker
        self.alive = True

    def run(self):
        wm = WebSocketManager("ticker", [f"{self.ticker}_KRW"], ["24H", "MID"])
        while self.alive:
            data = wm.get()

            if data['content']['tickType'] == "MID":
                self.dataMidSent.emit(int  (data['content']['closePrice'    ]),
                                      float(data['content']['chgRate'       ]),
                                      float(data['content']['volumePower'   ]))
            else:
                self.data24Sent.emit(int  (data['content']['closePrice'    ]),
                                     float(data['content']['volume'        ]),
                                     int  (data['content']['highPrice'     ]),
                                     float(data['content']['value'         ]),
                                     int  (data['content']['lowPrice'      ]),
                                     int  (data['content']['prevClosePrice']))

class OverviewWidget(QWidget):
    def __init__(self, parent=None, ticker="BTC"):
        super().__init__(parent)
        uic.loadUi("overview.ui", self)
        self.ticker = ticker
        
        self.ovw = OverViewWorker(ticker)
        self.ovw.data24Sent.connect(self.fill24Data)
        self.ovw.dataMidSent.connect(self.fillMidData)
        self.ovw.start()

    def fill24Data(self, currPrice, volume, highPrice, value, lowPrice, prevClosePrice):
         self.label_1.setText(f"{currPrice:,}")
         self.label_4.setText(f"{volume:,.4f} {self.ticker}")
         self.label_6.setText(f"{highPrice:,}")
         self.label_8.setText(f"{value/100000000:,.1f} 억")
         self.label_10.setText(f"{lowPrice:,}")
         self.label_14.setText(f"{prevClosePrice:,}")
         self.__updateStyle()
 
    def fillMidData(self, currPrice, chgRate, volumePower):
         self.label_1.setText(f"{currPrice:,}")
         self.label_2.setText(f"{chgRate:+.2f}%")
         self.label_12.setText(f"{volumePower:.2f}%")
         self.__updateStyle()

    def __updateStyle(self):
         if '-' in self.label_2.text():
             self.label_1.setStyleSheet("color:blue;")
             self.label_2.setStyleSheet("background-color:blue;color:white")
         else:
             self.label_1.setStyleSheet("color:red;")
             self.label_2.setStyleSheet("background-color:red;color:white")

if __name__ == "__main__":
    import sys
    from PyQt5.QtWidgets import QApplication
    app = QApplication(sys.argv)
    ob = OverviewWidget()
    ob.show()
    exit(app.exec_())


About Taehyung Kim

안녕하세요? 8년차 현업 C++ 개발자 김태형이라고 합니다. 😁 C/C++을 사랑하며 다양한 사람과의 협업을 즐깁니다. ☕ 꾸준한 자기개발을 미덕이라 생각하며 노력중이며, 제가 얻은 지식을 홈페이지에 정리 중입니다. 좀 더 상세한 제 이력서 혹은 Private 프로젝트 접근 권한을 원하신다면 메일주세요. 😎

Star
Useful Links