Get value from void QuickFix library method












1















I have a QuickFix Application in C#:



    public class MyQuickFixApp : IApplication
{
...
public void ToApp(Message msg, SessionID sessionID)
{
string s = msg.GetString(Tags.ClOrdID);
...
}
public void FromApp(Message msg, SessionID sessionID) { }
}


where the message to other Fix Server is sent from ToApp and the reply is comming to FromApp.

I need to store the tag value of a sent message (s) to select the corresponding reply. ToApp method is returning void. I tried to store the value in a public static filed, but it fails.



Looks like the follows:



    public class MyQuickFixApp : IApplication
{
...
public static string currClOrdID = "";
public void ToApp(Message msg, SessionID sessionID)
{
string s = msg.GetString(Tags.ClOrdID);
currClOrdID = s;
...
}
public void FromApp(Message msg, SessionID sessionID)
{
if (Equals(currClOrdID)) ...
}
}


I am getting NullreferenceException on the currClOrdID. What is the general strategy to do it? Please give me some hints.










share|improve this question





























    1















    I have a QuickFix Application in C#:



        public class MyQuickFixApp : IApplication
    {
    ...
    public void ToApp(Message msg, SessionID sessionID)
    {
    string s = msg.GetString(Tags.ClOrdID);
    ...
    }
    public void FromApp(Message msg, SessionID sessionID) { }
    }


    where the message to other Fix Server is sent from ToApp and the reply is comming to FromApp.

    I need to store the tag value of a sent message (s) to select the corresponding reply. ToApp method is returning void. I tried to store the value in a public static filed, but it fails.



    Looks like the follows:



        public class MyQuickFixApp : IApplication
    {
    ...
    public static string currClOrdID = "";
    public void ToApp(Message msg, SessionID sessionID)
    {
    string s = msg.GetString(Tags.ClOrdID);
    currClOrdID = s;
    ...
    }
    public void FromApp(Message msg, SessionID sessionID)
    {
    if (Equals(currClOrdID)) ...
    }
    }


    I am getting NullreferenceException on the currClOrdID. What is the general strategy to do it? Please give me some hints.










    share|improve this question



























      1












      1








      1








      I have a QuickFix Application in C#:



          public class MyQuickFixApp : IApplication
      {
      ...
      public void ToApp(Message msg, SessionID sessionID)
      {
      string s = msg.GetString(Tags.ClOrdID);
      ...
      }
      public void FromApp(Message msg, SessionID sessionID) { }
      }


      where the message to other Fix Server is sent from ToApp and the reply is comming to FromApp.

      I need to store the tag value of a sent message (s) to select the corresponding reply. ToApp method is returning void. I tried to store the value in a public static filed, but it fails.



      Looks like the follows:



          public class MyQuickFixApp : IApplication
      {
      ...
      public static string currClOrdID = "";
      public void ToApp(Message msg, SessionID sessionID)
      {
      string s = msg.GetString(Tags.ClOrdID);
      currClOrdID = s;
      ...
      }
      public void FromApp(Message msg, SessionID sessionID)
      {
      if (Equals(currClOrdID)) ...
      }
      }


      I am getting NullreferenceException on the currClOrdID. What is the general strategy to do it? Please give me some hints.










      share|improve this question
















      I have a QuickFix Application in C#:



          public class MyQuickFixApp : IApplication
      {
      ...
      public void ToApp(Message msg, SessionID sessionID)
      {
      string s = msg.GetString(Tags.ClOrdID);
      ...
      }
      public void FromApp(Message msg, SessionID sessionID) { }
      }


      where the message to other Fix Server is sent from ToApp and the reply is comming to FromApp.

      I need to store the tag value of a sent message (s) to select the corresponding reply. ToApp method is returning void. I tried to store the value in a public static filed, but it fails.



      Looks like the follows:



          public class MyQuickFixApp : IApplication
      {
      ...
      public static string currClOrdID = "";
      public void ToApp(Message msg, SessionID sessionID)
      {
      string s = msg.GetString(Tags.ClOrdID);
      currClOrdID = s;
      ...
      }
      public void FromApp(Message msg, SessionID sessionID)
      {
      if (Equals(currClOrdID)) ...
      }
      }


      I am getting NullreferenceException on the currClOrdID. What is the general strategy to do it? Please give me some hints.







      c# quickfixn






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 7:30







      user2376997

















      asked Jan 2 at 7:24









      user2376997user2376997

      10439




      10439
























          1 Answer
          1






          active

          oldest

          votes


















          1














          As per QuickFix/n Tutorial:




          The best way to write an app is with the specific, strongly typed Message and Field classes




          So you could use Crack(...); in FromApp:



          using QuickFix;

          public class MyApplication : MessageCracker, IApplication
          {
          public void FromApp(Message msg, SessionID sessionID)
          {
          Crack(msg, sessionID);
          }
          //...
          }


          Regarding ClOrdID, you could extract it from the message and directly pass it to processing function, it is safer than keeping ClOrdID in static variable in multi-threaded message processing.



          For example (assuming you need to process ExecutionReport message):



          public void OnMessage(QuickFix.FIX44.ExecutionReport msgReport, SessionID sessionID)
          {
          string clOrdID = msgReport.ClOrdID.getValue();
          ...
          YourProcessing(clOrdID, ...);
          }


          Notice that OnMessage(...) will be called from Crack(msg, sessionID);



          If you need to store additional data for processing the received message, I would use a dictionary, as you may have several messages pending, and the responses may arrive in unpredictable order. Also it seems logical to store such data close to (and before) calling Send rather then in ToApp, like below (assuming you are sending an order for execution, expecting ExecutionReport in reply):



          private ConcurrentDictionary<string, ...> _orderData = 
          new ConcurrentDictionary<string, ...>();

          public bool PlaceNewOrder(...)
          {
          string clOrdID = ...;
          QuickFix.FIX44.NewOrderSingle msgOrder =
          new QuickFix.FIX44.NewOrderSingle(new ClOrdID(clOrdID), ...);
          ...;
          _orderData.TryAdd(clOrdID, <data required for later processing>);
          // Notice the data is stored before sending the message
          // so it will be available to process a response
          Session.SendToTarget(msgOrder, sessionID);
          }


          When processing a response message you could retrieve the data stored for this particular clOrdID:



          private void YourProcessing(clOrdID, ...)
          {
          ...;
          _orderData.TryGetValue(clOrdID, out ...);
          // You may want to check return value to make sure the data was stored for this clOrdID...
          ...;
          }


          Also notice that at some point you should clean up the dictionary, for example when you know from processed message, that it is the final one, and do not expect any more messages for this ClOrdID.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002655%2fget-value-from-void-quickfix-library-method%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            As per QuickFix/n Tutorial:




            The best way to write an app is with the specific, strongly typed Message and Field classes




            So you could use Crack(...); in FromApp:



            using QuickFix;

            public class MyApplication : MessageCracker, IApplication
            {
            public void FromApp(Message msg, SessionID sessionID)
            {
            Crack(msg, sessionID);
            }
            //...
            }


            Regarding ClOrdID, you could extract it from the message and directly pass it to processing function, it is safer than keeping ClOrdID in static variable in multi-threaded message processing.



            For example (assuming you need to process ExecutionReport message):



            public void OnMessage(QuickFix.FIX44.ExecutionReport msgReport, SessionID sessionID)
            {
            string clOrdID = msgReport.ClOrdID.getValue();
            ...
            YourProcessing(clOrdID, ...);
            }


            Notice that OnMessage(...) will be called from Crack(msg, sessionID);



            If you need to store additional data for processing the received message, I would use a dictionary, as you may have several messages pending, and the responses may arrive in unpredictable order. Also it seems logical to store such data close to (and before) calling Send rather then in ToApp, like below (assuming you are sending an order for execution, expecting ExecutionReport in reply):



            private ConcurrentDictionary<string, ...> _orderData = 
            new ConcurrentDictionary<string, ...>();

            public bool PlaceNewOrder(...)
            {
            string clOrdID = ...;
            QuickFix.FIX44.NewOrderSingle msgOrder =
            new QuickFix.FIX44.NewOrderSingle(new ClOrdID(clOrdID), ...);
            ...;
            _orderData.TryAdd(clOrdID, <data required for later processing>);
            // Notice the data is stored before sending the message
            // so it will be available to process a response
            Session.SendToTarget(msgOrder, sessionID);
            }


            When processing a response message you could retrieve the data stored for this particular clOrdID:



            private void YourProcessing(clOrdID, ...)
            {
            ...;
            _orderData.TryGetValue(clOrdID, out ...);
            // You may want to check return value to make sure the data was stored for this clOrdID...
            ...;
            }


            Also notice that at some point you should clean up the dictionary, for example when you know from processed message, that it is the final one, and do not expect any more messages for this ClOrdID.






            share|improve this answer




























              1














              As per QuickFix/n Tutorial:




              The best way to write an app is with the specific, strongly typed Message and Field classes




              So you could use Crack(...); in FromApp:



              using QuickFix;

              public class MyApplication : MessageCracker, IApplication
              {
              public void FromApp(Message msg, SessionID sessionID)
              {
              Crack(msg, sessionID);
              }
              //...
              }


              Regarding ClOrdID, you could extract it from the message and directly pass it to processing function, it is safer than keeping ClOrdID in static variable in multi-threaded message processing.



              For example (assuming you need to process ExecutionReport message):



              public void OnMessage(QuickFix.FIX44.ExecutionReport msgReport, SessionID sessionID)
              {
              string clOrdID = msgReport.ClOrdID.getValue();
              ...
              YourProcessing(clOrdID, ...);
              }


              Notice that OnMessage(...) will be called from Crack(msg, sessionID);



              If you need to store additional data for processing the received message, I would use a dictionary, as you may have several messages pending, and the responses may arrive in unpredictable order. Also it seems logical to store such data close to (and before) calling Send rather then in ToApp, like below (assuming you are sending an order for execution, expecting ExecutionReport in reply):



              private ConcurrentDictionary<string, ...> _orderData = 
              new ConcurrentDictionary<string, ...>();

              public bool PlaceNewOrder(...)
              {
              string clOrdID = ...;
              QuickFix.FIX44.NewOrderSingle msgOrder =
              new QuickFix.FIX44.NewOrderSingle(new ClOrdID(clOrdID), ...);
              ...;
              _orderData.TryAdd(clOrdID, <data required for later processing>);
              // Notice the data is stored before sending the message
              // so it will be available to process a response
              Session.SendToTarget(msgOrder, sessionID);
              }


              When processing a response message you could retrieve the data stored for this particular clOrdID:



              private void YourProcessing(clOrdID, ...)
              {
              ...;
              _orderData.TryGetValue(clOrdID, out ...);
              // You may want to check return value to make sure the data was stored for this clOrdID...
              ...;
              }


              Also notice that at some point you should clean up the dictionary, for example when you know from processed message, that it is the final one, and do not expect any more messages for this ClOrdID.






              share|improve this answer


























                1












                1








                1







                As per QuickFix/n Tutorial:




                The best way to write an app is with the specific, strongly typed Message and Field classes




                So you could use Crack(...); in FromApp:



                using QuickFix;

                public class MyApplication : MessageCracker, IApplication
                {
                public void FromApp(Message msg, SessionID sessionID)
                {
                Crack(msg, sessionID);
                }
                //...
                }


                Regarding ClOrdID, you could extract it from the message and directly pass it to processing function, it is safer than keeping ClOrdID in static variable in multi-threaded message processing.



                For example (assuming you need to process ExecutionReport message):



                public void OnMessage(QuickFix.FIX44.ExecutionReport msgReport, SessionID sessionID)
                {
                string clOrdID = msgReport.ClOrdID.getValue();
                ...
                YourProcessing(clOrdID, ...);
                }


                Notice that OnMessage(...) will be called from Crack(msg, sessionID);



                If you need to store additional data for processing the received message, I would use a dictionary, as you may have several messages pending, and the responses may arrive in unpredictable order. Also it seems logical to store such data close to (and before) calling Send rather then in ToApp, like below (assuming you are sending an order for execution, expecting ExecutionReport in reply):



                private ConcurrentDictionary<string, ...> _orderData = 
                new ConcurrentDictionary<string, ...>();

                public bool PlaceNewOrder(...)
                {
                string clOrdID = ...;
                QuickFix.FIX44.NewOrderSingle msgOrder =
                new QuickFix.FIX44.NewOrderSingle(new ClOrdID(clOrdID), ...);
                ...;
                _orderData.TryAdd(clOrdID, <data required for later processing>);
                // Notice the data is stored before sending the message
                // so it will be available to process a response
                Session.SendToTarget(msgOrder, sessionID);
                }


                When processing a response message you could retrieve the data stored for this particular clOrdID:



                private void YourProcessing(clOrdID, ...)
                {
                ...;
                _orderData.TryGetValue(clOrdID, out ...);
                // You may want to check return value to make sure the data was stored for this clOrdID...
                ...;
                }


                Also notice that at some point you should clean up the dictionary, for example when you know from processed message, that it is the final one, and do not expect any more messages for this ClOrdID.






                share|improve this answer













                As per QuickFix/n Tutorial:




                The best way to write an app is with the specific, strongly typed Message and Field classes




                So you could use Crack(...); in FromApp:



                using QuickFix;

                public class MyApplication : MessageCracker, IApplication
                {
                public void FromApp(Message msg, SessionID sessionID)
                {
                Crack(msg, sessionID);
                }
                //...
                }


                Regarding ClOrdID, you could extract it from the message and directly pass it to processing function, it is safer than keeping ClOrdID in static variable in multi-threaded message processing.



                For example (assuming you need to process ExecutionReport message):



                public void OnMessage(QuickFix.FIX44.ExecutionReport msgReport, SessionID sessionID)
                {
                string clOrdID = msgReport.ClOrdID.getValue();
                ...
                YourProcessing(clOrdID, ...);
                }


                Notice that OnMessage(...) will be called from Crack(msg, sessionID);



                If you need to store additional data for processing the received message, I would use a dictionary, as you may have several messages pending, and the responses may arrive in unpredictable order. Also it seems logical to store such data close to (and before) calling Send rather then in ToApp, like below (assuming you are sending an order for execution, expecting ExecutionReport in reply):



                private ConcurrentDictionary<string, ...> _orderData = 
                new ConcurrentDictionary<string, ...>();

                public bool PlaceNewOrder(...)
                {
                string clOrdID = ...;
                QuickFix.FIX44.NewOrderSingle msgOrder =
                new QuickFix.FIX44.NewOrderSingle(new ClOrdID(clOrdID), ...);
                ...;
                _orderData.TryAdd(clOrdID, <data required for later processing>);
                // Notice the data is stored before sending the message
                // so it will be available to process a response
                Session.SendToTarget(msgOrder, sessionID);
                }


                When processing a response message you could retrieve the data stored for this particular clOrdID:



                private void YourProcessing(clOrdID, ...)
                {
                ...;
                _orderData.TryGetValue(clOrdID, out ...);
                // You may want to check return value to make sure the data was stored for this clOrdID...
                ...;
                }


                Also notice that at some point you should clean up the dictionary, for example when you know from processed message, that it is the final one, and do not expect any more messages for this ClOrdID.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 8 at 19:49









                PavelPavel

                665




                665
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002655%2fget-value-from-void-quickfix-library-method%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    'app-layout' is not a known element: how to share Component with different Modules

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    WPF add header to Image with URL pettitions [duplicate]