Using a socket programming library am creating a function and validating the same in every tick of the callback. so i declared a global variable initial in the top and checking that variable in the tick but am getting the below error:
ERROR:websocket:error from callback >: local variable 'initial' referenced before assignment
Seems on every call back the python global scope not getting initialized
(zeroconnecty.py)
from kiteconnect import WebSocket
kws = WebSocket("xxxx", "xxxx", "USERNAME")
initial=True
print "initial",initial
#Callback for tick reception.
def on_tick(tick, ws):
if(initial):
print "only execute if it called first time callback"
initial=False
else:
print "all times except initial callback"
#Callback for successful connection.
def on_connect(ws):
ws.subscribe([738561])
ws.set_mode(ws.MODE_FULL, [738561])
#Assign the callbacks.
kws.on_tick = on_tick
kws.on_connect = on_connect
#Infinite loop on the main thread. Nothing after this will run.
#You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()