我正在尝试使用来自 IG Index 的流 API,他们的文档在这里。Api 要求应用程序中包含轻流媒体客户端。所以我使用了这个版本并将它添加到我的项目中。我创建了一个连接到服务器的函数。(我相信)
def connect_light_stream_client():
if cst == None or xt == None:
create_session()
global client
client = lsc.LightstreamerClient(lightstreamer_username=stream_ident,
lightstreamer_password=stream_password,
lightstreamer_url=light_stream_server)
try:
client.connect()
except Exception as e:
print("Unable to connect to Lightstreamer Server")
return
然后我调用第二个函数,该函数应获取股票数据流,并在每次报价后打印结果。
def listner(item_info):
print(item_info)
def light_stream_chart_tick():
sub = lsc.LightstreamerSubscription(mode="DISTINCT", items={"CHART:CS.D.XRPUSD.TODAY.IP:TICK"},
fields={"BID"})
sub.addlistener(listner)
sub_key = client.subscribe(sub)
print(sub_key)
最后的打印产生的输出为 1。我从听者那里什么也得不到。有什么建议我做错了吗?