使用套接字编程库可以创建函数并在回调的每个滴答声中对其进行验证。所以我在顶部声明了一个初始的全局变量,并在勾号中检查了该变量,但出现以下错误:
错误:websocket:来自回调的错误>:分配前引用了本地变量'initial'
似乎在每次调用python全局范围时都未初始化
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()
使用套接字编程库可以创建函数并在回调的每个滴答声中对其进行验证。因此,我在顶部声明了一个初始的全局变量,并在...
尝试在on_tick()
函数中全局引用: