robjones90

lightsun2

Mar 8th, 2023
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. import json
  2. import websocket
  3.  
  4.  
  5. coin_name='btcusdt'
  6. symbol_name=coin_name.lower()+"@kline_5m"
  7. print(symbol_name)
  8.  
  9. #SYMBOL, OPEN, HIGH, LOW, CLOSE = [], [], [], [], []
  10.  
  11. def on_open(ws):
  12.     ws.send(json.dumps({"method": "SUBSCRIBE",
  13.                         "params": [symbol_name],
  14.                         "id": 1
  15.                         }))
  16.  
  17.     print("OPEN CONNECTION")
  18.  
  19. def on_message(ws, message):
  20.     print(f"Message: {message}")
  21.     print()
  22.     print('Data')
  23.     msg=json.loads(message)
  24.     bars=msg["k"]
  25.     status = bars["x"]
  26.     if bars["x"] == status:
  27.         # the type for all of the keys is str, they need to be float or int to divide
  28.         OPEN, HIGH, LOW, CLOSE, SYMBOL = float(bars["o"]), float(bars["h"]), float(bars["l"]), float(bars["c"]), bars["s"]
  29.         PTR = OPEN / CLOSE
  30.         result = (PTR / CLOSE) * 100
  31.         print(result)
  32.         print()
  33.  
  34. url="wss://fstream.binance.com/ws/"
  35. # ////////////////////////////////////
  36. ws=websocket.WebSocketApp(url, on_open=on_open, on_message=on_message)
  37. # ////////////////////////////////////
  38. ws.run_forever(ping_interval=300)
Advertisement
Add Comment
Please, Sign In to add comment