Last active
September 7, 2024 11:14
-
-
Save igotit-anything/8c41a63d070c74abdf146f2e22e2259e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pybit.unified_trading import WebSocket | |
from time import sleep | |
# 메시지 핸들러 함수 정의 | |
def handle_message(message): | |
print(message) | |
def main(): | |
# WebSocket 객체 생성 | |
ws = WebSocket( | |
testnet=False, # 실제 거래가 아닌 테스트넷을 사용할 경우 True로 설정 | |
channel_type="linear" # 리니어 채널 설정 | |
) | |
# BTCUSDT 거래 데이터 구독 | |
ws.trade_stream( | |
symbol="BTCUSDT", # 구독할 심볼 설정 | |
callback=handle_message # 데이터 수신 시 호출될 콜백 함수 | |
) | |
# 데이터 수신 대기 | |
try: | |
while True: | |
sleep(1) # 1초마다 반복 | |
except KeyboardInterrupt: # CTRL C | |
print("Interrupted by user") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bybit : https://partner.bybit.com/b/igotit_home
related posting : https://igotit.tistory.com/5831