Select Case FIXV
Case "FIX44"
Dim _message As QuickFix.FIX44.Heartbeat = New QuickFix.FIX44.Heartbeat
_message.Header.SetField(New MsgSeqNum(_csession.NextSenderMsgSeqNum))
_message.Header.SetField(New MsgType(0))
_message.Validate()
Case "FIX43"
Dim _message As QuickFix.FIX43.Heartbeat = New QuickFix.FIX43.Heartbeat
_message.Header.SetField(New MsgSeqNum(_csession.NextSenderMsgSeqNum))
_message.Header.SetField(New MsgType(0))
_message.Validate()
Case Else
End Select
Is there a way to simplify the following code, by dynamically choosing the FIX version 4.4 or 4.3? Thanks.
CodePudding user response:
OpenAI gave me this which works:
Dim _message As QuickFix.Message = Nothing
Select Case FIXV
Case "FIX44"
_message = New QuickFix.FIX44.Heartbeat()
Case "FIX43"
_message = New QuickFix.FIX43.Heartbeat()
End Select
If _message IsNot Nothing Then
_message.Header.SetField(New MsgSeqNum(_csession.NextSenderMsgSeqNum))
_message.Header.SetField(New MsgType(0))
_message.Validate()
End If
CodePudding user response:
There is not a way to do this, and that's intentional. There shouldn't be, because the fields that a message contains will usually differ between FIX versions. You just happened to pick Heartbeat, the most basic and unchanging message type across all FIX versions.
But let's look at the News (35=B) message: * News 4.0 has the Text (58) field, but not Headline (148) * News 4.4 has Headline, but not Text
Therefore, your suggested solution won't work.
Plus, it's just not really a common use case. In practice, you're writing an engine specific to a single counterparty connection. FIX doesn't really lend itself to one-size-fits-all solutions-- it's a customizable engine, because in practice, FIX is so flexible that you NEED to customize for every counterparty.
P.S. Why are you manually creating Heartbeats? The engine handles that for you.