anhtv13
anhtv13

Reputation: 1808

Fail to send a message in QuickFIXn

I'm trying to create a simple QuickFix and i get trouble in sending message.

Here is my Server code:

static void Main(string[] args)
{
    try
    {
        SessionSettings settings = new SessionSettings(@"C:\Users\anhtv\Desktop\QuickFix\QuickFix\server.cfg");
        FixServerApplication application = new FixServerApplication();
        FileStoreFactory storeFactory = new FileStoreFactory(settings);
        ScreenLogFactory logFactory = new ScreenLogFactory(settings);
        MessageFactory messageFactory = new DefaultMessageFactory();
        SocketAcceptor acceptor = new SocketAcceptor(application, storeFactory, settings, logFactory, messageFactory);

        acceptor.start();
        Console.WriteLine("press <enter> to quit");
        Console.Read();
        acceptor.stop();
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
    }

This is my config server.cfg:

# default settings for sessions
[DEFAULT]
FileStorePath=c:\fixfiles
FileLogPath=log
ConnectionType=acceptor
ReconnectInterval=60
SenderCompID=ARCA
SocketAcceptPort=9823
SocketReuseAddress=Y

# session definition
[SESSION]
BeginString=FIX.4.2
TargetCompID=TW
StartTime=12:30:00
EndTime=23:30:00
HeartBtInt=20
DataDictionary=C:\Users\anhtv\Desktop\QuickFix\QuickFix\fix\FIX42.xml

These are result in "toAdmin" method:

message: {8=FIX.4.19=4535=534=149=ARCA52=20150915-07:02:3756=TW10=213}
sessionId: {FIX.4.1:ARCA->TW}

Here is my Client code:

static void Main()
{
    SessionSettings settings = new SessionSettings(@"C:\Users\anhtv\Desktop\QuickFix\QuickFix\client.cfg");
    QuickFix.Application application = new ClientInitiator();
    FileStoreFactory storeFactory = new FileStoreFactory(settings);
    ScreenLogFactory logFactory = new ScreenLogFactory(settings);
    MessageFactory messageFactory = new DefaultMessageFactory();

    SocketInitiator initiator = new SocketInitiator(application, storeFactory, settings, logFactory, messageFactory);
    initiator.start();

    System.Collections.ArrayList list = initiator.getSessions();

    SessionID sessionID = (SessionID)list[0];

    QuickFix42.NewOrderSingle order = new QuickFix42.NewOrderSingle(new ClOrdID("DLF"), new HandlInst(HandlInst.MANUAL_ORDER), new Symbol("DLF"), new Side(Side.BUY), new TransactTime(DateTime.Now), new OrdType(OrdType.LIMIT));
    order.set(new OrderQty(45));
    order.set(new Price(25.4d));
    Console.WriteLine("Sending Order to Server");
    bool x = Session.sendToTarget(order, sessionID);// x is false

    Console.ReadLine();
    initiator.stop();
}

This is my config client.cfg

# default settings for sessions
[DEFAULT]
FileStorePath=c:\fixfiles
FileLogPath=log
ConnectionType=initiator
ReconnectInterval=60
SenderCompID=TW
SocketConnectHost=localhost

# session definition
[SESSION]
BeginString=FIX.4.2
TargetCompID=ARCA
StartTime=12:30:00
EndTime=23:30:00
HeartBtInt=20
SocketConnectPort=9823
DataDictionary=C:\Users\anhtv\Desktop\QuickFix\QuickFix\fix\FIX42.xml

These are result in "toAdmin" method:

message: {8=FIX.4.19=4535=534=249=TW52=20150915-07:04:4356=ARCA10=213}
sessionId: {FIX.4.1:TW->ARCA}

And I send message by calling:

bool x = Session.sendToTarget(order, sessionID); //x is false

Anyone can help please? I dont know why x is false here.

Upvotes: 1

Views: 642

Answers (1)

rupweb
rupweb

Reputation: 3328

Where's your SocketAcceptAddress in your acceptor config file? And instead of using "localhost" it may need to be 127.0.0.1

Upvotes: 2

Related Questions