U 실시간 데이터 출력(pyupbit) » 이력 » 버전 1
이태훈, 2025/02/10 03:37
| 1 | 1 | 이태훈 | h1. 실시간 데이터 출력(pyupbit) |
|---|---|---|---|
| 2 | |||
| 3 | h3. 소스코드 |
||
| 4 | |||
| 5 | <pre> |
||
| 6 | import sys |
||
| 7 | from pyupbit import WebSocketManager |
||
| 8 | from PyQt5.QtWidgets import * |
||
| 9 | from PyQt5.QtCore import * |
||
| 10 | |||
| 11 | class Worker(QThread): |
||
| 12 | recv = pyqtSignal(dict) |
||
| 13 | |||
| 14 | def run(self): |
||
| 15 | # create websocket for Upbit |
||
| 16 | wm = WebSocketManager("ticker", ["KRW-BTC"]) |
||
| 17 | |||
| 18 | while True: |
||
| 19 | data = wm.get() |
||
| 20 | print(data) |
||
| 21 | self.recv.emit(data) |
||
| 22 | |||
| 23 | class MyWindow(QMainWindow): |
||
| 24 | def __init__(self): |
||
| 25 | super().__init__() |
||
| 26 | |||
| 27 | label = QLabel("BTC", self) |
||
| 28 | label.move(20, 20) |
||
| 29 | |||
| 30 | self.price = QLabel("", self) |
||
| 31 | self.price.move(80, 20) |
||
| 32 | self.price.resize(100, 20) |
||
| 33 | |||
| 34 | button = QPushButton("Start", self) |
||
| 35 | button.move(20, 50) |
||
| 36 | button.clicked.connect(self.click_btn) |
||
| 37 | |||
| 38 | self.th = Worker() |
||
| 39 | self.th.recv.connect(self.receive_msg) |
||
| 40 | |||
| 41 | @pyqtSlot(dict) |
||
| 42 | def receive_msg(self, data): |
||
| 43 | print(data) |
||
| 44 | close_price = data.get("trade_price") |
||
| 45 | self.price.setText(str(close_price)) |
||
| 46 | |||
| 47 | def click_btn(self): |
||
| 48 | self.th.start() |
||
| 49 | |||
| 50 | if __name__ == "__main__": |
||
| 51 | app = QApplication(sys.argv) |
||
| 52 | mywindow = MyWindow() |
||
| 53 | mywindow.show() |
||
| 54 | app.exec_() |
||
| 55 | </pre> |
||
| 56 | |||
| 57 | h3. 결과 |
||
| 58 | |||
| 59 | !clipboard-202502101237-q8nq7.png! |
||
| 60 | |||
| 61 | |||
| 62 | <pre> |
||
| 63 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147805000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70382909032.02036, 'change': 'RISE', 'change_price': 226000.0, 'signed_change_price': 226000.0, 'change_rate': 0.0015313832, 'signed_change_rate': 0.0015313832, 'ask_bid': 'ASK', 'trade_volume': 9.854e-05, 'acc_trade_volume': 479.2424188, 'trade_date': '20250210', 'trade_time': '033725', 'trade_timestamp': 1739158645191, 'acc_ask_volume': 218.1680732, 'acc_bid_volume': 261.0743456, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158645232, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 64 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147805000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70382909032.02036, 'change': 'RISE', 'change_price': 226000.0, 'signed_change_price': 226000.0, 'change_rate': 0.0015313832, 'signed_change_rate': 0.0015313832, 'ask_bid': 'ASK', 'trade_volume': 9.854e-05, 'acc_trade_volume': 479.2424188, 'trade_date': '20250210', 'trade_time': '033725', 'trade_timestamp': 1739158645191, 'acc_ask_volume': 218.1680732, 'acc_bid_volume': 261.0743456, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158645232, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 65 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147805000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70387311353.69167, 'change': 'RISE', 'change_price': 226000.0, 'signed_change_price': 226000.0, 'change_rate': 0.0015313832, 'signed_change_rate': 0.0015313832, 'ask_bid': 'BID', 'trade_volume': 0.02978466, 'acc_trade_volume': 479.27220346, 'trade_date': '20250210', 'trade_time': '033725', 'trade_timestamp': 1739158645733, 'acc_ask_volume': 218.1680732, 'acc_bid_volume': 261.10413026, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158645774, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 66 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147805000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70387311353.69167, 'change': 'RISE', 'change_price': 226000.0, 'signed_change_price': 226000.0, 'change_rate': 0.0015313832, 'signed_change_rate': 0.0015313832, 'ask_bid': 'BID', 'trade_volume': 0.02978466, 'acc_trade_volume': 479.27220346, 'trade_date': '20250210', 'trade_time': '033725', 'trade_timestamp': 1739158645733, 'acc_ask_volume': 218.1680732, 'acc_bid_volume': 261.10413026, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158645774, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 67 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147805000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70387411352.64246, 'change': 'RISE', 'change_price': 226000.0, 'signed_change_price': 226000.0, 'change_rate': 0.0015313832, 'signed_change_rate': 0.0015313832, 'ask_bid': 'BID', 'trade_volume': 0.00067656, 'acc_trade_volume': 479.27288002, 'trade_date': '20250210', 'trade_time': '033725', 'trade_timestamp': 1739158645883, 'acc_ask_volume': 218.1680732, 'acc_bid_volume': 261.10480682, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158645933, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 68 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147805000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70387411352.64246, 'change': 'RISE', 'change_price': 226000.0, 'signed_change_price': 226000.0, 'change_rate': 0.0015313832, 'signed_change_rate': 0.0015313832, 'ask_bid': 'BID', 'trade_volume': 0.00067656, 'acc_trade_volume': 479.27288002, 'trade_date': '20250210', 'trade_time': '033725', 'trade_timestamp': 1739158645883, 'acc_ask_volume': 218.1680732, 'acc_bid_volume': 261.10480682, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158645933, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 69 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147726000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70387421352.2154, 'change': 'RISE', 'change_price': 147000.0, 'signed_change_price': 147000.0, 'change_rate': 0.0009960767, 'signed_change_rate': 0.0009960767, 'ask_bid': 'ASK', 'trade_volume': 6.769e-05, 'acc_trade_volume': 479.27294771, 'trade_date': '20250210', 'trade_time': '033726', 'trade_timestamp': 1739158646010, 'acc_ask_volume': 218.16814089, 'acc_bid_volume': 261.10480682, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158646053, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 70 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147726000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70387421352.2154, 'change': 'RISE', 'change_price': 147000.0, 'signed_change_price': 147000.0, 'change_rate': 0.0009960767, 'signed_change_rate': 0.0009960767, 'ask_bid': 'ASK', 'trade_volume': 6.769e-05, 'acc_trade_volume': 479.27294771, 'trade_date': '20250210', 'trade_time': '033726', 'trade_timestamp': 1739158646010, 'acc_ask_volume': 218.16814089, 'acc_bid_volume': 261.10480682, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158646053, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 71 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147726000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70387771162.95161, 'change': 'RISE', 'change_price': 147000.0, 'signed_change_price': 147000.0, 'change_rate': 0.0009960767, 'signed_change_rate': 0.0009960767, 'ask_bid': 'BID', 'trade_volume': 0.00236797, 'acc_trade_volume': 479.27531568, 'trade_date': '20250210', 'trade_time': '033726', 'trade_timestamp': 1739158646087, 'acc_ask_volume': 218.16814089, 'acc_bid_volume': 261.10717479, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158646135, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 72 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147726000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70387771162.95161, 'change': 'RISE', 'change_price': 147000.0, 'signed_change_price': 147000.0, 'change_rate': 0.0009960767, 'signed_change_rate': 0.0009960767, 'ask_bid': 'BID', 'trade_volume': 0.00236797, 'acc_trade_volume': 479.27531568, 'trade_date': '20250210', 'trade_time': '033726', 'trade_timestamp': 1739158646087, 'acc_ask_volume': 218.16814089, 'acc_bid_volume': 261.10717479, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158646135, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 73 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147726000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70388903385.24246, 'change': 'RISE', 'change_price': 147000.0, 'signed_change_price': 147000.0, 'change_rate': 0.0009960767, 'signed_change_rate': 0.0009960767, 'ask_bid': 'BID', 'trade_volume': 0.00766434, 'acc_trade_volume': 479.28298002, 'trade_date': '20250210', 'trade_time': '033726', 'trade_timestamp': 1739158646716, 'acc_ask_volume': 218.16814089, 'acc_bid_volume': 261.11483913, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158646755, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 74 | {'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147726000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70388903385.24246, 'change': 'RISE', 'change_price': 147000.0, 'signed_change_price': 147000.0, 'change_rate': 0.0009960767, 'signed_change_rate': 0.0009960767, 'ask_bid': 'BID', 'trade_volume': 0.00766434, 'acc_trade_volume': 479.28298002, 'trade_date': '20250210', 'trade_time': '033726', 'trade_timestamp': 1739158646716, 'acc_ask_volume': 218.16814089, 'acc_bid_volume': 261.11483913, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158646755, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'}{'type': 'ticker', 'code': 'KRW-BTC', 'opening_price': 147602000.0, 'high_price': 148455000.0, 'low_price': 146000000.0, 'trade_price': 147805000.0, 'prev_closing_price': 147579000.0, 'acc_trade_price': 70413937936.93216, 'change': 'RISE', 'change_price': 226000.0, 'signed_change_price': 226000.0, 'change_rate': 0.0015313832, 'signed_change_rate': 0.0015313832, 'ask_bid': 'BID', 'trade_volume': 0.16937554, 'acc_trade_volume': 479.45235556, 'trade_date': '20250210', 'trade_time': '033726', 'trade_timestamp': 1739158646716, 'acc_ask_volume': 218.16814089, 'acc_bid_volume': 261.28421467, 'highest_52_week_price': 163325000.0, 'highest_52_week_date': '2025-01-20', 'lowest_52_week_price': 65800000.0, 'lowest_52_week_date': '2024-02-13', 'market_state': 'ACTIVE', 'is_trading_suspended': False, 'delisting_date': None, 'market_warning': 'NONE', 'timestamp': 1739158646756, 'acc_trade_price_24h': 270117802237.25406, 'acc_trade_volume_24h': 1831.1881721, 'stream_type': 'REALTIME'} |
||
| 75 | </pre> |