I'm calling the IV using tickGeneric. It gets the IV but prints it 6 times, not sure why. It prints it intermixed in the previous function tickPrice as well. This is my current print out: The IV is 0.3761491160881086 The IV is 0.3761491160881086 The last price is: 280.19 The IV is 0.3761491160881086 The IV is 0.3761491160881086 The IV is 0.3761491160881086 The current bid price is: 280.0 The current ask price is: 280.2 The IV is 0.3761491160881086 Here is my relevant code: class TestApp(EWrapper, EClient): ... def nextValidId(self, orderId): self.start() def tickPrice(self, reqId, tickType, price, attrib): if tickType == 1 and reqId == 1: print('The current bid price is: ', price) if tickType == 2 and reqId == 1: print('The current ask price is: ', price) if tickType == 4 and reqId == 1: print('The last price is: ', price) def tickGeneric(self, reqId, tickType, value): #super().tickGeneric(reqId, tickType, value) print("The IV is", value) ... def start(self): #self.reqSecDefOptParams(1, "AAPL", "", "STK", 265598) contract = Contract() contract.symbol = 'AAPL' contract.secType = 'STK' contract.exchange = 'SMART' contract.currency = 'USD' contract.primaryExchange = 'NASDAQ' contract.lastTradeDateOrContractMonth = '202010' self.reqMktData(1, contract, '106', False, False, []) def stop(self): self.done = True self.disconnect()
It could be, but I'm guessing, that IB's servers think that one of the constituents involved in calculating the IV has changed. And conclude that IV has changed, therefore sending you the new value.
+ tickPrice just prints once. I don't get why it prints IV first, then tickPrice. I would've assumed tickPrice and tickGeneric would run one after the other
They run independently from each other. You will receive an update whenever the value has changed. Unless the value changes too quickly: then IB will throttle the update rate.
That makes sense, one time I ran it and the last value printed was different than the first 5. It always prints 6 times though, like that's a default or something. Is there a way to stop it after it runs once? I suppose if I'll be saving it to a variable it doesn't really matter how many times it overwrites it.
You can indeed have a variable constantly being overwritten, as long as the rest of your code is fine with that. You can unsubscribe from market data by using cancelMktData(1). 1 being the identifier you used in reqMktData().
a) If you want the values just once, set the Snapshot parameter to true in the reqMktData call. b) I suggest that in your tickGeneric function you print both the tickType and the value. You may be getting different tickType's each with the same value.
a) I get "Error: 1 321 Error validating request:-'bW' : cause - Snapshot market data subscription is not applicable to generic ticks" b) I get "tickType 24" for each IV value. Am I supposed to use one "reqMktData()" function for all the market requests?