¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 ¿ªÔÆÌåÓý

reqSecDefOptionParams returns wrong trading class


 

Hi guys,?
?
so i have a complete pipeline setup for the data back and through my application for options data.
The only problem i am facing right now is that if i am trying to get data for NVDA via reqSecDefOptionParam, i am getting back 2NVDA as trading class and that doesnt have data.
Now i am stuck what to do, its similar with AMZN, i am getting back 2AMZN as trading class with no data.
?
?


 

¿ªÔÆÌåÓý

If I call reqMktData with this contract:

?

³§²â³¾²ú´Ç±ô=¡±±·³Õ¶Ù´¡¡±

³§±ð³¦³Ù²â±è±ð=¡±³§°Õ°­¡±

Lasttradedator contract monthe=¡±20250425¡±

Strike=124

¸é¾±²µ³ó³Ù=¡±°ä´¡³¢³¢¡±

·¡³æ³¦³ó²¹²Ô²µ±ð=¡±³§²Ñ´¡¸é°Õ¡±

°ä³Ü°ù°ù±ð²Ô³¦²â=¡±±«³§¶Ù¡±

°Õ°ù²¹»å¾±²Ô²µ³¦±ô²¹²õ²õ=¡±2±·³Õ¶Ù´¡¡±

?

I get this data returned:

?

20250414 20:38:40.292? id=5 MarketDataType=Realtime

20250414 20:38:40.292? id=3 Bid=-1 size=0 Can Auto Execute

20250414 20:38:40.292? id=3 Ask=-1 size=0 Can Auto Execute

20250414 20:38:40.292? id=3 BidSize=0

20250414 20:38:40.292? id=3 AskSize=0

20250414 20:38:40.293? id=3 LastSize=0

20250414 20:38:40.293? id=3 Close=0.85 size=0

20250414 20:38:40.293? id=3 Halted=0

20250414 20:38:40.293? id=0 Bid=-1 size=0 Can Auto Execute

20250414 20:38:40.293? id=0 Ask=-1 size=0 Can Auto Execute

20250414 20:38:40.293? id=0 BidSize=0

20250414 20:38:40.293? id=0 AskSize=0

20250414 20:38:40.293? id=0 LastSize=0

20250414 20:38:40.293? id=0 Close=0.85 size=0

20250414 20:38:40.293? id=0 Halted=0

20250414 20:38:40.293? id=5 Bid=-1 size=0 Can Auto Execute

20250414 20:38:40.293? id=5 Ask=-1 size=0 Can Auto Execute

20250414 20:38:40.293? id=5 BidSize=0

20250414 20:38:40.293? id=5 AskSize=0

20250414 20:38:40.293? id=5 LastSize=0

20250414 20:38:40.293? id=5 Close=0.85 size=0

20250414 20:38:40.293? id=5 Halted=0

20250414 20:38:41.296? id=5 Halted=0

?

Not very interesting data because the market is closed, but it rather indicates that your claim of no data is incorrect.

?

Richard

?

?

?

From: [email protected] <[email protected]> On Behalf Of skateriit via groups.io
Sent: 14 April 2025 20:42
To: [email protected]
Subject: [TWS API] reqSecDefOptionParams returns wrong trading class

?

Hi guys,?

?

so i have a complete pipeline setup for the data back and through my application for options data.

The only problem i am facing right now is that if i am trying to get data for NVDA via reqSecDefOptionParam, i am getting back 2NVDA as trading class and that doesnt have data.

Now i am stuck what to do, its similar with AMZN, i am getting back 2AMZN as trading class with no data.

?

?


 

?
so this is NVDA
and this is 2NVDA, i meant there is nothing in 2NVDA
and even though market is closed u can get historical data for the stock, so basically why u getting 0s for everything is not because market is closed because 2nvda doesnt have anything
?


 

Also if i try getting data for AAPL, TSLA, and other stocks i get back trading class as AAPL, TSLA, and was thinking is there any method in which we can define that we just need the same trading class back as what we have provided.
?


 

¿ªÔÆÌåÓý

If two contracts have the same symbol but different trading classes, they are different contracts. So NVDA call option with strike 124 for 20250425 with trading class NVDA has contract id 772477960, whereas the contract with trading class 2NvDA has contract id 766595300. I¡¯ve no idea what trading class 2NVDA means, and I¡¯ve no idea why 124 is the only strike that has a trading class 2NVDA as well as NVDA (and only for that one expiry date), but clearly no-one is trading it. (It might even be an error in IBKR¡¯s contract database.)

?

Because there are two different contracts whose only difference is the trading class, you have to specify which trading class you want (for example for reqMktData) otherwise you¡¯ll be told the contract is ambiguous.

?

As you¡¯ve noticed, most options have trading class the same as the symbol. It¡¯s your responsibility to know what you¡¯re trading, so if you do come across a security that has more than one trading class, you need to find out what they mean. For example, for some (but not all) futures the trading class indicates whether it¡¯s monthly or weekly or two-weekly contract.

?

Richard

?

?

?

From: [email protected] <[email protected]> On Behalf Of skateriit via groups.io
Sent: 14 April 2025 22:16
To: [email protected]
Subject: Re: [TWS API] reqSecDefOptionParams returns wrong trading class

?

Also if i try getting data for AAPL, TSLA, and other stocks i get back trading class as AAPL, TSLA, and was thinking is there any method in which we can define that we just need the same trading class back as what we have provided.

?


 

Thank you for the reply, its quite informative.
?
I guess the problem is in the api function itself. So to request the option chain we are using
reqSecDefOptParams(0, "IBM", "", "STK", 8314);
so we cannot define the trading class here, and we get the response back in this function which has trading class in it
securityDefinitionOptionParameter(self, reqId: int, exchange: str, underlyingConId: int, tradingClass: str, multiplier: str, expirations: SetOfString, strikes: SetOfFloat).
?
Also for more clarity, here how my code flow is basically, i define a contract -> get contract details for contract id -> send request via reqSecDefOptParams to get option chain and get back response in securityDefinitionOptionParameter which has hashset of strikes and expirations, reason of doing this so that I have all the valid strikes for that stock or index, but now the problem is same we are getting trading class back in via the above function. Is there any other way around it.
?
Prat.
client.reqSecDefOptParams(0, "IBM", "", "STK", 8314);cl
client.reqSecDefOptParams(0, "IBM", "", "STK", 8314);


 

So it sounds like you need to review the query contract you use for reqContractDetails() and make sure that you request the NVDA trading class. That way you will receive a contract with conId 772477960 (instead of 766595300 for 2NVDA) and reqSecDefOptParams() will use the correct trading class.

´³¨¹°ù²µ±ð²Ô

?
On Mon, Apr 14, 2025 at 06:32 PM, <skateriit@...> wrote:

?
Also for more clarity, here how my code flow is basically, i define a contract -> get contract details for contract id -> send request via reqSecDefOptParams to get option chain and get back response in securityDefinitionOptionParameter which has hashset of strikes and expirations, reason of doing this so that I have all the valid strikes for that stock or index, but now the problem is same we are getting trading class back in via the above function. Is there any other way around it.
?
client.reqSecDefOptParams(0, "IBM", "", "STK", 8314);cl
client.reqSecDefOptParams(0, "IBM", "", "STK", 8314);


 

ohhh this makes complete sense, thanks jurgen and richard really appricate it.


 

[update] so defining the contract with trading class didnt work for me what worked was that when we receive the data in securityDefinitionOptionParameter, in the code just add a statement if (tradingClass != ticker) return; so basically there are multiple times the response is send for to securityDefinitionOptionParameter i guess for all trading class we have, so it will take the correct tradingclass and then give the optionchain.