b 상승장 알리미2 » 이력 » 버전 2
이태훈, 2025/02/04 06:37
| 1 | 1 | 이태훈 | h1. 상승장 알리미2 |
|---|---|---|---|
| 2 | 2 | 이태훈 | |
| 3 | h3. 소스코드 |
||
| 4 | |||
| 5 | <pre> |
||
| 6 | import sys |
||
| 7 | import pybithumb |
||
| 8 | from PyQt5.QtWidgets import * |
||
| 9 | from PyQt5 import uic |
||
| 10 | from PyQt5.QtCore import * |
||
| 11 | |||
| 12 | tickers = ["BTC", "ETH", "XRP"] |
||
| 13 | form_class = uic.loadUiType("05_20_1.ui")[0] |
||
| 14 | |||
| 15 | class MyWindow(QMainWindow, form_class): |
||
| 16 | def __init__(self): |
||
| 17 | super().__init__() |
||
| 18 | self.setupUi(self) |
||
| 19 | |||
| 20 | timer = QTimer(self) |
||
| 21 | timer.start(5000) |
||
| 22 | timer.timeout.connect(self.timeout) |
||
| 23 | |||
| 24 | def get_market_infos(self, ticker): |
||
| 25 | df = pybithumb.get_ohlcv(ticker) |
||
| 26 | ma5 = df['close'].rolling(window=5).mean() |
||
| 27 | last_ma5 = ma5.iloc[-2] |
||
| 28 | price = pybithumb.get_current_price(ticker) |
||
| 29 | |||
| 30 | state = None |
||
| 31 | if price > last_ma5: |
||
| 32 | state = "상승장" |
||
| 33 | else: |
||
| 34 | state = "하락장" |
||
| 35 | return price, last_ma5, state |
||
| 36 | |||
| 37 | def timeout(self): |
||
| 38 | for i, ticker in enumerate(tickers): |
||
| 39 | item = QTableWidgetItem(ticker) |
||
| 40 | self.tableWidget.setItem(i, 0, item) |
||
| 41 | |||
| 42 | price, last_ma5, state = self.get_market_infos(ticker) |
||
| 43 | self.tableWidget.setItem(i, 1, QTableWidgetItem(str(price))) |
||
| 44 | self.tableWidget.setItem(i, 2, QTableWidgetItem(str(last_ma5))) |
||
| 45 | self.tableWidget.setItem(i, 3, QTableWidgetItem(state)) |
||
| 46 | |||
| 47 | app = QApplication(sys.argv) |
||
| 48 | window = MyWindow() |
||
| 49 | window.show() |
||
| 50 | app.exec_() |
||
| 51 | </pre> |
||
| 52 | |||
| 53 | h3. 결과 |
||
| 54 | |||
| 55 | !clipboard-202502041537-2ilwg.png! |