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