Skip to content

Instantly share code, notes, and snippets.

@igotit-anything
Last active September 7, 2024 11:14
Show Gist options
  • Save igotit-anything/8c41a63d070c74abdf146f2e22e2259e to your computer and use it in GitHub Desktop.
Save igotit-anything/8c41a63d070c74abdf146f2e22e2259e to your computer and use it in GitHub Desktop.
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()
@igotit-anything
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment