Hey Draql12,?
?
On second thought, I think marketPrice() may be a more robust choice, as it first seeks to use the most recent trade price (comparing to only the actual ask and bid prices in that moment ignoring their sizes). If the three don't jive, then the function calls Midpoint().
?
The marketPrice() function could be especially useful for low-volume securities (such as OTM options) that don't have an active bid or ask. Although if the last trade price of the security occurred a long time ago (perhaps a week or a few days), then could adversely impact you but still, that fail would fall more on IB's data service (for providing you with an outdated and irrelevant last trade price) than the marketPrice() function itself. Naw meen.
?
I have re-printed its source code below for additional reading.
?
? ? def marketPrice(self) -> float:
? ? ? ? """
? ? ? ? Return the first available one of
? ? ? ? * last price if within current bid/ask or no bid/ask available;
? ? ? ? * average of bid and ask (midpoint).
? ? ? ? """
? ? ? ? if self.hasBidAsk():
? ? ? ? ? ? if self.bid <= self.last <= self.ask: # <== check it out ignores bid/ask sizes!
? ? ? ? ? ? ? ? price = self.last
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? price = self.midpoint() # <== what you already have
? ? ? ? else:
? ? ? ? ? ? price = self.last #<== all else failed
? ? ? ? return price
?
Regards,
Some Guy