Autotrading with Interactive Brokers fired off an order much too late

Questions about MultiCharts and user contributed studies.
HPF
Posts: 47
Joined: 02 Apr 2013
Has thanked: 11 times
Been thanked: 7 times

Autotrading with Interactive Brokers fired off an order much too late

Postby HPF » 13 Nov 2020

Hi,

I had the following (somewhat dangerous) situation.

MC64 10.0 (build 13626)
IB Gateway 976.2s
instrument: Dax Future (Eurex, Frankfurt), symbol FDAX DEC 20 (25 EUR multiple) in IB terminology

I have a strategy based on minute bars, auto-trading with IB, which submitted an order

buy ("Enter Long") 1 contracts next bar open

The same strategy runs in two different IB accounts (two workspaces in MC64 based on the same chart. running the same strategy). From the log file of the IB gateway I see that the order for one account was transmitted to IB and filled, but the order for the other account was not submitted to IB at that time.

Now if my strategy does not get any Market_Position_at_Broker_for_the_Strategy <> 0 within three minutes, it sends me an error message by email and stops trading (there is a boolean variable set and there is an if-clause that skips any trading relevant commands of the strategy in that case).

When I saw the email with the error message, I looked at the MC64 machine, saw that IB had not filled the order for one of the two accounts (I suspected that IB had rejected the order for whatever reason, lack of margin, fast market, etc) and I decided that the situation was safe and that I would revisit the log files later.

That was a mistake. About 30 minutes later, MC64 submitted the "lost" order to the IB gateway. That's clear from the gateway log. IB filled it. That should have never happened. Luckily I receive another error message by email in this case (Market_Position_at_Broker_for_the_Strategy <> 0 even if no order was supposed to be filled).

When I looked at the MC64 machine again, the screen with the two workspaces with the strategy was visibly lagging (something I hadn't noticed 30 minutes earlier).

From the log files of the IB gateway it is clear that one order was submitted and filled when this was supposed to happen. The other order was not submitted at that time, but rather about 30 minutes later. IB had not rejected any order at all. It seems that IB cannot be blamed for anything here.

Now my question is:
* this happened once in 2 years and so isn't exactly easy to reproduce (I actually do *not* want it to reoccur)
* is this behaviour perhaps related to several MC64 processes (tsServer, TradingServer, MultiCharts64, ....) one of which may have stalled and another one fired off the now unwanted order?
* where was the crucial order held during the lag of 30 minutes? What is the supposed path of the order on the way from my strategy to the IB gateway
* what are MC64's internal safeguards against firing off an order that much late (even if something unforeseen happens and a process stalls)
* the virtual machine logs show that neither CPU usage nor memory nor I/O was anywhere near capacity when that happened.
* it is possible that when the order originally was to be submitted, there may have been an unusually high number of ticks sent by IB - it was a kind of "fast market" period
* how can I possibly debug such a situation?

Thanks for any ideas and any useful hints.

HPF

User avatar
syswizard
Posts: 295
Joined: 15 Dec 2012
Has thanked: 16 times
Been thanked: 28 times

Re: Autotrading with Interactive Brokers fired off an order much too late

Postby syswizard » 13 Nov 2020

Just a couple of comments on your problem:
1) You are 3 releases behind in MC and at least 2 releases behind with the IB Gateway.
Its tough to get technical resolution on old releases.

2) Do you have both logs turned on in the IB Gateway ? They will tell you a lot.
I know I keep mine turned off for performance reasons.

3) Is the windows execution priority the same for the gateway and MC ?
I make sure that the IB Gateway runs in a separate core and at a higher priority than MC.
This set-up has been rock-solid for me.

User avatar
Smoky
Posts: 517
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 99 times
Been thanked: 121 times

Re: Autotrading with Interactive Brokers fired off an order much too late

Postby Smoky » 04 Dec 2020

@ Syswizard

please can You explain us own You made your rock setup ? (3)

User avatar
syswizard
Posts: 295
Joined: 15 Dec 2012
Has thanked: 16 times
Been thanked: 28 times

Re: Autotrading with Interactive Brokers fired off an order much too late

Postby syswizard » 04 Dec 2020

Besides having the latest and greatest releases installed, I think with a non-integrated, modular set-up like Multicharts (which has it's advantages and disadvantages), it's best to insure the execution/clearing platform has priority over the charting platform.
So here is the start-up command for the IB Gateway:

Code: Select all

echo off START "" /HIGH /B /MIN /AFFINITY 0xC "C:\Jts\ibgateway\978\ibgateway.exe"
Once I started using the above, orders were never lost or delayed. This places the Gateway into a separate core with a high execution priority.
Whatever you do, DO NOT set any process priority to /REALTIME....it really messes up Windows.
I tried that with Excel once, and the machine just locked-up.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Autotrading with Interactive Brokers fired off an order much too late

Postby TJ » 05 Dec 2020

How are the accounts set up?
Two IB accts in one machine?
Two MultiCharts? or One MultiCharts sending orders to two accts?

Where are the machines?
At home/office?
or at a remote site? a shared server?

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Autotrading with Interactive Brokers fired off an order much too late

Postby TJ » 05 Dec 2020

It sounds like the internet or gateway was disconnected for a moment, and order was sent when the connection was reactivated.

Do you have a heart-beat checker?

User avatar
syswizard
Posts: 295
Joined: 15 Dec 2012
Has thanked: 16 times
Been thanked: 28 times

Re: Autotrading with Interactive Brokers fired off an order much too late

Postby syswizard » 05 Dec 2020

Good points TJ and here is a good article related to the issue: https://www.dnsstuff.com/free-network-m ... g-software
Traceroute NG appears to be one good solution.

User avatar
Mark Brown
Posts: 182
Joined: 29 Nov 2016
Has thanked: 114 times
Been thanked: 18 times

Re: Autotrading with Interactive Brokers fired off an order much too late

Postby Mark Brown » 05 Dec 2020

i had the same problem can search here and when it did trade it doubled my order, i think it has to do with ib's crappy snapshot data.

User avatar
syswizard
Posts: 295
Joined: 15 Dec 2012
Has thanked: 16 times
Been thanked: 28 times

Re: Autotrading with Interactive Brokers fired off an order much too late

Postby syswizard » 07 Dec 2020

i had the same problem can search here and when it did trade it doubled my order, i think it has to do with ib's crappy snapshot data.
Interactive's IB Gateway has several logging options. I usually keep them disabled for performance reasons. However, when execution problems arise you must turn these on.


Return to “MultiCharts”