0

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?

sashkello
  • 17,306
  • 24
  • 81
  • 109

1 Answers1

2

Use cancelMktData(). After calling this method, market data for the specified Id will stop flowing.

sashkello
  • 17,306
  • 24
  • 81
  • 109
Martijn
  • 36
  • 1