Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WebSocket example subscribe
#!/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