Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AddOnFramework.cs Orders Collection, example using LINQ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    AddOnFramework.cs Orders Collection, example using LINQ?

    EDITED:
    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.

    Code:
    // 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
    }
    thank you

    EDITED:
    My initial confusion was trying to figure out what type of collection the ~Acct~.Orders was.

    I used this code
    Code:
    var ordCollTyep = accountSelector.SelectedAccount.Orders.GetType();
    to return the type as System.Collections.ObjectModel.Collection<NinjaTra der.Cbi.Order>

    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.

    Last edited by balltrader; 02-12-2021, 09:42 PM.

    #2
    Hello balltrader,

    Thanks for your post.

    This is more of a C# question than a NinjaScript specific question.

    We will leave the thread open for any community members who have written their NinjaScript code to utilize LINQ to share their comments.

    If you have any other NinjaScript specific inquiries, please don't hesitate to open a new thread.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    581 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    338 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    554 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    552 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X