Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import websocket
- coin_name='btcusdt'
- symbol_name=coin_name.lower()+"@kline_5m"
- print(symbol_name)
- #SYMBOL, OPEN, HIGH, LOW, CLOSE = [], [], [], [], []
- def on_open(ws):
- ws.send(json.dumps({"method": "SUBSCRIBE",
- "params": [symbol_name],
- "id": 1
- }))
- print("OPEN CONNECTION")
- def on_message(ws, message):
- print(f"Message: {message}")
- print()
- print('Data')
- msg=json.loads(message)
- bars=msg["k"]
- status = bars["x"]
- if bars["x"] == status:
- # the type for all of the keys is str, they need to be float or int to divide
- OPEN, HIGH, LOW, CLOSE, SYMBOL = float(bars["o"]), float(bars["h"]), float(bars["l"]), float(bars["c"]), bars["s"]
- PTR = OPEN / CLOSE
- result = (PTR / CLOSE) * 100
- print(result)
- print()
- url="wss://fstream.binance.com/ws/"
- # ////////////////////////////////////
- ws=websocket.WebSocketApp(url, on_open=on_open, on_message=on_message)
- # ////////////////////////////////////
- ws.run_forever(ping_interval=300)
Advertisement
Add Comment
Please, Sign In to add comment