Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

updating Order list on realtime

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

    updating Order list on realtime

    Hello. I have a List containing various stop orders. I'm trying to set it up so that if a strategy shuts down and then restarts all those orders are changed from historical to realtime. In the State = State.Realtime, I have written:

    foreach (Order o in StopList)
    stopList(o) = GetRealtimeOrder(o)

    but the compiler doesn't like that. I feel like this should be straightforward but clearly I don't understand either how Lists work or how the GetRealtimeOrder works. Can you help me?

    Thanks

    #2
    Hello stewarco,

    Thanks for the note.

    When you use a foreach loop, you do not need to reference the list again in the loop body, it will iterate each value in the List object. I do not have the full context here, but you can do this to make it work:

    Code:
    foreach (Order o in StopList)
    o = GetRealtimeOrder(o)
    Here is a publicly available link that includes some examples of using foreach:



    Please let me know if I can assist further.

    Comment


      #3
      follow up

      thanks. I'll review the link you provided, and I had tried the language you suggested, but I get the Error message "Cannot assign to 'o' because it is a 'foreach iteration variable'. any idea what's going on there?

      Comment


        #4
        Hello stewarco,

        Thanks for the reply.

        Sorry I did not catch that. You can not mutate the actual iteration object while doing a foreach. You will either have to use a regular for loop like so:

        Code:
        for(int i = 0; i < myList.Count; ++i)
        			{
        				Print(myList[i]);
        			}
        Or you can use the List class IndexOf method to get the index from the object being iterated.

        https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx - IndexOf

        There are also other solutions, like this change method described in this post:

        In one place i am using the list of string in that case the i am able to change the value of the string as code given below, foreach(string item in itemlist.ToList()) { item = someValue; //I am...


        Please let me know if I can assist further.

        Comment


          #5
          ok thanks i'll try those

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X