Get value from void QuickFix library method
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
add a comment |
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
add a comment |
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
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
c# quickfixn
edited Jan 2 at 7:30
user2376997
asked Jan 2 at 7:24
user2376997user2376997
10439
10439
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
.
add a comment |
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
.
add a comment |
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
.
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
.
answered Feb 8 at 19:49
PavelPavel
665
665
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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