Binance websocket server <-> Python websocket client
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
import json | |
import websocket | |
import datetime | |
def ws_trades(): | |
socket = f'wss://stream.binance.com:9443/ws/ethusdt@trade' | |
def on_message(wsapp,message): | |
json_message = json.loads(message) | |
handle_trades(json_message) | |
def on_error(wsapp,error): | |
print(error) | |
wsapp = websocket.WebSocketApp(socket, on_message=on_message, on_error=on_error) | |
wsapp.run_forever() | |
def handle_trades(json_message): | |
print(json_message) | |
print("-----------------------") | |
ws_trades() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to execute:
pip3 install websocket-client
python3 websocket-binance.py