在 QuickFIX 接受器中自定义 FIX 登录过程

发布于 2024-09-16 20:58:37 字数 497 浏览 11 评论 0原文

我正在使用 QuickFIX 和 C# 创建 FIX 接受器(服务器)。我希望客户端(FIX 发起者)使用用户名和密码登录。但是,我不确定如何在 QuickFIX 中做到这一点。

通过调试 QuickFIX 源代码,我发现了以下事件序列:

  • QuickFIX 将调用 Session::verify 来验证登录。
  • Session::verify 将执行各种检查,例如组件 ID 和序列号,并在某个时刻确定收到的登录是否有效。
  • 然后,Session::verify 将调用 Application::fromAdmin 回调,我认为这是自定义登录等内容的自然位置。
  • 然而,此时 QuickFIX 已经确定登录成功,并且当回调返回时,接受器将返回相应的登录消息。

如何在接受器中自定义 FIX 登录过程?修改 QuickFIX 代码是我唯一的选择吗?

I'm using QuickFIX and C# to create a FIX acceptor (server). I want the client (the FIX initiator) to logon using a username and password. However, I'm not sure how I can do that in QuickFIX.

By debugging into the QuickFIX source code I have discovered the following sequence of events:

  • QuickFIX will call Session::verify to verify the logon.
  • Session::verify will perform various checks of things like comp ID's and sequence numbers and at some point determine that the logon received is valid.
  • Session::verify will then call the Application::fromAdmin callback which I assume is the natural place to customize things like logon.
  • However, at this point the logon has already been determined to be OK by QuickFIX and a corresponding logon message will be returned by the acceptor when the callback returns.

How do I customize the FIX logon process in an acceptor? Is modifying the QuickFIX code my only option?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

So要识趣 2024-09-23 20:58:37

如果您使用的是 FIX 4.3 或更高版本,登录消息可能包含 密码标签。如果您使用的是以前的版本,请将其设为自定义标签并将其添加到词典中。

fromAdmin 处理程序中,检查密码是否正确(从查找表或其他地方)。如果不是,则抛出 RejectLogon 例外。如果未引发此异常,QuickFix 将假定一切正常并让用户登录。

示例(需要更多健全性检查):

public void fromAdmin(Message message, SessionID id)
{
   var logon = message as QuickFix44.Logon;

   if (logon != null)
   {
      string userName = logon.getUserName().getValue();
      string expectedPassword = PasswordsByUser[userName];

      string suppliedPassword = logon.getPassword().getValue();

      if(expectedPassword != suppliedPassword)
          throw new RejectLogon();
   }     
}

If you are using FIX 4.3 or later, the Logon message can have a Password tag. If you are using a previous version, make it a custom tag and add it to the dictionaries.

In the fromAdmin handler, check that the password is correct (from a lookup table or elsewhere). If it is not, throw a RejectLogon exception. If this exception isn't thrown, QuickFix will assume everything is a-ok and log the user on.

Example (needs more sanity checks):

public void fromAdmin(Message message, SessionID id)
{
   var logon = message as QuickFix44.Logon;

   if (logon != null)
   {
      string userName = logon.getUserName().getValue();
      string expectedPassword = PasswordsByUser[userName];

      string suppliedPassword = logon.getPassword().getValue();

      if(expectedPassword != suppliedPassword)
          throw new RejectLogon();
   }     
}
错々过的事 2024-09-23 20:58:37

当管理消息从对方发送到您的 FIX 引擎时,fromAdmin 会通知您。这对于对登录消息进行额外验证(例如检查密码)非常有用。抛出 RejectLogon 异常将断开对方的连接。

会话验证通常检查 FIX 开始字符串、SenderCompID 和目标 CompID。如果这 3 个都很好,则会话已建立(QuickFIXJ 还有其他字段也用于子组件 ID)。

即使在会话已设置之后,对于该特定会话,接收方也不会接受消息,直到登录过程完成为止。如果您尝试这样做,您将被拒绝。

因此,在 fromAdmin 中,您可以检查传入的登录消息请求,并检查登录消息中包含的您期望该连接/会话的有效密码。

fromAdmin notifies you when an administrative message is sent from a counterparty to your FIX engine. This can be usefull for doing extra validation on logon messages such as for checking passwords. Throwing a RejectLogon exception will disconnect the counterparty.

Session verification generally ckecks for the FIX Begin String, SenderCompID and target CompID. If this 3 are fine then session is set up(QuickFIXJ has other fields also for subcomp ids).

Even after Session has been set up messages wouldn't be accepted at the acceptor, for that specific session, till logon process has been completed. You will get a reject if you try so.

So in fromAdmin you can check for the incoming logon message request and check for the valid password, contained in the logon message, you expect for that connection/session.

微暖i 2024-09-23 20:58:37

抛出 RejectLogon QuickFIXException 会破坏整个代码并中断其余会话(如果您确实有多个会话)。
就我自己而言,我编写了一条注销消息并将其发送回对方。代码会是这样的:

public void fromAdmin(Message message, SessionID id)
{
   var logon = message as QuickFix44.Logon;

   if (logon != null)
   {
      string userName = logon.getUserName().getValue();
      string expectedPassword = PasswordsByUser[userName];

      string suppliedPassword = logon.getPassword().getValue();

      if(expectedPassword != suppliedPassword)
          {
                Message _logoutmess = new Message();
                _logoutmess.Header.SetField(new MsgType() { Tag = 35, Obj = "5" });
                _logoutmess.SetField(new Text("Invalid credentials"));
                Session.SendToTarget(_logoutmess, id);
          }
   }     
}

Throwing a RejectLogon QuickFIXException breaks the whole code and interrupts the rest of the sessions (if you do have more than one).
In my own case, I compose a logout message and have it sent back to the counterparty. Code would be something like this:

public void fromAdmin(Message message, SessionID id)
{
   var logon = message as QuickFix44.Logon;

   if (logon != null)
   {
      string userName = logon.getUserName().getValue();
      string expectedPassword = PasswordsByUser[userName];

      string suppliedPassword = logon.getPassword().getValue();

      if(expectedPassword != suppliedPassword)
          {
                Message _logoutmess = new Message();
                _logoutmess.Header.SetField(new MsgType() { Tag = 35, Obj = "5" });
                _logoutmess.SetField(new Text("Invalid credentials"));
                Session.SendToTarget(_logoutmess, id);
          }
   }     
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文