简体   繁体   English

无法在QuickFIXn中发送消息

[英]Fail to send a message in QuickFIXn

I'm trying to create a simple QuickFix and i get trouble in sending message. 我试图创建一个简单的QuickFix,但在发送消息时遇到麻烦。

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: 这是我的配置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: 这些是“ toAdmin”方法的结果:

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 这是我的配置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: 这些是“ toAdmin”方法的结果:

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. 我不知道为什么x在这里是假的。

Where's your SocketAcceptAddress in your acceptor config file? 您的接受器配置文件中的SocketAcceptAddress在哪里? And instead of using "localhost" it may need to be 127.0.0.1 而不是使用“ localhost”,它可能需要是127.0.0.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM