I'm trying to just start working with the TWS API with Python. I've copied the instructional video exactly, but it doesn't seem to be working. The code below should just get market data.
When I run that, nothing prints. I've also added a print statement to the tickPrice and tickSize function in the wrapper.py file, so it seems the tickPrice and tickSize functions are never called, what are reasons this might be?
Code:
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()
When I run that, nothing prints. I've also added a print statement to the tickPrice and tickSize function in the wrapper.py file, so it seems the tickPrice and tickSize functions are never called, what are reasons this might be?
Last edited: