Here is my example of using LINQ to query the collection of Orders.
I didn't want to loop thru all orders, if I can get a subset first.
// LINQ Query ? var openOrders = from theOrder in accountSelector.SelectedAccount.Orders where ( theOrder.OrderState == OrderState.Accepted || theOrder.OrderState == OrderState.Working ) orderby theOrder.Id select theOrder; foreach (Order openOrder in openOrders) { // bonk bonk }
EDITED:
My initial confusion was trying to figure out what type of collection the ~Acct~.Orders was.
I used this code
var ordCollTyep = accountSelector.SelectedAccount.Orders.GetType();
but trying to put all that in the type specifier in front of the local var "openOrders" would not compile, giving errors of
"CS0266
Cannot implicitly convert type 'System.Linq.IOrderedEnumerable<NinjaTrader.Cbi.Or der>' to 'System.Collections.ObjectModel.Collection<NinjaTr ader.Cbi.Order>'. An explicit conversion exists (are you missing a cast?)
so after a few drinks, I somehow got the idea to just use the generic type of "var" to recv the results from the LINQ query, because all I really needed is the item inside the filtered LINQ results.
the code at the beginning of this post is working code.
any comments for a better method are welcome.
Comment