At 빗썸 개요창 » 이력 » 버전 1
이태훈, 2025/02/12 13:43
| 1 | 1 | 이태훈 | h1. At 빗썸 개요창 |
|---|---|---|---|
| 2 | |||
| 3 | h3. 소스코드 |
||
| 4 | |||
| 5 | <pre> |
||
| 6 | import sys |
||
| 7 | from PyQt5 import uic |
||
| 8 | from PyQt5.QtWidgets import QWidget, QApplication |
||
| 9 | from PyQt5.QtCore import Qt, QThread, pyqtSignal |
||
| 10 | from pybithumb import WebSocketManager |
||
| 11 | |||
| 12 | class OverViewWorker(QThread): |
||
| 13 | dataMidSent = pyqtSignal(int, float, float) |
||
| 14 | data24Sent = pyqtSignal(float, int, float, int, int) |
||
| 15 | |||
| 16 | def __init__(self, ticker): |
||
| 17 | super().__init__() |
||
| 18 | self.ticker = ticker |
||
| 19 | self.alive = True |
||
| 20 | |||
| 21 | def run(self): |
||
| 22 | wm = WebSocketManager("ticker", [f"{self.ticker}_KRW"], ["24H", "MID"]) |
||
| 23 | while self.alive: |
||
| 24 | data = wm.get() |
||
| 25 | |||
| 26 | if data['content']['tickType'] == "MID": |
||
| 27 | self.dataMidSent.emit(int(data['content']['closePrice']), |
||
| 28 | float(data['content']['chgRate']), |
||
| 29 | float(data['content']['volumePower'])) |
||
| 30 | else : |
||
| 31 | self.data24Sent.emit(float(data['content']['volume']), |
||
| 32 | int(data['content']['highPrice']), |
||
| 33 | float(data['content']['value']), |
||
| 34 | int(data['content']['lowPrice']), |
||
| 35 | int(data['content']['prevClosePrice'])) |
||
| 36 | |||
| 37 | wm.terminate() # 해당코드가 없으면 종료가 제대로 이루어지지않음. |
||
| 38 | |||
| 39 | def close(self): |
||
| 40 | self.alive = False |
||
| 41 | |||
| 42 | class OverviewWidget(QWidget): |
||
| 43 | def __init__(self, parent=None, ticker="BTC"): |
||
| 44 | super().__init__(parent) |
||
| 45 | uic.loadUi("resource/overview.ui", self) |
||
| 46 | self.setWindowTitle("실시간 개요창") |
||
| 47 | |||
| 48 | self.ticker = ticker |
||
| 49 | |||
| 50 | self.label_3.setText("거래량(24H)") |
||
| 51 | self.label_5.setText("고가(당일)") |
||
| 52 | self.label_7.setText("거래금액(24H)") |
||
| 53 | self.label_9.setText("저가(당일)") |
||
| 54 | self.label_11.setText("채결강도(24H)") |
||
| 55 | self.label_13.setText("전일종가") |
||
| 56 | |||
| 57 | self.ovw = OverViewWorker(ticker) |
||
| 58 | self.ovw.dataMidSent.connect(self.fillMidData) |
||
| 59 | self.ovw.data24Sent.connect(self.fill24Data) |
||
| 60 | self.ovw.start() |
||
| 61 | |||
| 62 | def closeEvent(self, event): |
||
| 63 | self.ovw.close() |
||
| 64 | |||
| 65 | def fillMidData(self, currPrice, chgRate, volumePower): |
||
| 66 | self.label_1.setText(f"{currPrice:,}") |
||
| 67 | self.label_2.setText(f"{chgRate:+.2f}%") |
||
| 68 | self.label_12.setText(f"{volumePower:.2f}%") |
||
| 69 | self.__updateStyle() |
||
| 70 | |||
| 71 | def fill24Data(self, volume, highPrice, value, lowPrice, prevClosePrice): |
||
| 72 | self.label_4.setText(f"{volume:,.4f} {self.ticker}") |
||
| 73 | self.label_6.setText(f"{highPrice:,}") |
||
| 74 | self.label_8.setText(f"{value/100000000:,.1f} 억") |
||
| 75 | self.label_10.setText(f"{lowPrice:,}") |
||
| 76 | self.label_14.setText(f"{prevClosePrice:,}") |
||
| 77 | self.__updateStyle() |
||
| 78 | |||
| 79 | def __updateStyle(self): |
||
| 80 | if '-' in self.label_2.text(): |
||
| 81 | self.label_1.setStyleSheet("color:blue;") |
||
| 82 | self.label_2.setStyleSheet("background-color:blue;color:white") |
||
| 83 | else: |
||
| 84 | self.label_1.setStyleSheet("color:red;") |
||
| 85 | self.label_2.setStyleSheet("background-color:red;color:white") |
||
| 86 | |||
| 87 | if __name__ == "__main__": |
||
| 88 | app = QApplication(sys.argv) |
||
| 89 | ob = OverviewWidget() |
||
| 90 | ob.show() |
||
| 91 | exit(app.exec_()) |
||
| 92 | </pre> |
||
| 93 | |||
| 94 | h3. 결과 |
||
| 95 | |||
| 96 | !clipboard-202502122243-4knts.png! |