向 QUICKFIX N 中的特定会话发送消息

Sending a Message to a specific session in QUICKFIX N

我最近接到任务,要为新交易者制作一个基本的交易平台。我正在连接到银行 FIX 4.4 实施。

银行已指定 2 个时段。一份用于报价数据,一份用于交易执行。

我正在使用 QuickfixN 并使用 c# 进行编码

我已经将发起程序会话配置设置为包含两个会话。端口不同,目标 comp id 和发件人 comp id 不同。我可以很好地连接到两者。我正在苦苦挣扎的是弄清楚如何通过一个会话而不是另一个会话发送我的订单请求。

两个会话都需要 FIX 4.4。默认情况下它只使用第一个会话。

好吧,您需要多路复用要在其上发送消息的 session 的 SessionId,并设置消息 header。像这样的东西(在 Java 中):

public void mySend (Message m) throws FieldNotFound 
{       
    String beginString = "FIX.4.4";
    String sender = "SENDER";
    String target = "TARGET";

    // Set the message headers
    m.getHeader().setField(new SenderCompID(sender));
    m.getHeader().setField(new TargetCompID(target));

    // Set the correct session for the initiator to send out to
    SessionID s = new SessionID(beginString, sender, target);

    // Lookup the relevant QF session
    _session = Session.lookupSession(s);

    // Send the FIX message
    try
    {
            if (_session != null)
            {
                _session.send(m);
            }
            else
            {
                log("Can't send message: FIX session not created.");
                log(" " + m.toString());
            }
    }
    catch (Exception e)
    {
            errorHandler(e);
    }
}

创建启动器时,将会话对象保存到变量中。 (也许通过 OnCreate 回调,就像 here 那样。)

使消息发送者可以访问这些变量class。

然后要发送消息,只需调用以下方法之一:

quoteSession.send(msg)
tradeSession.send(msg)