Created
October 11, 2020 03:39
-
-
Save yuyasugano/b44ebb41a7bdb2eed5b86c46beca8b26 to your computer and use it in GitHub Desktop.
WebSocket example subscribe
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
#!/usr/bin/python | |
import json | |
import logging | |
import socketio | |
logging.basicConfig( | |
level=logging.DEBUG, | |
filename='./socketio.log', | |
format='%(levelname)s : %(asctime)s : %(message)s' | |
) | |
logger = logging.getLogger(__name__) | |
logger.info('Created socketio client') | |
sio = socketio.Client( | |
reconnection=True, | |
reconnection_attempts=0, | |
reconnection_delay=1, | |
reconnection_delay_max=30, | |
logger=True | |
) | |
@sio.event | |
def connect(): | |
logger.info('connected to server') | |
sio.emit('join-room', 'transactions_btc_jpy') | |
@sio.event | |
def message(data): | |
logger.info('print message') | |
print(json.dumps(data, indent=2)) | |
@sio.event | |
def disconnect(): | |
logger.info('disconnected from server') | |
url = 'wss://stream.bitbank.cc' | |
sio.connect(url, transports=['websocket']) | |
sio.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment