Hi I have a Python script I copied from the tutorial. Just a simple script to print some ticker info.
It runs well the first time I run it and it prints out all the info it should.
However any time I try to run it again, it builds but nothing prints. I get no errors or anything. It's like it just ignore the print function.
I've noticed the first time I run it, in TWS, the API says "connected".
After that when I try running it again, "disconnected" flashes and then it just shows grey (neither "connected" nor "disconnected"). I don't know if this is part of the issue.
It does this even if I don't change anything, make a small change, or even try running a different script.
Here is the code snippet:
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.ticktype import TickTypeEnum
from ibapi.contract import Contract
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("TickPrice. TickerId:", reqId, "tickType:", TickTypeEnum.to_str(tickType),
"Price:", price, end=' ')
def tickSize(self, reqId, tickType, size):
print("Tick Size. TickerId:", reqId, "tickType:", TickTypeEnum.to_str(tickType),
"Size:", size)
def main():
app = TestApp()
app.connect('127.0.0.1', 7497, 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, [])
if __name__ == "__main__":
main()
It runs well the first time I run it and it prints out all the info it should.
However any time I try to run it again, it builds but nothing prints. I get no errors or anything. It's like it just ignore the print function.
I've noticed the first time I run it, in TWS, the API says "connected".
After that when I try running it again, "disconnected" flashes and then it just shows grey (neither "connected" nor "disconnected"). I don't know if this is part of the issue.
It does this even if I don't change anything, make a small change, or even try running a different script.
Here is the code snippet:
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.ticktype import TickTypeEnum
from ibapi.contract import Contract
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("TickPrice. TickerId:", reqId, "tickType:", TickTypeEnum.to_str(tickType),
"Price:", price, end=' ')
def tickSize(self, reqId, tickType, size):
print("Tick Size. TickerId:", reqId, "tickType:", TickTypeEnum.to_str(tickType),
"Size:", size)
def main():
app = TestApp()
app.connect('127.0.0.1', 7497, 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, [])
if __name__ == "__main__":
main()