I'm trying to use the Interactive Brokers API with Python. I've tried to implement one of their basic examples by doing everything exactly how they have in their instructional video but it doesn't seem to work. Below is the code that should return some market data but when I run it nothing prints.
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.ticktype import TickTypeEnum
class TestApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def error(self, reqId, errorCode, errorString):
print("Error: ", reqId, " ", errorCode, " ", errorString)
def tickPrice(self, reqId, tickType, price, attrib):
print("Tick Price. Ticker Id ", reqId, " tickType: ", TickTypeEnum.to_str(tickType), end=' ')
def tickSize(self, reqId, tickType, size):
print("test")
print("Tick Size. Ticker Id ", reqId, " tickType: ", TickTypeEnum.to_str(tickType), "Size: ", size)
def main():
app = TestApp()
app.connect("127.0.0.1", 7496, 0)
contract = Contract()
contract.symbol = "AAPL"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"
contract.primaryExchange = "NASDAQ"
app.reqMarketDataType(4)
app.reqMktData(1, contract, "", False, False, [])
app.run()
if __name__ == "__main__":
main()
I'm not sure what could be happening, but I'm guessing it has something to do with the TestApp functions not getting properly overwritten, or something along those lines. Thanks for any help or info you could provide.