Hi Patrick,
Ooops, my bad with the tickerId - I was trying to get the first tickerId to be 1 and to also use it as the index to the tickers list, but I failed to subtract 1 from the tickerId when using it to index the zero based tickers list.
In dataReturn, I should have had: app.reqMktData(tickerId, usTechStk(tickers[tickerId-1]), "", False, False, [])
What you have now will mean the first reqId will be zero - maybe that's OK, but I'm not sure.
But, here's the thing: In tickPrice, I see code that references tickerId. Which tickerId is that? It's not the local tickerId given to the thread. Seems it could be the tickerId used in the loop that spawns the threads.
This tickerId will now be 2 and will not change.
So, in tickPrice, you will be checking whether the reqId == 2 and printing the prices only for FB since that is the tickerId used when the reqMktDate request was made for FB.?
Just for fun, try the following code. I adjusted my original code to subtract 1 from the tickerId before using it as the index. I also modified the tickPrice method to NOT check the reqId against the tickerId.
Note that I also changed the print statement to an "f" style formatting string (a lower case f goes just before the string and braces contain the values) to print the symbol with the price to see whether we will now get all three symbols reporting.
I used reqId-1 as the index to tickers since the incoming reqId should be 1,2, or 3, so subtracting 1 will make it 0,1, or 2 to correctly index the tickers.?
--------------------------------------------------------------------------------
tickers = ["JG", "AAPL", "FB"]
def dataReturn(app, tickerId):
??? app.reqMktData(tickerId, usTechStk(tickers[tickerId-1]), "", False, False, [])?? # subtract 1 from tickerId to get correct tickers symbol
? ? time.sleep(5) #Add some breathing room for testing
threads = []
for tickerId in range(1, len(tickers)+1):? # start tickerId at 1
? ? t = threading.Thread(target=dataReturn, args=(app, tickerId))
? ? t.start()
? ? threads.append(t)
def tickPrice(self, reqId, tickType, price, attrib):
? ? ? ? if tickType == 1:
? ? ? ? ? ? self.bidprice = {"ReqId": reqId, "TickType": tickType, "Price": price, "Attrib": attrib}
? ? ? ? ? ? print(f"The current bid price for {tickers[reqId-1]} is: {price}")
? ? ? ? ? ??
? ? ? ? elif tickType == 2:
? ? ? ? ? ? self.askprice = {"ReqId": reqId, "TickType": tickType, "Price": price, "Attrib": attrib}
? ? ? ? ? ? print(f"The current ask price for {tickers[reqId-1]} is: {price}")
? ? ? ? ? ??
? ? ? ? elif tickType == 4:
? ? ? ? ? ? self.lastprice = {"ReqId": reqId, "TickType": tickType, "Price": price, "Attrib": attrib}
? ? ? ? ? ? print(f"The current last price for {tickers[reqId-1]} is: {price}")??
--------------------------------------------------------------------------------------------------
Cheers,
Scott