¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

How to receive Options information (like: Open, High, Low) using reqMktData() or reqHistoricalData()


 

Hi,
I am trying to fetch some Options data like: OPEN, LOW, HIGH, CLOSE and etc using either?reqMktData() or reqHistoricalData(). So I write the following Python code:

connect("127.0.0.1", 4002, 1)
contract = Contract()
contract.symbol = ".MSFT211029C00275000"
contract.currency = "USD"
contract.exchange = "SMART"
reqMarketDataType(1)
reqMktData(2, contract, "", False, False, [])

Now in the above code if I add?contract.secType = "STK", it does not returns Error:? 1? ?200? ?No security definition has been found for the request,
and if I add?contract.secType = "OPT", it returns?Error:? 1? ?321? ?Error validating request.-'bX' : cause - When the local symbol field is empty, please fill the following fields (right, strike, expiry).
I am curious why I need to include expiry when I pass the exact symbol (.MSFT211029C00275000) or why I didn't receive any data while using the STK.

Does anyone help me how I can get expected Options result using reqMktData() or reqHistoricalData().


 

¿ªÔÆÌåÓý

What you have supplied as 'symbol' is actually a (incorrect) localSymbol. The symbol for a stock option is the symbol for the underlying stock, in the case "MSFT", whereas the localSymbol is IB's identifier for the target contract. If you don't specify localSymbol you have to give enough other details to uniquely identify the contract you want.

?

The localSymbol for the option you're after is actually:

?

"MSFT? 211029C00275000"

?

Note that there are two spaces after MSFT.

?

If you use the localSymbol, the only other things you need to supply are the secType (which you must ALWAYS supply) and the exchange (because a contract with a given localSymbol may be tradeable on several exchanges) , thus:

?

contract = Contract()

contract.secType = "OPT"

contract.localSymbol = "MSFT? 211029C00275000"

contract.exchange = "SMART"

?