Created
September 11, 2022 14:37
-
-
Save atitawat-pol/4068998bf8383efb4fe6d694628a20ef to your computer and use it in GitHub Desktop.
Binance simeple websocket Python
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 websocket | |
import json | |
quote = "ethusdt" | |
interval = "15m" | |
# socket = f"wss://stream.binance.com:9443/ws/{quote}@kline_{interval}" | |
socket = f"wss://stream.binance.com:9443/ws/{quote}@trade" | |
# What to do when receiving a message from the server | |
def on_message(self, message): | |
print(message) | |
# What to do when closing a connection | |
def on_close(self): | |
print("### closed ###") | |
# websocket object creation | |
ws = websocket.WebSocketApp( | |
socket, | |
on_message=on_message, | |
on_close=on_close | |
) | |
# Run the websocket client | |
ws.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment