Profile Picture

RE double counting some partial fills resulting in positions out of sync with IB and resulting in...

Posted By tfconrad 6 Years Ago

RE double counting some partial fills resulting in positions out of...

Message
Posted Wednesday June 29 2011
Hello,

Overall I must say I am impressed with the RightEdge.  I am having a big problem with positions getting out of sync with IB and resulting overfills -  this seems to happen on about 1 of every 10 trades with IB.  It appears that RE occasionally double-counts partial fills.  I turned on the broker logging in the latest v36 build.  Below are the order execution messages which appear to tell the story.  I initiated a trade to sell 321 TWC.  One of the 100 shares partial fills was double-counted by RE (see highlighted line) at a time when the current fill size was 317/321, resulting in RE thinking my total position size was 417 when it was actually 321.  The log messages then start talking about an untracked order.  This then results in an overfill as when I go to close the position, RE says the size is 417, so I close 417 and wind up long 96 which is a trade I'd rather bet against and I wind up paying extra commissions and punitive commissions on the oddlot < 100 shares.

How do we fix this?  I have read a bunch of posts about overfill issues but I am unclear how best to fix this.  In some of those posts it almost seems that the definition of a position is getting confused, it should really be defined by there being one and only one position for each unique symbol, i.e. +100 AAPL and -50AAPL is not two positions, the only "position" for AAPL is +50.  I also tried using the code below, below the messages but I'm not sure if it is helping.  I attached the log file including all messages for that symbol.  I look forward to your diagnosis.

Time Symbol Order Position Event Details
11:34:15 TWC 683 9 ExecDetails 20110629  11:34:13 Sold Size: 100 Price: 77.73
11:34:15 TWC 683 9 ExecDetails Partial fill: total 100/321
11:34:25 TWC 683 9 ExecDetails 20110629  11:34:23 Sold Size: -100 Price: 77.73
11:34:25 TWC 683 9 ExecDetails ### Execution Ignored - Negative Fill
11:34:25 TWC 683 9 ExecDetails 20110629  11:34:23 Sold Size: 100 Price: 77.73
11:34:25 TWC 683 9 ExecDetails Partial fill: total 200/321
11:34:35 TWC 683 9 ExecDetails 20110629  11:34:34 Sold Size: 100 Price: 77.73
11:34:35 TWC 683 9 ExecDetails Partial fill: total 300/321
11:34:36 TWC 683 9 ExecDetails 20110629  11:34:35 Sold Size: 17 Price: 77.73
11:34:36 TWC 683 9 ExecDetails Partial fill: total 317/321
11:34:37 TWC 683 9 ExecDetails 20110629  11:34:35 Sold Size: 100 Price: 77.73
11:34:45 TWC 683 n/a ExecDetails: untracked order 20110629  11:34:44 Sold Size: -317 Price: 77.73
11:34:46 TWC 683 n/a ExecDetails: untracked order 20110629  11:34:44 Sold Size: 317 Price: 77.73
11:34:54 TWC 683 n/a ExecDetails: untracked order 20110629  11:34:53 Sold Size: 4 Price: 77.73
11:34:55 TWC 683 n/a ExecDetails: untracked order 20110629  11:34:53 Sold Size: -321 Price: 77.73
11:34:55 TWC 683 n/a ExecDetails: untracked order 20110629  11:34:53 Sold Size: 321 Price: 77.73
12:00:03 TWC 695 9 ExecDetails 20110629  12:00:01 Bought Size: 417 Price: 77.81
12:00:03 TWC 695 n/a ExecDetails: untracked order 20110629  12:00:01 Bought Size: -417 Price: 77.81
12:00:03 TWC 695 n/a ExecDetails: untracked order 20110629  12:00:01 Bought Size: 417 Price: 77.81


public override void OrderFilled(Position position, Trade trade)
{
 // This method is called when an order is filled

        // if my position is now 0, then cancel any other orders
        if (position.CurrentSize == 0)
        {
            // if there are still pending orders, cancel them
            if (position.Orders.Count > 0)
            {
                foreach (Order pendingOrders in position.Orders)
                {
                    pendingOrders.CancelOrder();
                    TradingSystem.WriteMessage("Pending Order cancel since position now flat for " + pendingOrders.Symbol);
                }
            }
        }
}


Attachments
Posted Wednesday June 29 2011
I think perhaps the is here:

11:34:25 TWC 683 9 ExecDetails 20110629 11:34:23 Sold Size: -100 Price: 77.73
11:34:25 TWC 683 9 ExecDetails ### Execution Ignored - Negative Fill

TWS is sending a negative fill and the plugin is ignoring it. I guess TWS is sending the negative fill to cancel the fill that it sent previously. Can you check the logs and see if the out of sync/overfills always correspond to a negative fill?

Thanks,
Daniel
Posted Wednesday June 29 2011
It would also be worth looking at the TWS audit trail and see what it has for the orders with negative fills.

Daniel
Posted Thursday June 30 2011
Yes, every ###Execution ignored - Negative Fill message appears to correspond to RightEdge having a different position size than IB, which eventually results in overfills. 

Looking at the IB Log at c:\jts\asdfasdf\executions.txt, I see that it looks like every trade made automatically by RightEdge has a negative fill. It looks like once all the partial fills add up to a complete fill, a negative fill message is issued for the whole amount and another positive fill amount for the whole thing is added.  It appears that some negative fills in this log do *not* cause an Execution Ignore-Negative Fill message in RE.

I am pretty sure these negative fills are related to having an FA account allocation profile which allocates trades from a master account to subaccounts. (e.g. Fxxxxx acct +100, Fxxxx acct -100, Uxxxxx acct +100: net Uxxxxx +100).  The manually created trades in IB do not appear to have the negative fills in the IB log I believe because no allocation is required there  so 100% goes to Uxxxx sub account, so therefore there is no transfering of trades from one account to another.  Note: I could only get RightEdge working with IB once I setup an FA profile under Service Setup->IB->Other settings->FA Profile as well as setting this profile up within IB as well.  I would have prefered to keep it simple and not allocate trades and just specify one/my account to get 100% of any trades.

So is the solution to modify the IB plug-in.dll so that it does not ignore these negative fill messages and keeps a running total?

Posted Friday July 01 2011
I think what you want to do is just ignore all the fills to the Fxxxxx account. The TWS plugin already has logic in the client_ExecDetails to ignore fills for accounts that don't match the account specified in the plugin settings, so you may just be able to use that. Otherwise you can modify the plugin.

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems