Hello, I’m a complete beginner at programming. I have problem with calculations with data from Binanace stream. For example how can I calculate “high” - “low” like in line 24 in my example code?
Thanks.
import websocket, datetime, pprint, json, config
import numpy as np
from binance.client import Client
client = Client(config.api_key, config.api_secret, testnet=True)
symbol = 'btcusdt'
def on_message(ws, message):
print()
print(str(datetime.datetime.now()) + ": ")
#print(message)
json_message = json.loads(message)
# pprint.pprint(json_message)
high = json_message['h']
low = json_message['l']
print(high)
print(low)
range = high - low
print(range)
if high > low:
print("Is higher")
else:
print("Is not higher")
def on_error(ws, error):
print(error)
def on_close(ws, close_msg):
print("### closed ###" + close_msg)
def streamKline(symbol):
websocket.enableTrace(False)
socket = f'wss://stream.binance.com:9443/ws/{symbol}@ticker'
ws = websocket.WebSocketApp(socket,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.run_forever()
streamKline(symbol)