public void ConnectToQuotes() { string addrStr = "216.52.236.111"; ushort port = 5020; string userName = "******"; string password = "******"; // string userName = "******"; // string password = "******"; using (Socket socket = Factory.Provider.Socket("TestSocket", addrStr, port)) { socket.MessageFactory = new MessageFactoryMbtQuotes(); socket.SetBlocking(true); socket.Connect(); socket.SetBlocking(false); Message message = socket.MessageFactory.Create(); string hashPassword = MBTQuotesProvider.Hash(password); string login = "******" + userName + ";133=" + hashPassword + "\n"; message.DataOut.Write(login.ToCharArray()); while (!socket.TrySendMessage(message)) { Factory.Parallel.Yield(); } while (!socket.TryGetMessage(out message)) { Factory.Parallel.Yield(); } string response = new string(message.DataIn.ReadChars(message.Remaining)); string expectedResponse = "G|100=DEMOYZPS;8055=demo01\n"; socket.MessageFactory.Release(message); Assert.AreEqual(expectedResponse, response); } }
public unsafe void ConnectToFIXFails() { string addrStr = "216.52.236.112"; ushort port = 5679; string password = "******"; string userName = "******"; using (Selector selector = Factory.Provider.Selector(OnException)) using (Socket socket = Factory.Provider.Socket("TestSocket")) { socket.PacketFactory = new PacketFactoryFIX4_4(); selector.Start(); selector.OnDisconnect = OnDisconnect; socket.SetBlocking(true); socket.Connect(addrStr, port); socket.SetBlocking(false); selector.AddReader(socket); selector.AddWriter(socket); Packet packet = socket.CreatePacket(); string hashPassword = MBTQuotesProvider.Hash(password); var fixFactory = new FIXFactory4_4(1, userName, destination); var mbtMsg = (FIXMessage4_4)fixFactory.Create(); mbtMsg.SetEncryption(0); mbtMsg.SetHeartBeatInterval(30); mbtMsg.ResetSequence(); mbtMsg.SetEncoding("554_H1"); mbtMsg.SetPassword(password); mbtMsg.AddHeader("A"); string login = mbtMsg.ToString(); packet.DataOut.Write(login.ToCharArray()); log.Info("Login message: \n" + packet); while (!socket.TrySendPacket(packet)) { Factory.Parallel.Yield(); } long end = Factory.Parallel.TickCount + 5000; while (!socket.TryGetPacket(out packet)) { if (Factory.Parallel.TickCount > end) { // If it times out here. Then return with success // for the test. return; } Factory.Parallel.Yield(); } Assert.Fail("Should have received login timed out response."); } }
public void ConnectToQuotes() { string addrStr = "216.52.236.111"; ushort port = 5020; string userName = "******"; string password = "******"; // string userName = "******"; // string password = "******"; using (Selector selector = Factory.Provider.Selector(OnException)) using (Socket socket = Factory.Provider.Socket("TestSocket")) { socket.PacketFactory = new PacketFactoryMBTQuotes(); selector.Start(); socket.SetBlocking(true); socket.Connect(addrStr, port); socket.SetBlocking(false); selector.AddReader(socket); selector.AddWriter(socket); Packet packet = socket.CreatePacket(); string hashPassword = MBTQuotesProvider.Hash(password); string login = "******" + userName + ";133=" + hashPassword + "\n"; packet.DataOut.Write(login.ToCharArray()); while (!socket.TrySendPacket(packet)) { Factory.Parallel.Yield(); } while (!socket.TryGetPacket(out packet)) { Factory.Parallel.Yield(); } string response = new string(packet.DataIn.ReadChars(packet.Remaining)); string expectedResponse = "G|100=DEMOYZPS;8055=demo01\n"; Assert.AreEqual(expectedResponse, response); } }
public unsafe void ConnectToFIX() { string addrStr = "216.52.236.112"; ushort port = 5679; // Forex // string password = "******"; // string userName = "******"; // Equity string password = "******"; string userName = "******"; using (var filter = new FIXPretradeFilter(addrStr, port)) using (Socket socket = Factory.Provider.Socket("TestSocket", "127.0.0.1", filter.LocalPort)) { socket.MessageFactory = new MessageFactoryFix44(); socket.SetBlocking(true); socket.Connect(); socket.SetBlocking(false); Message message = socket.MessageFactory.Create(); string hashPassword = MBTQuotesProvider.Hash(password); var fixFactory = new FIXFactory4_4(1, userName, destination); var mbtMsg = (FIXMessage4_4)fixFactory.Create(); mbtMsg.SetEncryption(0); mbtMsg.SetHeartBeatInterval(30); mbtMsg.ResetSequence(); mbtMsg.SetEncoding("554_H1"); mbtMsg.SetPassword(password); mbtMsg.AddHeader("A"); string login = mbtMsg.ToString(); message.DataOut.Write(login.ToCharArray()); log.Info("Login message: \n" + message); while (!socket.TrySendMessage(message)) { Factory.Parallel.Yield(); } long end = Factory.Parallel.TickCount + 5000; while (!socket.TryGetMessage(out message)) { if (Factory.Parallel.TickCount > end) { Assert.Fail("Login Timed Out."); } Factory.Parallel.Yield(); } MessageFIX4_4 packetFIX = (MessageFIX4_4)message; // packetFIX.ReadMessage(); Assert.AreEqual("FIX.4.4", packetFIX.Version); Assert.AreEqual("A", packetFIX.MessageType); Assert.AreEqual("MBT", packetFIX.Sender); Assert.AreEqual(userName, packetFIX.Target); Assert.AreEqual(1, packetFIX.Sequence); Assert.NotNull(packetFIX.TimeStamp); Assert.AreEqual("0", packetFIX.Encryption); Assert.AreEqual(30, packetFIX.HeartBeatInterval); socket.MessageFactory.Release(message); } }
public MBTProvider(string configName) { fixProvider = new MBTFIXProvider(configName); quotesProvider = new MBTQuotesProvider(configName); }