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

            var fullSymbol1 = FuturesSymbolUtil.CombineRootMaturityMonthYear(ric, mmy);

            Assert.AreEqual(fullSymbol1, "TYM9", "Failed to combine symbol");

            var fullSymbol2 = FuturesSymbolUtil.CombineRootMaturityMonthYear("P", mmy);

            Assert.AreEqual(fullSymbol2, "P M9", "Failed to combine symbol");

            // do some RIC parsing

            var fullSymbol3 = FuturesSymbolUtil.CombineRootMaturityMonthYear("TTA", "201003");

            Assert.AreEqual(fullSymbol3, "TTAH0", "Failed to combine symbol");

            var fullSymbol4 = FuturesSymbolUtil.CombineRootMaturityMonthYear("6B", "201003");

            Assert.AreEqual(fullSymbol4, "6BH0", "Failed to combine symbol");

            // Test the funny ric root
            var fullSymbol5 = FuturesSymbolUtil.CombineRootMaturityMonthYear("VX:VE", "201003");

            Assert.AreEqual("VXH0:VE", fullSymbol5, "Failed to combine symbol");
        }
Ejemplo n.º 2
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.º 3
0
        public string MapPlatformRootToBloombergSymbol(string platform, string platformRoot, string monthYear)
        {
            var bloombergRoot = ConvertPlatformReceiving(platform, platformRoot, true);

            return(FuturesSymbolUtil.CombineRootMaturityMonthYear(bloombergRoot, monthYear));
        }
Ejemplo n.º 4
0
        public void TestExtractSymbolRoot()
        {
            // Test everything that we might get

            const string bbid = "TYM9 Comdty";
            const string ric  = "TYM9";

            var root1 = FuturesSymbolUtil.ExtractSymbolRoot(bbid);

            Assert.AreEqual("TY", root1, "Failed to extract root from Bloomberg with Yellow key");

            var root2 = FuturesSymbolUtil.ExtractSymbolRoot(ric);

            Assert.AreEqual("TY", root2, "Failed to extract root from Bloomberg/RIC");

            const string shortRootSymbol = "P M9";
            var          root3           = FuturesSymbolUtil.ExtractSymbolRoot(shortRootSymbol);

            Assert.AreEqual("P", root3, "Failed to extract root from a short symbol root");

            const string shortSymbol = "P";
            var          root4       = FuturesSymbolUtil.ExtractSymbolRoot(shortSymbol);

            Assert.AreEqual("P", root4, "Failed to extract short root");

            const string shortSymbolSpace = "P ";
            var          root4S           = FuturesSymbolUtil.ExtractSymbolRoot(shortSymbolSpace);

            Assert.AreEqual("P", root4S, "Failed to extract short root");


            const string shortSymbol2 = "TU";
            var          root41       = FuturesSymbolUtil.ExtractSymbolRoot(shortSymbol2);

            Assert.AreEqual("TU", root41, "Failed to extract short root");

            // do some RIC parsing
            const string bigRic = "TTAH0";

            var root5 = FuturesSymbolUtil.ExtractSymbolRoot(bigRic);

            Assert.AreEqual("TTA", root5, "Failed to extract big root from RIC");

            const string numbers = "6BH0";

            var root6 = FuturesSymbolUtil.ExtractSymbolRoot(numbers);

            Assert.AreEqual("6B", root6, "Failed to extract numeric root");

            // Try futures options
            const string futuresOptions = "TYH9C";

            var root7 = FuturesSymbolUtil.ExtractSymbolRoot(futuresOptions);

            Assert.AreEqual("TY_C", root7, "Failed to extract futures option root");

            // Try futures options
            const string futuresOptionsRoot = "TY_P";

            var root8 = FuturesSymbolUtil.ExtractSymbolRoot(futuresOptionsRoot);

            Assert.AreEqual("TY_P", root8, "Failed to extract futures option root");

            // Try futures options
            const string weirdSymbol = "ESH8 08";

            var root9 = FuturesSymbolUtil.ExtractSymbolRoot(weirdSymbol);

            Assert.AreEqual("ES", root9, "Failed to extract weird root");

            var root10 = FuturesSymbolUtil.ExtractSymbolRoot("VXH0:VE");

            Assert.AreEqual("VX", root10, "Failed to extract weird root");
        }
Ejemplo n.º 5
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);
            }
        }