Pleas, am new here, and i realy need help am developing a trading robot in python using websocket, but now, if i try calculating the percentage change of bitcoin from its open price to its current price(closed price) in a daily time frame, i will recieve no output, it only displays open conections, no output…but if i compaire open price against close price, i will recieve an output::: i realy appreciate any help thanks
This is the sample of my code
import json
import websocket
#/////////////////////////////////////////////
coin_name=input(“ENTER SYMBOLE NAME TO TRADE IN BINANCE FUTURES :\n”)
symbol_name=coin_name.lower()+"@kline_1d"
print(symbol_name)
SYMBOLL, OPEN,HIGH,LOW,CLOSE,=,,,,
#///////////////////////////////////////////
MESSAGE_SUB={“method”: “SUBSCRIBE”,“params”: [symbol_name],“id”: 1}
def on_open(ws):
MESSAGE_SUB
ws.send(json.dumps(MESSAGE_SUB))
print(“OPEN CONECTION”)
#////////////////////////////////////
def on_message(ws, message):
msg=json.loads(message)
bars=msg[“k”]
if bars[“x”]==False:
OPEN.append(bars[“o”])
HIGH.append(bars[“h”])
LOW.append(bars[“l”])
CLOSE.append(bars[“c”])
SYMBOLL.append(bars[“s”])
#[THIS IS THE PERCENTAGE CALCULATIONS]
def get_percentage_difference(new_num,old_num):
return float((abs(new_num - old_num) / old_num) * 100)
print(get_percentage_difference(CLOSE, OPEN))
////////////////////////////////////
url=“wss://fstream.binance.com/ws”
////////////////////////////////////
ws=websocket.WebSocketApp(url,on_open=on_open,on_message=on_message)
////////////////////////////////////
ws.run_forever()