Ejemplo n.º 1
0
        public void TestExtractMaturityMonthYear()
        {
            // Test everything that we might get
            const string mmy = "200906";

            var mmy1 = FuturesSymbolUtil.ExtractMaturityMonthFromSymbol("TYM9");

            Assert.AreEqual(mmy, mmy1);

            var mmy2 = FuturesSymbolUtil.ExtractMaturityMonthFromSymbol("P M9");

            Assert.AreEqual(mmy, mmy2);

            // do some RIC parsing
            var mmy3 = FuturesSymbolUtil.ExtractMaturityMonthFromSymbol("TTAH0");

            Assert.AreEqual("201003", mmy3);

            var mmy4 = FuturesSymbolUtil.ExtractMaturityMonthFromSymbol("6BH0");

            Assert.AreEqual("201003", mmy4);

            var mmy5 = FuturesSymbolUtil.ExtractMaturityMonthFromSymbol("VXH0:VE");

            Assert.AreEqual("201003", mmy5);
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }