public void TestSendOrder() { var nmsClient = new NmsClientApp("TestClient"); nmsClient.Configure(BrokerUrl, FerCommandQueue); nmsClient.Start(); WaitFor(Connected, nmsClient, 10000); Assert.IsTrue(nmsClient.Connected(), "Failed to connect"); var order = CreateLimitOrder(); var messageId = nmsClient.SendOrder(order); Assert.IsNotNull(messageId, "Failed to send order"); Console.WriteLine("Sent message:" + messageId); // simulate the server processing ProcessTestOrder(); WaitFor(Response, nmsClient, 3000); Assert.GreaterOrEqual(nmsClient.OrderCacheCount, 1, "Failed to receive response"); var response = nmsClient.GetResponseFor(messageId); Assert.IsNotNull(response, "Did not receive response for order " + messageId); var sentOrder = nmsClient.GetOrderByKey(order.CacheKey); Assert.IsNotNull(sentOrder, "Failed to lookup order by clientOrderID"); Assert.AreNotSame("NEW", sentOrder.Status, "Status not updated to non NEW"); nmsClient.Stop(); Assert.IsFalse(nmsClient.Connected(), "Failed to disconnect"); }
public void TestSendOrderIntegration() { var nmsClient = new NmsClientApp("TestClient"); nmsClient.Configure(BrokerUrl, FerCommandQueue); nmsClient.Start(); WaitFor(Connected, nmsClient, 10000); Assert.IsTrue(nmsClient.Connected(), "Failed to connect"); var order = CreateLimitOrder(); // Since this is an integration test, change platform to 'TEST' order.platform = "TEST"; order.strategy = "TEST-EQUITY-STRATEGY"; Console.WriteLine("Created order " + order.CacheKey); var messageId = nmsClient.SendOrder(order); Assert.IsNotNull(messageId, "Failed to send order"); Console.WriteLine("Sent message:" + messageId); WaitFor(Response, nmsClient, 3000); Assert.GreaterOrEqual(nmsClient.OrderCacheCount, 1, "Failed to receive response"); Thread.Sleep(1000); var response = nmsClient.GetResponseFor(messageId); Assert.IsNotNull(response, "Did not receive response for order " + messageId); Assert.IsFalse(response.ContainsKey("ERROR_1"), "Error with order:" + GetValueForKey("ERROR_1", response)); nmsClient.Stop(); Assert.IsFalse(nmsClient.Connected(), "Failed to disconnect"); }
public void TestStartStop() { var nmsClient = new NmsClientApp("TestClient"); nmsClient.Configure(BrokerUrl, FerCommandQueue); nmsClient.Start(); WaitFor(Connected, nmsClient, 10000); Assert.IsTrue(nmsClient.Connected(), "Failed to connect"); nmsClient.Stop(); Assert.IsFalse(nmsClient.Connected(), "Failed to disconnect"); }
/// <summary> /// Publish an order that is represented by a string of key/value pairs. /// </summary> /// <param name="orderString"></param> /// <returns></returns> public object Pub(string orderString) { // We are public API called from Excel, ensure we catch all exceptions try { // turn the string into an order so that we can do some validation on it. var orderFields = MessageUtil.ExtractRecord(orderString); var order = new Order(orderFields); if (order.ModifiedClientID) { return("#Error: ClientOrderID does not meet requirements. Must be 16 or less, without spaces and %"); } if (nmsClient.Connected()) { var cachedOrder = nmsClient.GetOrderByClientOrderID(order.ClientOrderID); if (cachedOrder != null && cachedOrder.Status != "INVALID") { return("#Error - order already sent '" + order.ClientOrderID + "'"); } var nmsMessageID = nmsClient.SendOrder(order); } else { return("#Warn: Not connected to broker, try again"); } return("Published " + GenerateExcelTimestamp()); } catch (Exception e) { Console.WriteLine(e); return("#Error: Unable to Publish: " + e.Message); } }
public OrderPublisherAddin() { nmsClient = NmsClientFactory.GetClientFor(Configuration.BrokerUrl); if (!nmsClient.Connected()) { // Sleep to give the connection time to startup Thread.Sleep(500); } }
/// <summary> /// We have been added to a spreadsheet cell. /// </summary> /// <param name="topicID"></param> /// <param name="parameters"> /// We are expecting one (1) parameter that represents the UserOrderID and OrderDate /// </param> /// <param name="getNewValues"></param> /// <returns></returns> object IRtdServer.ConnectData(int topicID, ref Array parameters, ref bool getNewValues) { try { getNewValues = true; // over-write any saved values in the spreadsheet var queryStr = (parameters.GetValue(0)).ToString(); var queryParts = MessageUtil.ExtractRecord(queryStr); var queryOrder = new Order(queryParts); if (!queryOrder.CanCalculateCompositOrderId) { return("#Error: UserOrderId/OrderDate do not meet requirements"); } lock (nmsClient) { var cacheKey = queryOrder.CacheKey; orderToTopicMapping[cacheKey] = topicID; var order = nmsClient.GetOrderByKey(cacheKey); if (order == null) { // Give us a chance to connect, but don't waste too much time if (!nmsClient.Connected()) { Thread.Sleep(1000); } if (nmsClient.Connected()) { // query the system for the order nmsClient.QueryOrder(queryOrder.userOrderId, (DateTime)queryOrder.orderDate); return("Unknown order - sent query"); } return("#Warn: Not connected to broker, try again"); } return(GetErrorOrStatus(order)); } } catch (Exception e) { //log.Error(e); return("#Error looking up order status:" + e.Message); } }
public OrderPublisherAddin(AppConfiguration config) { _config = config; _nmsClient = NmsClientFactory.GetClientFor(_config.BrokerUrl); if (!_nmsClient.Connected()) { // Sleep to give the connection time to startup Thread.Sleep(500); } }
public void TestSessionReconnect() { var nmsClient = new NmsClientApp("TestClient"); nmsClient.Configure(BrokerUrl, FerCommandQueue); nmsClient.Start(); WaitFor(Connected, nmsClient, 10000); Assert.IsTrue(nmsClient.Connected(), "Failed to connect"); Console.WriteLine("Killing the broker NOW!"); StopActiveMQBroker(); StartActiveMQBroker(); // sleep for a minute so we have time to kill the broker Thread.Sleep(1000); Console.WriteLine("Going to reconnect, the broker better be up!"); WaitFor(Connected, nmsClient, 1000); Assert.IsTrue(nmsClient.Connected(), "Failed to connect"); }
int IRtdServer.Heartbeat() { try { if (lastHeartbeat != 1 && !nmsClient.Connected()) { return(lastHeartbeat); } if (lastHeartbeat == 1 && !nmsClient.Connected()) { // We will wait for two bad heart beats to restart lastHeartbeat = -1; return(1); } // we are working find, reset the heartbeat value lastHeartbeat = 1; } catch (Exception e) { Console.WriteLine(e); // don't know what happened, but should restart lastHeartbeat = -1; } return(lastHeartbeat); }
/// <summary> /// Startup the RTD server to listen to the Broker. /// </summary> /// <param name="callbackObject"></param> /// <returns></returns> int IRtdServer.ServerStart(IRTDUpdateEvent callbackObject) { try { xlRTDUpdateCallbackHandler = callbackObject; nmsClient = NmsClientFactory.Instance.getClientFor(Configuration.BrokerUrl); if (!nmsClient.Connected()) { // Sleep to give the connection time to startup Thread.Sleep(500); } nmsClient.UpdatedOrder += ReceivedOrder; lastHeartbeat = 1; return(1); } catch (Exception e) { Console.WriteLine(e); return(-1); } }
// static OrderSubscriberRtd() { // var configurationFileName = System.Reflection.Assembly.GetExecutingAssembly().Location + ".config"; // log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(configurationFileName)); // } #region RTD /// <summary> /// Startup the RTD server to listen to the Broker. /// </summary> /// <param name="callbackObject"></param> /// <returns></returns> public int ServerStart(IRTDUpdateEvent callbackObject) { try { _xlRtdUpdateCallbackHandler = callbackObject; _nmsClient = NmsClientFactory.GetClientFor(_config.BrokerUrl); if (!_nmsClient.Connected()) { _nmsClient.Start(); // Sleep to give the connection time to startup Thread.Sleep(500); } _nmsClient.UpdatedOrder += ReceivedOrder; _lastHeartbeat = 1; return(1); } catch (Exception e) { _log.Error(e); return(-1); } }
private object Pub(string orderString, string messageType) { // We are public (well, we are common code to the public API) API called from Excel, ensure we catch all exceptions try { log.Info(orderString); // turn the string into an order so that we can do some validation on it. var orderFields = MessageUtil.ExtractRecord(orderString, true); if (orderFields.Count == 0) { return("#Warn: did not receive a proper order string. " + orderString); } // To work with Bloomberg EMSX we require the OrderDate and UserOrderId // ClientOrderId is nolonger valid if (orderFields.ContainsKey("CLIENTORDERID")) { return("#Error: Specify UserOrderId and OrderDate instead of ClientOrderId"); } var order = new Order(orderFields); if (order.ModifiedUserOrderId) { return("#Error: UserOrderID does not meet requirements. Must be 6 or less, without spaces and %"); } if (!order.CanCalculateCompositOrderId) { return("#Error: Missing OrderDate"); } lock (nmsClient) { if (nmsClient.Connected()) { var cachedOrder = nmsClient.GetOrderByKey(order.CacheKey); // what kind of order are we? switch (messageType) { case "NEW": if (cachedOrder != null && cachedOrder.Status != "INVALID" && cachedOrder.Status != "UNKNOWN") { return("#Error - order already sent '" + order.CacheKey + "'"); } nmsClient.SendOrder(order); break; case "CANCEL": nmsClient.SendCancel(order); break; case "REPLACE": order.FixMessageType = "G"; nmsClient.SendReplace(order); break; default: return("#Error: Unable to determine type of message to send. '" + messageType + "'"); } log.Info("Sent order:" + order.ToSting()); } else { nmsClient.Start(); return("#Warn: Not connected to broker, try again"); } } return("Published " + GenerateExcelTimestamp()); } catch (Exception e) { Console.WriteLine("Unable to publish" + e.Message); return("#Error: Unable to Publish: " + e.Message); } }