I am implementing a scale in/out functionality and have discovered I need to handle the case where the user drags a stop on top of another in an effort to merge the two.
No problem... (except there is) I figured I could detect the move in OnOrderUpdate, which I can when OrderState == ChangePending and update the list of order objects I'm trying to keep track of. That all works. In my list of stop orders, I can find the stop the user is dragging and remove that from the list. Now I just need to update the quantity of the order they dragged the order onto. I do that just fine too. But when I look at the order on the chart, the order flag from ChartTrader tells me there is more orders in the stop/target than should be.
Catch-22. OK, maybe I don't really need to update my order object in my list - maybe they get updated by the framework - who knows?. So I try that - I comment out the line of code that updates my order object. The stop/target flag from ChartTrader is now correct after I drag one order on top of another but when I check the quantity of the order that I still have in my list, the order is not updated. (I didn't think it would be - just trying everything I can think of.)
It seems, when I change the order quantity in my list object it adds one extra to the chart object, (because the order that I'm dragging has qty = 1) making that incorrect but at least my order list is correct. In other words, if the qty on the chart trader flag to which I'm dragging is 5, the new qty ends up being 7 instead of 6. When I don't update the quantity, the flag on the ChartTrader is correct, my the orders in my list are not. Here is the code that simply cannot win:
if( order.OrderState == OrderState.ChangePending ) { double draggedStopPrice = order.StopPrice; double droppedStopPrice = order.StopPriceChanged; double draggedTargetPrice = order.LimitPrice; double droppedTargetPrice = order.LimitPriceChanged; // Find the list object (order) with the dragged price and remove that guy if( draggedStopPrice > 0 ) { // User moved a stop // First update the quantity of the dropped object Order stopOrder2Update = StopOrders.Find(o => o.StopPrice == droppedStopPrice); if( stopOrder2Update != null ) { //stopOrder2Update.Quantity += order.Quantity; // Next, remove the order from the list Order stopOrder2Change = StopOrders.Find(o => o.StopPrice == draggedStopPrice); if (stopOrder2Change != null) { StopOrders.Remove(stopOrder2Change); } } } else if( draggedTargetPrice > 0 ) { // User moved a target // First update the quantity of the dropped object Order targetOrder2Update = TargetOrders.Find(o => o.LimitPrice == droppedTargetPrice); if (targetOrder2Update != null) { //targetOrder2Update.Quantity += order.Quantity; // Next, remove the order from the list Order targetOrder2Change = TargetOrders.Find(o => o.LimitPrice == draggedTargetPrice); if (targetOrder2Change != null) { TargetOrders.Remove(targetOrder2Change); } } } }
Any idea what I'm missing? What is the proper way to update a quantity so it doesn't mess with the what ChartTrader thinks it should be?
Thanks!
PS. I'm using unmanaged orders.
Comment