public void AddQuoteAndCheckSignal()
        {
            ThreeDucksStrategy tds = new ThreeDucksStrategy();
            tds.startWatching("GOOG");
            QuoteMessage q = new QuoteMessage();
            q.SymbolName = "GOOG";
            q.timestamp = DateTime.Now;
            q.Price = 10;
            tds.NewQuote(q);

            StrategySummary s = tds.getSummary("GOOG");
            Assert.AreEqual("GOOG", s.SymbolName);
            Assert.IsNotNull(s.AsOf);
            Assert.AreEqual(StrategySignal.None, s.CurrentSignal);
        }
        public void TestForBuySignal()
        {
            Dictionary<string, string> settings = new Dictionary<string, string>();
            settings.Add("FIRST_DUCK_SECONDS", "1");
            settings.Add("SECOND_DUCK_SECONDS", "1");
            settings.Add("THIRD_DUCK_SECONDS", "1");
            settings.Add("MOVING_AVERAGE_WINDOW", "2");

            ThreeDucksStrategy tds = new ThreeDucksStrategy(settings);
            tds.startWatching("GOOG");

            QuoteMessage q1 = new QuoteMessage(10, new DateTime(2013, 06, 13, 0, 0, 1), "GOOG");
            QuoteMessage q2 = new QuoteMessage(20, new DateTime(2013, 06, 13, 0, 0, 2), "GOOG");

            tds.NewQuote(q1);
            tds.NewQuote(q2);

            StrategySummary result = tds.getSummary("GOOG");
            Assert.AreEqual(StrategySignal.Buy, result.CurrentSignal);
        }
        // this is the method used to process real-time streaming quotes
        public void NewQuote(QuoteMessage quote)
        {
            ILog log = LogManager.GetLogger(typeof(ThreeDucksStrategy));
            log.DebugFormat("Quote received: {0} {1} {2}", quote.SymbolName, quote.timestamp.ToString(), quote.Price);

            foreach (SmaMetric m in _metrics[quote.SymbolName])
            {
                m.Add(quote.timestamp, quote.Price);
            }
        }
        // determines if we need to raise any alerts as a result of the most recent quote
        public void CheckSignals(QuoteMessage quote)
        {
            int buy_ducks = 0;
            int sell_ducks = 0;

            foreach (SmaMetric m in _metrics[quote.SymbolName])
            {
                if (quote.Price > m.Avg) buy_ducks++;
                if (quote.Price < m.Avg) sell_ducks++;
            }
            if (buy_ducks == 3)
            {
                _signals[quote.SymbolName] = StrategySignal.Buy;
                if (_watchForBuy.Contains(quote.SymbolName))
                {
                    _alerter.BuyAlert(quote.SymbolName, DEFAULT_BUY_SIZE, quote.Price);
                }
            }
            else if (sell_ducks == 3)
            {
                _signals[quote.SymbolName] = StrategySignal.Sell;
                if (_watchForSell.Contains(quote.SymbolName))
                {
                    _alerter.SellAlert(quote.SymbolName, quote.Price);
                }
            }
            else
            {
                _signals[quote.SymbolName] = StrategySignal.None;
            }
        }