Implementing IB order submission

To allThanks for all the help getting my trading systems up and running, I have (re)learned an absolute boatload of VB.NET over the last couple of months getting my trading systems up to snuff!! Thanks!!

Now comes the final piece of the puzzle for me... I have been papertrading my systems for three months (read: out of sample data check) and it is currently performing as expected (even in the down market) with around 200 trades (in line with expected number over 3 months) I would like to be able to automatically submit the generated trades to IB. I have used IB to gather live data (Equities, Forex and Futures) and so I know the connectivity seems to be fine. I was hoping someone could help point me in the right direction to submitting the Buy/Sell orders automatically (would make my life a lot easier )

So my rough protocol (a long only system to make it easier for now ):

(i) Update price data for specific watch list with scheduled script(ii) Run simulation to generate buy/sell selections - Buys are Limit order, Sells are Market at Open (closing those that have reached appropriate technical thresholds). These are generated during the NewBar() sub.(iii) **would like to automate this step** Submit orders (manually, currently) into IB prior to Market open as Day orders(iv) Go get coffee

I would like to automate step (iii) so that I can get to (iv) a little quicker

Kidding aside, what are the approximate steps and critical considerations as I move into this automated step and is there a sample code (VB preferred, but i can hack my way through C code if necessary) that I could review/implement that would help this.

I would test everything in an IB paper trading account before going live. From a conceptual perspective, the process is straightforward:

1. Ensure that you configure the folder so that the services specify the broker service with your IB plugin. Also ensure the Realtime Data Service (does not need to be the same as the broker service). 2. Ensure your symbols in your IB folder are correctly working with IB. It sounds like you’ve already done this with the live data testing.3. Review your Options | Live options to ensure they are setup to your preferences.

There may be nuances with the IB plugin such as order parameters, obtaining information back from IB servers, etc. However, all are easy to verify when testing with the IB paper trading account. Note, these nuances sometimes result from changes on IB’s servers and/or with different TWS version so you should monitor with checks in your code. For each upgrade in TWS, I would re-test your system against a paper trading account before going live.

To ensure orders a correctly submitted to IB, you can place breakpoints in the SubmitOrder method in the TWSPlugin class.

DuaneThanks for the response and a genuine thank you for the advice. I feared that the response would be what you wrote

I have checked all of the connectivity and run the system live but no orders get submitted to the TWS when the full model is run. I can manually Open Positions (and they show up in the TWS) so connectivity seems to work well, but automated submission of generated positions doesn't.

Am I missing something obvious (most likely I am) within the code that is needed to submit orders/control/check etc...I guess this is where I am looking to see if I am in need of additional support.

You’ll need to place breakpoints in the SubmitOrder method mention above. It is the fastest way to resolve. Otherwise you may just be guessing.

Also, check your TWS audit logs. These may help. It usually comes down to a simple order setting that can easily be modified in the TWSPlugin.

Note, this is actually a big advantage for RightEdge since changes from the IB team can be compensated for straight away in your code. Other products have a closed source module for their TWS interface and if IB changes something that breaks the connectivity, you end up waiting for the company to fix the interface.

DanielOnce again, thanks for you all your help! But I still feel like I am missing something in all of thise...ugh (it is not your fault, just my lack of understanding!)

I think I am missing a fundamental piece of code or sub/method (just how I feel).

(i) I can develop/run/manipulate models (and have developed several that look very promising and I have back/paper/out-of-sample tested sufficiently)(ii) I know I can take a watch list live (get live data/submit manual orders etc...) using IB connectivity(iii) I can automate data updates and running models (using scripts)

So...I revert back to my original difficulty of not being able to run a model live and have it submit the orders that are generated. Note that in my model code I only have the usual NewBar() where I buy/sell long positions with the usual "open position" language. I am not really using "live data" as part of my model, everything is based on EOD analysis for buy/sell. So an updated daily set of data us sufficient to generate my positions. Once generated I want to submit DAY LIMIT (buy) /MARKET (sell) orders to IB (either at open or overnight).

Should my base code should change (see below for sample open long position code):

How do I access TWS logs and with regards to the settings for TWS plugin, I am unsure as to how I should go about finding/editing these.

Sorry if this seems very newbie on the surface, this is an aspect I haven't dealt with and my coding experience is probably lower than a lot of forum users, so apologise for the potential idiocy of some of these questions I am just trying to learn!

TWS settings are in the options of the services (configure services | select the service | Modify).

Your code looks fine. Are you running it live via the “Start Data Feed” and then “Start Live System”? The live system will use your historical data and generate trades which will be submitted to the broker in the live system. Configure Real Time Data and Broker in the configuration of your folder.

The TWS logs for RightEdge are your AppData\Roaming\Yye Software\RightEdge\2010.1.0.0\TWSLogs folder. However, the TWS audit logs I was referring to is in TWS under Account | Audit Trail.

It sounds like your already set up. Are your breakpoints hit in SubmitOrder of TWSPlugin per the above?

(i) Open model(ii) Run model manually (so I can see the number/size of potential orders)(iii) Login into IB(iv) Once completely logged into IB, I initiate Live feed (with appropriate checkbox(es) on Watchlist(s))(v) The I initiate Live Model

So I follow the order you are suggesting. I literally just tried it (out of hours) and I can see the orders as "Pending" in the Live System output window. So that feels good (I have never seen that before). So it does look like things are behaving normally. However, I haven't yet managed to see them orders be posted to my IB account.

I would like orders to be submitted pre-open (so they are waiting once the market opens) - is that possible? Obviously they are sitting pending now when I could literally go into IB and enter orders for Monday open. If not then I guess I will have to wait until normal market hours to test whether this really work and take a look through the logs - unless something I said above sparks a thought/something someone has seen before.

Thanks again for your patience as I try to work through this. It seems so simple (and I believe that it is), but for some reason it is flummoxing me