QuickFix/n - 登录内的自定义字段
QuickFix/n - Custom fields inside Logon
我正在尝试创建一个基于 QuickFix/n 的启动器。
我的对应方(服务器)要求登录消息携带两个自定义 fields.I 已经将它们添加到数据字典、字段和登录消息中。
在代码中我可以操纵消息来添加用户名和密码,但我找不到如何加载自定义字段。
以下是我迄今为止所做的一些摘录:
TradeClientApp.cs
...
public void ToAdmin(Message message, SessionID sessionID)
{
QuickFix.SessionSettings settings = new QuickFix.SessionSettings("./initiator.cfg");
List<SessionID> sids = settings.GetSessions().ToList();
Dictionary settingsDict = settings.Get(sids.First());
var appName = settingsDict.GetString("ApplicationName");
var userType = settingsDict.GetString("UserType");
if (message.GetType() == typeof(QuickFix.FIX44.Logon))
{
message.SetField(new Username("USERNAME"));
message.SetField(new Password("PASSWORD"));
message.SetField(new QuickFix.Fields.ResetSeqNumFlag(true));
//tag 9933
message.SetField(new RawData(string.Format($"9933={appName}")));
//tag 20110
message.SetField(new RawData(string.Format($"20110={userType}")));
}
}
initiator.cfg文件:
[DEFAULT]
UseDataDictionary=Y
DataDictionary=./spec/FIX44.xml
FileStorePath=store
FileLogPath=log
ConnectionType=initiator
ReconnectInterval=60
[SESSION]
BeginString=FIX.4.4
SenderCompID=USERNAME
ResetSeqNumFlag=Y
Username=USERNAME
Password=PASSWORD
TargetCompID=TARGETCOMPID
StartTime=12:30:00
EndTime=23:30:00
HeartBtInt=10
ApplicationName=app-name
UserType=V
SocketConnectPort=446
SocketConnectHost=SERVERHOST
里面FIX44.XML
<message name="Logon" msgtype="A" msgcat="admin">
<field name="EncryptMethod" required="Y" />
<field name="HeartBtInt" required="Y" />
<field name="RawDataLength" required="N" />
<field name="RawData" required="N" />
<field name="ResetSeqNumFlag" required="N" />
<field name="NextExpectedMsgSeqNum" required="N" />
<field name="MaxMessageSize" required="N" />
<group name="NoMsgTypes" required="N">
<field name="RefMsgType" required="N" />
<field name="MsgDirection" required="N" />
</group>
<field name="TestMessageIndicator" required="N" />
<field name="Username" required="N" />
<field name="Password" required="N" />
<field name="ApplicationName" required="N" />
<field name="UserType" required="N" />
</message>
<fields>
...
<field number="9933" name="ApplicationName" type="STRING"/>
<field number="20110" name="UserType" type="STRING" />
</fields>
</fix>
当我尝试连接时,我得到了这个日志:
<outgoing> 8=FIX.4.49=12035=A34=149=USERNAME52=20191008-21:19:41.49856=TARGETCOMPID96=20110=V98=0108=10141=Y553=USERNAME554=PASSWORD10=097
使用我示例中所示的 RawData,消息携带 20110=V 作为 RawData,即标记 96,它不帮帮我。
我已经在 ToAdmin:
里面试过了
message.Header.SetField(new StringField(QuickFix.Fields.Tags.UserType, ""));
或
message.SetField(new QuickFix.Fields.UserType(true));
但都不起作用。
您究竟如何向登录消息添加自定义字段?
我认为您弄错了 RawData
数据类型。这实际上是指原始数据,而不是遵循默认编码的字符串。
来自规范:
string field containing raw data with no format or content
restrictions. Data fields are always immediately preceded by a length
field. The length field should specify the number of bytes of the
value of the data field (up to but not including the terminating SOH).
我不太熟悉 QuickFIX 的 C# 实现,但您应该能够简单地使用特定的标记号添加这些字段,例如
message.SetField(new StringField(20110, "V"));
我希望没有语法错误,但你应该明白了。
编辑:我看到您在登录消息上手动设置 ResetSeqNum 字段。这是气馁。 quickFIX/n 当你在设置中设置 ResetSeqNum=Y 时应该处理这个问题(你已经有那个设置)。
我正在尝试创建一个基于 QuickFix/n 的启动器。 我的对应方(服务器)要求登录消息携带两个自定义 fields.I 已经将它们添加到数据字典、字段和登录消息中。 在代码中我可以操纵消息来添加用户名和密码,但我找不到如何加载自定义字段。
以下是我迄今为止所做的一些摘录:
TradeClientApp.cs
...
public void ToAdmin(Message message, SessionID sessionID)
{
QuickFix.SessionSettings settings = new QuickFix.SessionSettings("./initiator.cfg");
List<SessionID> sids = settings.GetSessions().ToList();
Dictionary settingsDict = settings.Get(sids.First());
var appName = settingsDict.GetString("ApplicationName");
var userType = settingsDict.GetString("UserType");
if (message.GetType() == typeof(QuickFix.FIX44.Logon))
{
message.SetField(new Username("USERNAME"));
message.SetField(new Password("PASSWORD"));
message.SetField(new QuickFix.Fields.ResetSeqNumFlag(true));
//tag 9933
message.SetField(new RawData(string.Format($"9933={appName}")));
//tag 20110
message.SetField(new RawData(string.Format($"20110={userType}")));
}
}
initiator.cfg文件:
[DEFAULT]
UseDataDictionary=Y
DataDictionary=./spec/FIX44.xml
FileStorePath=store
FileLogPath=log
ConnectionType=initiator
ReconnectInterval=60
[SESSION]
BeginString=FIX.4.4
SenderCompID=USERNAME
ResetSeqNumFlag=Y
Username=USERNAME
Password=PASSWORD
TargetCompID=TARGETCOMPID
StartTime=12:30:00
EndTime=23:30:00
HeartBtInt=10
ApplicationName=app-name
UserType=V
SocketConnectPort=446
SocketConnectHost=SERVERHOST
里面FIX44.XML
<message name="Logon" msgtype="A" msgcat="admin">
<field name="EncryptMethod" required="Y" />
<field name="HeartBtInt" required="Y" />
<field name="RawDataLength" required="N" />
<field name="RawData" required="N" />
<field name="ResetSeqNumFlag" required="N" />
<field name="NextExpectedMsgSeqNum" required="N" />
<field name="MaxMessageSize" required="N" />
<group name="NoMsgTypes" required="N">
<field name="RefMsgType" required="N" />
<field name="MsgDirection" required="N" />
</group>
<field name="TestMessageIndicator" required="N" />
<field name="Username" required="N" />
<field name="Password" required="N" />
<field name="ApplicationName" required="N" />
<field name="UserType" required="N" />
</message>
<fields>
...
<field number="9933" name="ApplicationName" type="STRING"/>
<field number="20110" name="UserType" type="STRING" />
</fields>
</fix>
当我尝试连接时,我得到了这个日志:
<outgoing> 8=FIX.4.49=12035=A34=149=USERNAME52=20191008-21:19:41.49856=TARGETCOMPID96=20110=V98=0108=10141=Y553=USERNAME554=PASSWORD10=097
使用我示例中所示的 RawData,消息携带 20110=V 作为 RawData,即标记 96,它不帮帮我。 我已经在 ToAdmin:
里面试过了message.Header.SetField(new StringField(QuickFix.Fields.Tags.UserType, ""));
或
message.SetField(new QuickFix.Fields.UserType(true));
但都不起作用。
您究竟如何向登录消息添加自定义字段?
我认为您弄错了 RawData
数据类型。这实际上是指原始数据,而不是遵循默认编码的字符串。
来自规范:
string field containing raw data with no format or content restrictions. Data fields are always immediately preceded by a length field. The length field should specify the number of bytes of the value of the data field (up to but not including the terminating SOH).
我不太熟悉 QuickFIX 的 C# 实现,但您应该能够简单地使用特定的标记号添加这些字段,例如
message.SetField(new StringField(20110, "V"));
我希望没有语法错误,但你应该明白了。
编辑:我看到您在登录消息上手动设置 ResetSeqNum 字段。这是气馁。 quickFIX/n 当你在设置中设置 ResetSeqNum=Y 时应该处理这个问题(你已经有那个设置)。