Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need an example of getting a contract specification for use in a combo options trade #11

Closed
markmcwiggins opened this issue Sep 24, 2019 · 4 comments

Comments

@markmcwiggins
Copy link

Hi ...

Thanks again for providing this code ... I got the spread example to work last week using it ..

But! I used contractIDs I had gotten through another API ... is there an example somewhere I'm missing?

I would like to be able to do this just using localSymbol, but that doesn't seem to work.

Any guidance on this? Thanks much.

@stevegee58
Copy link

stevegee58 commented Sep 25, 2019

Only way I know of is to download the option chain for that symbol from IB TWS, then you can store the contract IDs accessible by P/C, expiry, and strike.
My application will download the chain for the selected symbol and store it in a file if it doesn't already exist. That way if I exit the program during the day I still have the chain if I restart the program. Before the market opens the next day I delete the file and start the program. That way I get a fresh chain since the chain is different every day.
Downloading the chain for indexes like SPX and ETFs like SPY can take a minute or so from TWS.

@markmcwiggins
Copy link
Author

What I'm doing is just automating a few trades per week; I could download the whole chain but all I really need is a maximum 4 contracts per trade; no reasonable way to do that?

If not would you mind sharing a snippet of your code to download the whole chain?

@stevegee58
Copy link

stevegee58 commented Sep 25, 2019

The following will download the whole chain for 1 symbol. I never download the whole chain, just the symbol I'm interested in.


        Contract C;

        C.symbol = symbol;
        C.secType = *SecType::OPT;		//"OPT"
        C.currency = "USD";
        C.exchange = *Exchange::IB_SMART;	//"SMART";
        if (expiry != "")
        {
            C.expiry = expiry;
        }
        // C.right = call or put
        // C.strike = desired strike

        m_EC->reqContractDetails(m_NextOrderId++, C);

I always just download all the expiries for the symbol I'm trading, once every morning. As you can see you can just download a single expiry too. I haven't done this but if you know you only want calls or puts you could add that to the contract specification, probably the same for strikes.
BTW I only trade SPX and SPY.

@markmcwiggins
Copy link
Author

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants