我正在尝试创建一个简单的 QuickFix,但在发送消息时遇到了麻烦。
这是我的服务器代码:
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);
}
这是我的配置 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
这些是“toAdmin”方法的结果:
message: {8=FIX.4.19=4535=534=149=ARCA52=20150915-07:02:3756=TW10=213}
sessionId: {FIX.4.1:ARCA->TW}
这是我的客户代码:
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();
}
这是我的配置 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
这些是“toAdmin”方法的结果:
message: {8=FIX.4.19=4535=534=249=TW52=20150915-07:04:4356=ARCA10=213}
sessionId: {FIX.4.1:TW->ARCA}
我通过调用发送消息:
bool x = Session.sendToTarget(order, sessionID); //x is false
任何人都可以帮忙吗?我不知道为什么 x 在这里是假的。