0
# Here is my settings.cfg file:
# Thank you.Here is what i tried.My settings.cfg file

[DEFAULT]
# Settings which apply to all the Sessions.
ConnectionType=initiator
LogonTimeout=30
ReconnectInterval=20
ResetOnLogon=Y
FileLogPath=C:\Work\QuickFIXJ\logs
FileStorePath=C:\Work\QuickFIXJ\logs

[SESSION]
# Settings specifically for one session
BeginString=FIX.4.4
SenderCompID=XYZ
TargetCompID=TYZ
TimeZone=Asia/Tokyo
StartTime=16:00:00
EndTime=13:30:00
HeartBtInt=60
SocketConnectPort=7200
SocketConnectHost=123.123.123.123
UseDataDictionary=Y
DataDictionary=C:\Work\QuickFIXJ\datadictionary\FIX44.xml

[GATEWAY]
Port=4444

[TRANSPORT]
Port=4444

and then

//initiator code:

public class TestQuickFixJConnectivity {
    public static void main(String[] args) {
        SocketInitiator socketInitiator = null;
        try {
            SessionSettings sessionSettings = new SessionSettings("C:\\Work\\QuickFixJ\\sessionSettings.txt");
            Application application = new TestApplicationImpl();
            FileStoreFactory fileStoreFactory = new FileStoreFactory(sessionSettings);
            FileLogFactory logFactory = new FileLogFactory(sessionSettings);
            MessageFactory messageFactory = new DefaultMessageFactory();
            socketInitiator = new SocketInitiator(application,
                    fileStoreFactory, sessionSettings, logFactory,
                    messageFactory);
            socketInitiator.start();
            SessionID sessionId = socketInitiator.getSessions().get(0);
            sendLogonRequest(sessionId);
            int i = 0;
            do {
                try {
                    Thread.sleep(1000);
                    System.out.println(socketInitiator.isLoggedOn());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                i++;
            } while ((!socketInitiator.isLoggedOn()) && (i < 30));
        } catch (ConfigError e) {
            e.printStackTrace();
        } catch (SessionNotFound e) {
            e.printStackTrace();
        } catch (Exception exp) {
            exp.printStackTrace();
        } finally {
            if (socketInitiator != null) {
                socketInitiator.stop(true);
            }
        }
    }

    private static void sendLogonRequest(SessionID sessionId) throws SessionNotFound {
        Logon logon = new Logon();
        Message msg=new Message();
        Header header = msg.getHeader();
        logon.set(new HeartBtInt(60));
        logon.set(new ResetSeqNumFlag(true));
        header.setField(new BeginString("FIX.4.4"));
        header.setField(new MsgType("AP"));
        header.setField(new SenderCompId("XYZ"));
        header.setField(new TagetCompId("TYZ"));
        header.setField(new ResetSeqNumFlag(true));
        //here i m setting all the fields in the csv report .
        msg.setField(705,new SortQty(""));
        // ....
        //below statement returning false
        boolean sent = Session.sendToTarget(msg, sessionId);
        System.out.println("Logon Message Sent : " + sent);
    }
}

Please find my observations below:

In the event logs I am seeing as Created session: and the message which I am trying to send. Also I could see that the sender sequence number is getting incremented in the logs.

Messages.log and header.logs are blank and body.log has the message which i am trying to send.

Also onCreate and ToApp are being called when I try to run the code.

I want to know whether i have sent the message successfully ?

Also boolean sent = Session.sendToTarget(msg, sessionId); is returning false.

I don't see ToAdmin and FromAdmin being executed in my code. Also Do I need to write the acceptor code as well for the same, or just the initiator code will be fine. The DataDictionary which i am using has all the fields set, but I am not sure whether its being used by QuickFixJ when i try to execute the code.

Please advise whats going wrong in this?

1 Answer 1

1

OK your settings file looks ok and you're saying it works, but I don't think you need GATEWAY and TRANSPORT headings

As for your code, all you need to do to start with is setup the default QuickFIX Application, FileStoreFactory, LogFactory, MessageFactory and Initiator which you have done.

The default QuickFIX automatically logs on to the Target in your settings file, and if the logon is accepted then it begins to heartbeat. From your comments it sounds like this is happening.

So what's going wrong is your sendLogonRequest is not necessary. Also, if you do send "extra" logons then the target FIX engine will probably reject or ignore them. The reject message would be seen in the logs or file store.

So then you have the QuickFIX API with which to start with you can simply output messages to your own log.

Something like this

public void fromApp(Message msg, SessionID s) throws UnsupportedMessageType, FieldNotFound, IncorrectTagValue
{
    log.debug(String.valueOf(LocalTime.now()) + " INITIATOR: FromApp " + msg.toString());
}
public void toApp(Message msg, SessionID s)
{
    log.info(String.valueOf(LocalTime.now()) + " INITIATOR: ToApp " + msg.toString());  
}   
public void fromAdmin(Message msg, SessionID s) throws FieldNotFound, IncorrectTagValue
{
    Log.trace("INITIATOR: FromAdmin " + msg.getClass() + " " + msg.toString());    
}   
public void onCreate(SessionID s) 
{
    log.info("INITIATOR: OnCreate " + s.toString());
}    
public void onLogout(SessionID s)
{
    log.error("INITIATOR: OnLogout " + s.toString());   
}   
public void onLogon(SessionID s)
{
    log.info("INITIATOR: OnLogon " + s.toString());
}    
public void toAdmin(Message msg, SessionID s)
{
    log.trace("INITIATOR: ToAdmin " + msg.getClass() + " " + msg.toString());
}

Then when you want to send a message, try something like this:

    QuoteReqID id = new QuoteReqID("1234");

    // Create Quote Request message
    QuoteRequest qr = new QuoteRequest(id);

    // Setup outgoing group and specify an index for each group tag
    NoRelatedSym g = new NoRelatedSym();

    String instrument = m.getString("EUR/USD");
    Symbol symbol = new Symbol(instrument);     
    g.setField(1, symbol);

    QuoteRequestType qt = new QuoteRequestType(102);
    g.setField(2, qt);

    OrderQty qty = new OrderQty("1000000");
    g.setField(3, qty);

    SettlType sType = new SettlType("B");
    g.setField(4, sType);

    SettlDate sDate = new SettlDate("20170315");
    g.setField(5, sDate);

    Account account = new Account("357647");
    g.setField(6, account); 

    // add group to request
    qr.addGroup(g);

    Session s = Session.lookupSession(i.getSessions().get(0));
    s.send(qr); 
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you :)I made the changes in my code,tried sending messages ..My code doesn't call toadmin and from admin ,its just calling toapp ...is it necessary to send a logon msgtype=A before sending a application message (here I am trying to send msgtype=AP).Also how do I know whether my messages are successfully sent.
"If the logon is successful ,it begins to heartbeat "how do I know this ?By tag number in logs file?
yes those sound l like heartbeats... What you need to do is get the FIX rules of engagement from your counterparty and start requesting different types of messages from them...
Thank you so much rupweb.I have gone through Rules of engagement. Could you please tell me is the FIX engine required to install on client side code.here I am using just inniator code ..and the code is written using Quickfixj.Also I came across an article about FIX its says when there is a successful logon to the acceptor you will be receiving heartbeats from the counterparty as well ..I don't see this happening in my case ..this I have verified the logs its just sending the messages for AP type from the client side ..am I missing something.
If you are a client then you need to connect to a provider FIX engine and the quickfix library is a good way of doing that. For your implementations of the quickfix library interface put System.out.println("in xxx"); code in your implementations of each interface method where xxx is the method name. Finally, if the logs show repeated AP messages it sounds like you're not connecting to your provider. You do not need that sendLogonRequest method, just to implement the quickfix interface, it will connect automatically depending on your configuration file...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.