Exemplo n.º 1
0
 public void TestRicToTicker()
 {
     Assert.AreEqual("IBM", EquityTickerUtil.ConvertRicToTicker("IBM.N"));
     Assert.AreEqual("MSFT", EquityTickerUtil.ConvertRicToTicker("MSFT.O"));
     Assert.AreEqual("XLP", EquityTickerUtil.ConvertRicToTicker("XLP.P"));
     Assert.AreEqual("F", EquityTickerUtil.ConvertRicToTicker("F.N"));
     Assert.AreEqual("C", EquityTickerUtil.ConvertRicToTicker("C.N"));
 }
Exemplo n.º 2
0
        public void TestOrderXmlToOrders()
        {
            var fullFileContents = LoadTestOrders();

            // do the test
            var orders = MessageUtil.ParseXmlToDictionary(fullFileContents, 1);

            Assert.IsNotNull(orders);
            Assert.AreEqual(5, orders.Count);

            var equityOrder = orders[0];

            Assert.IsTrue(MessageUtil.IsEquityOrder(equityOrder));

            VerifyAllFields(orders);
            equityOrder["BID"] = EquityTickerUtil.ConvertRicToTicker(equityOrder["RIC"]);

            var tradeRecord = MessageUtil.CreateTradeRecord(equityOrder);

            Assert.IsNotNull(tradeRecord);
            Assert.AreEqual("MSFT", tradeRecord["BID"]);
        }
        /// <summary>
        /// Event handler for order creation and/or update.
        /// </summary>
        /// <param name="orderId">the order id or multiple if more than one order is received.</param>
        /// <param name="xmlOrders"></param>
        /// <param name="uniqueId"></param>
        /// <param name="confirmed"></param>
        public void ReceiveOrders(string orderId, string xmlOrders, int uniqueId, ref bool confirmed)
        {
            // extract the orders, translate symbols, and update the cache
            var positionsToPublish = new List <IDictionary <string, string> >();

            lock (_orderEventIds) {
                try {
                    if (_orderEventIds.Contains(uniqueId))
                    {
                        return;
                    }
                    var orders = MessageUtil.ParseXmlToDictionary(xmlOrders, uniqueId);
                    foreach (var order in orders)
                    {
                        // convert order into a trade record
                        if (MessageUtil.IsEquityOrder(order))
                        {
                            var ticker = EquityTickerUtil.ConvertRicToTicker(order["RIC"]);
                            order["BID"] = ticker;
                        }
                        else if (MessageUtil.IsFuturesOrder(order))
                        {
                            var failedRicLookup = false;
                            var ric             = order["RIC"];
                            var ricRoot         = FuturesSymbolUtil.ExtractSymbolRoot(ric);
                            var bbRoot          = _fsm.ConvertRicRoot(ricRoot);
                            if (string.IsNullOrEmpty(bbRoot))
                            {
                                _log.Warn("No mapping for RIC root: " + ricRoot);
                                bbRoot           = ricRoot;
                                order["WARNING"] = "No mapping for RIC root";
                                failedRicLookup  = true;
                            }
                            var monthYear = FuturesSymbolUtil.ExtractMaturityMonthFromSymbol(order["RIC"]);
                            var bbSymbol  = FuturesSymbolUtil.CombineRootMaturityMonthYear(bbRoot, monthYear);
                            if (failedRicLookup)
                            {
                                bbSymbol = bbSymbol + " - using RIC";
                            }
                            order["BID"] = bbSymbol;
                        }
                        else
                        {
                            continue;
                        }

                        var tradeRecord     = MessageUtil.CreateTradeRecord(order);
                        var updatedPosition = _positionCache.Update(tradeRecord);
                        positionsToPublish.Add(updatedPosition);
                    }
                    _orderEventIds.Add(uniqueId);
                    confirmed = true;
                } catch (Exception e) {
                    _log.Error("Processing order events from TradingScreen", e);
                }
            }
            try {
                foreach (var position in positionsToPublish)
                {
                    position.Add("Source", "TradingScreen");
                    var strategy = position["Strategy"];
                    if (string.IsNullOrEmpty(strategy))
                    {
                        strategy = "MISSING";
                    }
                    var sb = new StringBuilder(512);
                    sb.Append("TradingScreen.Positions.").Append(strategy).Append(".").Append(position["BID"]);

                    _broker.Publish(sb.ToString(), position);
                }
            } catch (Exception e) {
                _log.Error("Publishing positions from TradingScreen", e);
            }
        }