这是一段非常标准的代码,我用来通过 python 从 Interactive Brokers API 请求一些数据:
from ib.ext.Contract import Contract
from ib.opt import ibConnection, message
import time
def watcher(msg):
print msg
con = ibConnection()
con.registerAll(watcher)
con.connect()
contract = Contract()
contract.m_symbol = "EUR"
contract.m_exchange = "IDEALPRO"
contract.m_currency = "USD"
contract.m_secType = "CASH"
con.reqMktData(1, contract, '', False)
time.sleep(5)
con.disconnect()
print "DISCONNECTED"
time.sleep(60)
我希望连接在之后关闭con.disconnect()
,但是它会不断获取新数据(消息打印更新的出价、询问等)。
为什么disconnect()
似乎什么也没做,我如何才能真正关闭连接?