Beispiel #1
0
        public void TestMapping()
        {
            var          fsm                 = new FuturesSymbolMapper();
            const string platform            = "TEST";
            const string bloombergRoot       = "SF";
            const string platformReceiveRoot = "6S";
            const string platformSendRoot    = "SFSS";

            // Setup our test data
            fsm.AddBloombergMapping(platform, bloombergRoot, platformReceiveRoot, platformSendRoot, 10);

            var mappedBloomberg = fsm.ConvertPlatformReceiving(platform, platformReceiveRoot, false);

            Assert.AreEqual(mappedBloomberg, bloombergRoot);

            var ricRoot = fsm.LookupPlatformSendingRoot(platform, bloombergRoot, false);

            Assert.AreEqual(ricRoot, platformSendRoot);

            var mappedPlatform = fsm.LookupPlatformRoot(platform, bloombergRoot, false);

            Assert.AreEqual(mappedPlatform, platformReceiveRoot);

            var toBloomberg = fsm.LookupToBloombergPriceMultiplier(platform, bloombergRoot);

            Assert.AreEqual(toBloomberg, 10);

            var toPlatform = fsm.LookupToPlatformPriceMultiplier(platform, bloombergRoot);

            Assert.AreEqual(toPlatform, decimal.One / 10);

            // Test logic for converting exchange to bloomberg pricing and vice versa
            // multiply by 10
            var bbPrice = (decimal)0.7268 * toBloomberg;

            Assert.AreEqual(bbPrice, 7.268);

            // multiply by 1/10
            var platformPrice = (decimal)72.68 * toPlatform;

            Assert.AreEqual(platformPrice, 7.268);

            var bbSymbol = fsm.MapPlatformRootToBloombergSymbol(platform, platformReceiveRoot, "200906");

            Assert.AreEqual(bbSymbol, "SFM9");

            // Do the RIC to Bloomberg mapping
            // We are using TRADS for the platform to cheat, ensure we have it
            fsm.AddBloombergMapping("TRADS", bloombergRoot, platformReceiveRoot, platformSendRoot, 10);

            var sfRoot = fsm.ConvertRicRoot("SFSS");

            Assert.AreEqual("SF", sfRoot);

            var fredRoot = fsm.ConvertRicRoot("1FRED");

            Assert.IsNull(fredRoot);
        }
        /// <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);
            }
        }