Profile Picture

Position "pending close"

Posted By gillean 5 Years Ago
Message
Posted Wednesday February 08 2012
Good afternoon everyone,

I'm working on a plugin for MBT and have run into a problem while testing it live on a demo account. I keep working myself into a situation where RE and MBT become out of sync, and I am wondering if there's anything I can do to fix it. Consider the following example.

I am long 100 shares of ABC. I also have a pending stoploss order to sell 100 shares of ABC. These are both reflected correctly in the RE open positions and pending orders tabs. My system then issues a Position.CloseAtMarket() for the ABC position. My stop order gets cancelled correctly but then let's say the Sell 100 ABC order gets rejected for whatever reason. The broker plugin sends an OrderUpdated event with the new BrokerOrderState.Rejected status. RightEdge keeps the position marked "Pending close". If I try to manually close it, I get an error that says something to the effect of "this position is already pending close".

My question is: How can I make RightEdge realize this position is still open and no longer "pending close" ? It appears that I've done everything I can from the plugin side by updating the order with BrokerOrderState.Rejected. Is there something more I can do from the plugin side or do I need to create something in my system to look for this?

Thanks for any insight
Posted Thursday February 16 2012
Hi Gillean,

Right now there's not really a good way to get out of this situation. For the next build, I've fixed it so that if the close order is cancelled or rejected, the pending close flag will be reset to false.

For now, instead of calling CloseAtMarket(), you can just submit a market order to close the position with SubmitOrder(), and cancel any profit targets or stop losses. (Those orders will still automatically be cancelled once the close order is filled, so you don't necessarily need to do this part.) This way the position won't be marked "pending close" in the first place.

Thanks,
Daniel
Posted Monday February 20 2012
dplaisted (2/16/2012)
For the next build, I've fixed it so that if the close order is cancelled or rejected, the pending close flag will be reset to false.


Thanks Daniel, glad to hear this. I'll try what you suggested to see if I can make it work that way
Posted Tuesday June 18 2013
Hi Daniel, I have this same problem of not being able to close positions if there was a previous attempt. In a LIVE system (build 39), using the method of sending an order to close at market actually causes RE to give an exception about null reference while writing to the Live System grid, however it works in sim.

So I'm in a spot of bother. When will the fix you mentioned be available? or which build was it introduced?

I can't tell because the Announcement Forum is currently empty

thanks in advance.
Posted Thursday June 20 2013
Hi Smersh,

This was fixed in build 42.

Thanks,
Daniel
Posted Thursday June 20 2013
Great news! thanks
Posted Sunday June 23 2013
Daniel - was the change made inside RE or a plugin?

I have a small change to the TWS plugin that I need to apply to the new b48 src code and I want to make sure I don't lose your fix for this problem.

thanks
Posted Tuesday June 25 2013
I don't think that particular fix was in the TWS plugin itself, but there have been other fixes, so I'd recommend you update to the latest source. You can make a backup of your code and then compare your old code to the new plugin code with a diff tool such as WinMerge.

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems