public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerHost = d_serverHost; sessionOptions.ServerPort = d_serverPort; sessionOptions.AuthenticationOptions = d_authOptions; System.Console.WriteLine("Connecting to " + d_serverHost + ":" + d_serverPort); ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent); if (!session.Start()) { Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions.Length != 0) { if (!Authorize(out identity, session)) { return; } } TopicList topicList = new TopicList(); topicList.Add( d_serviceName + "/220/660/1", new CorrelationID(new MyStream("220/660/1"))); session.CreateTopics( topicList, ResolveMode.AUTO_REGISTER_SERVICES, identity); List <MyStream> myStreams = new List <MyStream>(); for (int i = 0; i < topicList.Size; ++i) { if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED) { Topic topic = session.GetTopic(topicList.MessageAt(i)); MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object; stream.SetTopic(topic); myStreams.Add(stream); } } PublishEvents(session, myStreams); session.Stop(); }
private void Publish(TopicList topicList, ProviderSession session) { List <MyStream> myStreams = new List <MyStream>(); for (int i = 0; i < topicList.Size; ++i) { if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED) { Message message = topicList.MessageAt(i); Topic topic = session.GetTopic(message); MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object; stream.setTopic(topic); myStreams.Add(stream); Console.WriteLine("Topic created: " + stream.getId()); } } Service pubService = session.GetService(d_service); if (pubService == null) { Console.Error.WriteLine("service unavailable"); return; } // Now we will start publishing Event eventObj = pubService.CreatePublishEvent(); EventFormatter eventFormatter = new EventFormatter(eventObj); for (int index = 0; index < myStreams.Count; index++) { MyStream stream = (MyStream)myStreams[index]; eventFormatter.AppendRecapMessage(stream.getTopic(), null); eventFormatter.SetElement("numRows", 25); eventFormatter.SetElement("numCols", 80); eventFormatter.PushElement("rowUpdate"); for (int i = 1; i <= 5; ++i) { eventFormatter.AppendElement(); eventFormatter.SetElement("rowNum", i); eventFormatter.PushElement("spanUpdate"); eventFormatter.AppendElement(); eventFormatter.SetElement("startCol", 1); eventFormatter.SetElement("length", 10); eventFormatter.SetElement("text", "INITIAL"); eventFormatter.SetElement("fgColor", "RED"); eventFormatter.PushElement("attr"); eventFormatter.AppendValue("UNDERLINE"); eventFormatter.AppendValue("BLINK"); eventFormatter.PopElement(); eventFormatter.PopElement(); eventFormatter.PopElement(); eventFormatter.PopElement(); } eventFormatter.PopElement(); } if (d_verbose > 0) { PrintMessage(eventObj); } session.Publish(eventObj); while (d_running) { eventObj = pubService.CreatePublishEvent(); eventFormatter = new EventFormatter(eventObj); for (int index = 0; index < myStreams.Count; index++) { MyStream stream = (MyStream)myStreams[index]; eventFormatter.AppendMessage("RowUpdate", stream.getTopic()); eventFormatter.SetElement("rowNum", 1); eventFormatter.PushElement("spanUpdate"); eventFormatter.AppendElement(); eventFormatter.SetElement("startCol", 1); String text = System.DateTime.Now.ToString(); eventFormatter.SetElement("length", text.Length); eventFormatter.SetElement("text", text); eventFormatter.PopElement(); eventFormatter.AppendElement(); eventFormatter.SetElement("startCol", text.Length + 10); text = System.DateTime.Now.ToString(); eventFormatter.SetElement("length", text.Length); eventFormatter.SetElement("text", text); eventFormatter.PopElement(); eventFormatter.PopElement(); } if (d_verbose > 0) { PrintMessage(eventObj); } session.Publish(eventObj); Thread.Sleep(10 * 1000); } }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_serverHosts.Count]; for (int i = 0; i < d_serverHosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_serverHosts[i], d_serverPort); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = d_serverHosts.Count; System.Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { System.Console.Write(" " + server); } System.Console.WriteLine(); ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent); if (!session.Start()) { Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions != null) { bool isAuthorized = false; identity = session.CreateIdentity(); if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); if (Authorize(authService, identity, session, new CorrelationID())) { isAuthorized = true; } } if (!isAuthorized) { System.Console.Error.WriteLine("No authorization"); return; } } TopicList topicList = new TopicList(); topicList.Add( d_serviceName + "/" + d_topic, new CorrelationID(new MyStream(d_topic))); session.CreateTopics( topicList, ResolveMode.AUTO_REGISTER_SERVICES, identity); List <MyStream> myStreams = new List <MyStream>(); for (int i = 0; i < topicList.Size; ++i) { if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED) { Topic topic = session.GetTopic(topicList.MessageAt(i)); MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object; stream.SetTopic(topic); myStreams.Add(stream); } } PublishEvents(session, myStreams); session.Stop(); }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_serverHosts.Count]; for (int i = 0; i < d_serverHosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_serverHosts[i], d_serverPort); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = d_serverHosts.Count; System.Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { System.Console.Write(" " + server); } System.Console.WriteLine(); ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent); if (!session.Start()) { Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions != null) { bool isAuthorized = false; identity = session.CreateIdentity(); if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); if (Authorize(authService, identity, session, new CorrelationID())) { isAuthorized = true; } } if (!isAuthorized) { System.Console.Error.WriteLine("No authorization"); return; } } TopicList topicList = new TopicList(); topicList.Add( d_serviceName + "/ticker/929903DF6 Corp", new CorrelationID(new MyStream("AUDEUR Curncy"))); topicList.Add( d_serviceName + "/ticker/EC070336 Corp", new CorrelationID(new MyStream("EC070336 Corp"))); topicList.Add( d_serviceName + "/ticker/6832348A9 Corp", new CorrelationID(new MyStream("6832348A9 Corp"))); session.CreateTopics( topicList, ResolveMode.AUTO_REGISTER_SERVICES, identity); Service service = session.GetService(d_serviceName); if (service == null) { System.Console.Error.WriteLine("Open service failed: " + d_serviceName); return; } List <MyStream> myStreams = new List <MyStream>(); for (int i = 0; i < topicList.Size; ++i) { if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED) { Topic topic = session.GetTopic(topicList.MessageAt(i)); MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object; stream.SetTopic(topic); myStreams.Add(stream); } } int iteration = 0; while (iteration++ < d_maxEvents) { if (!d_running) { break; } Event eventObj = service.CreatePublishEvent(); EventFormatter eventFormatter = new EventFormatter(eventObj); foreach (MyStream stream in myStreams) { eventFormatter.AppendMessage("MarketData", stream.GetTopic()); eventFormatter.SetElement(BID, stream.GetBid()); eventFormatter.SetElement(ASK, stream.GetAsk()); eventFormatter.SetElement(BID_SIZE, 1200); eventFormatter.SetElement(ASK_SIZE, 1400); } System.Console.WriteLine(System.DateTime.Now.ToString() + " -"); foreach (Message msg in eventObj) { System.Console.WriteLine(msg); } session.Publish(eventObj); Thread.Sleep(10 * 1000); } session.Stop(); }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = servers.Length; System.Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { System.Console.Write(" " + server); } System.Console.WriteLine(); ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent); if (!session.Start()) { System.Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions != null) { if (!Authorize(out identity, session)) { return; } } if (d_groupId != null) { // NOTE: will perform explicit service registration here, instead of letting // createTopics do it, as the latter approach doesn't allow for custom // ServiceRegistrationOptions ServiceRegistrationOptions serviceRegistrationOptions = new ServiceRegistrationOptions(); serviceRegistrationOptions.GroupId = d_groupId; serviceRegistrationOptions.ServicePriority = d_priority; if (!session.RegisterService(d_service, identity, serviceRegistrationOptions)) { System.Console.Write("Failed to register " + d_service); return; } } TopicList topicList = new TopicList(); for (int i = 0; i < d_topics.Count; i++) { topicList.Add( d_service + "/" + d_topics[i], new CorrelationID(new MyStream(d_topics[i]))); } session.CreateTopics( topicList, ResolveMode.AUTO_REGISTER_SERVICES, identity); // createTopics() is synchronous, topicList will be updated // with the results of topic creation (resolution will happen // under the covers) List <MyStream> myStreams = new List <MyStream>(); for (int i = 0; i < topicList.Size; ++i) { MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object; if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED) { Message msg = topicList.MessageAt(i); stream.setTopic(session.GetTopic(msg)); myStreams.Add(stream); System.Console.WriteLine("Topic created: " + topicList.TopicStringAt(i)); } else { System.Console.WriteLine("Stream '" + stream.getId() + "': topic not resolved, status = " + topicList.StatusAt(i)); } } Service service = session.GetService(d_service); // Now we will start publishing Name eventName = Name.GetName("MarketDataEvents"); Name high = Name.GetName("HIGH"); Name low = Name.GetName("LOW"); long tickCount = 1; for (int eventCount = 0; eventCount < d_maxEvents; ++eventCount) { Event eventObj = service.CreatePublishEvent(); EventFormatter eventFormatter = new EventFormatter(eventObj); for (int index = 0; index < myStreams.Count; index++) { Topic topic = myStreams[index].getTopic(); if (!topic.IsActive()) { continue; } eventFormatter.AppendMessage(eventName, topic); if (1 == tickCount) { eventFormatter.SetElement("OPEN", 1.0); } else if (2 == tickCount) { eventFormatter.SetElement("BEST_BID", 3.0); } eventFormatter.SetElement(high, tickCount * 1.0); eventFormatter.SetElement(low, tickCount * 0.5); ++tickCount; } foreach (Message msg in eventObj) { System.Console.WriteLine(msg); } session.Publish(eventObj); Thread.Sleep(2 * 1000); } session.Stop(); }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerHost = d_serverHost; sessionOptions.ServerPort = d_serverPort; sessionOptions.AuthenticationOptions = d_authOptions; System.Console.WriteLine("Connecting to " + d_serverHost + ":" + d_serverPort); ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent); if (!session.Start()) { Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions.Length != 0) { if (!Authorize(out identity, session)) { return; } } TopicList topicList = new TopicList(); topicList.Add( d_serviceName + "/ticker/929903DF6 Corp", new CorrelationID(new MyStream("AUDEUR Curncy"))); topicList.Add( d_serviceName + "/ticker/EC070336 Corp", new CorrelationID(new MyStream("EC070336 Corp"))); topicList.Add( d_serviceName + "/ticker/6832348A9 Corp", new CorrelationID(new MyStream("6832348A9 Corp"))); session.CreateTopics( topicList, ResolveMode.AUTO_REGISTER_SERVICES, identity); Service service = session.GetService(d_serviceName); if (service == null) { System.Console.Error.WriteLine("Open service failed: " + d_serviceName); return; } List <MyStream> myStreams = new List <MyStream>(); for (int i = 0; i < topicList.Size; ++i) { if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED) { Topic topic = session.GetTopic(topicList.MessageAt(i)); MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object; stream.SetTopic(topic); myStreams.Add(stream); } } int iteration = 0; while (iteration++ < d_maxEvents) { Event eventObj = service.CreatePublishEvent(); EventFormatter eventFormatter = new EventFormatter(eventObj); foreach (MyStream stream in myStreams) { eventFormatter.AppendMessage("MarketData", stream.GetTopic()); eventFormatter.SetElement(BID, stream.GetBid()); eventFormatter.SetElement(ASK, stream.GetAsk()); eventFormatter.SetElement(BID_SIZE, 1200); eventFormatter.SetElement(ASK_SIZE, 1400); } System.Console.WriteLine(System.DateTime.Now.ToString() + " -"); foreach (Message msg in eventObj) { System.Console.WriteLine(msg); } session.Publish(eventObj); Thread.Sleep(10 * 1000); } session.Stop(); }