/// <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); } }
/// <summary> /// We have been added to a spreadsheet cell. /// </summary> /// <param name="topicID"></param> /// <param name="parameters"> /// We are only expecting one (1) parameter, the ClientOrderID. /// </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 clientOrderID = (parameters.GetValue(0)).ToString().ToUpper(); lock (orderToTopicMapping) { orderToTopicMapping[clientOrderID] = topicID; } var order = nmsClient.GetOrderByClientOrderID(clientOrderID); return(order != null ? order.Status : "Unknown order"); } catch (Exception e) { Console.WriteLine(e); return("#Error looking up order status:" + e.Message); } }