0

I've recently been given the task of making a basic trading platform for new traders. I'm connecting to a bank FIX 4.4 implementation.

The bank has specified 2 sessions. One for quote data and one for trade executions.

I'm using QuickfixN and coding in c#

I have set up my initiator session config to have both sessions in it. The port is different and the target comp ids and sender comp ids are different. I can connect to both fine. What i'm struggling with is figuring out how to send my order requests through one session and not the other.

Both sessions require FIX 4.4. By default it just uses the first session.

Brett
  • 1,951
  • 2
  • 28
  • 35

2 Answers2

4

When you create the initiators, save the session objects into variables. (Perhaps via the OnCreate callback, as done here.)

Make those variables accessible to the message-sending class.

Then to send messages, just call one of:

quoteSession.send(msg)
tradeSession.send(msg)
Grant Birchmeier
  • 17,809
  • 11
  • 63
  • 98
0

Well you need to multiplex the SessionId of the session on which to send a message, and setup the message header. Something like this (in 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);
    }
}
rupweb
  • 3,052
  • 1
  • 30
  • 57
  • 1
    Setting the headers here is useless; they'll be clobbered with the session's values during `_session.send(m)`. Also, doing a session lookup for every send is unnecessary; better to just save the sessions into externally visible vars and let the caller decide which to use. – Grant Birchmeier May 09 '16 at 14:22
  • Thanks, I didn't know the sender comp id and target comp id tags for a QF message would be overwritten by calling send. Right? Code similar to above was supposed to be a quick way to solve multiplexing between many different acceptor and initiator sessions (i.e. for price distribution and updates to many FIX clients) and yeah managing some kind of internal array of sessions is a better way of doing it (you don't know how many sessions will be dynamically connected / disco'd etc) – rupweb May 11 '16 at 15:58
  • Correct. Most of the time you'll create a message without setting any header fields at all; you just rely on the engine to do it for you based on the session. In QuickFIX/n, the BeginString/SenderCompID/TargetCompID will all be clobbered. In Java, I'm not 100% sure, but I suspect it's the same. – Grant Birchmeier May 11 '16 at 21:45