Here is a pretty standard piece of code I use to request some data from Interactive Brokers API through python:
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)
I expect the connection to be closed after con.disconnect()
, however it keeps getting new data (messages print updated bid, ask etc).
Why doesn't disconnect()
seem to do anything and how can I actually close the connection?
Use cancelMktData()
. After calling this method, market data for the specified Id will stop flowing.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.