public void WatchListItemParams()
 {
     Symbol s = new Symbol("GOOG");
     WatchListItem wli = new WatchListItem(s, "Default");
     Assert.AreEqual(wli.ListName, "Default");
     Assert.AreEqual(wli.SymbolName, "GOOG");
 }
        public Quote getQoute(Symbol symbol)
        {
            //the pupose of this is to get an up to minute stock update without having to do a sql query with a where clause looking for the current time
            //first time will take a second to run after that it will speed up
            Quote StockQt = new Quote();
            Qt.StockQuote SQ = new Qt.StockQuote();
            XmlDocument doc = new XmlDocument();

            string UpdatedQoute = SQ.GetQuote(symbol.ToString());
            doc.LoadXml(UpdatedQoute);
            StockQt.price = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("//Stock/Last").InnerText);
            StockQt.SymbolName = doc.DocumentElement.SelectSingleNode("//Stock/Name").InnerText;
            StockQt.timestamp = Convert.ToDateTime(doc.DocumentElement.SelectSingleNode("//Stock/Date").InnerText + " " + doc.DocumentElement.SelectSingleNode("//Stock/Time").InnerText);
            StockQt.Symbol = symbol;
            return StockQt;
        }
        public void TestSell()
        {
            Symbol s = new Symbol("GOOG");
            Position pos = new Position();
            Trade t = new Trade();
            t.Status = tradeStatus.Active;
            t.type = tradeTypes.Buy;
            t.Position = pos;
            t.Symbol = s;
            t.timestamp = new DateTime(2013, 6, 1);
            t.price = 10;
            t.quantity = 5;

            Trade sell = t.sell(2);
            Assert.AreEqual(s, sell.Symbol);
            Assert.AreEqual(pos, sell.Position);
            Assert.AreEqual(tradeStatus.Closed, sell.Status);
            Assert.AreEqual(tradeTypes.Sell, sell.type);
            Assert.AreEqual(2, sell.quantity);
            Assert.AreNotEqual(t.timestamp, sell.timestamp);
            Assert.AreEqual(t, sell.RelatedTrade);
        }
Exemple #4
0
        /// <summary>
        /// Called by the UI to add an item to the list.
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="listName"></param>
        /// <returns></returns>
        bool IWatchList.AddToList(ISymbol symbol, string listName)
        {
            string sname = symbol.name;
            string lname = listName;

            if (sname.Length > 0 && lname.Length > 0)
            {
                TraderContext db = new TraderContext();
                // checks if watchlist item exists
                var WLI_QUERY = db.WatchListItems.Where(x => (x.SymbolName.Equals(sname) && x.ListName.Equals(lname))).ToList();
                if (WLI_QUERY.Count >= 1)
                {
                    return false;
                }
                else // if not, checks if symbol exists
                {
                    var SYMBOL_QUERY = db.Symbols.Where(x => x.name.Equals(sname)).ToList();
                    if (SYMBOL_QUERY.Count == 0)
                    {
                        Symbol s = new Symbol(sname);
                        db.Symbols.Add(s);
                        db.SaveChanges();
                    }
                    db.WatchListItems.Add(new WatchListItem(symbol, listName));
                    db.SaveChanges();
                    return true;
                }
            }
            else
            {
                return false;
            }
        }
 public Quote FindLastQuoteFor(Symbol symbol)
 {
     if (symbol == null) throw new ArgumentNullException("symbol");
     return Quotes.Where(x => x.SymbolName == symbol.name).OrderByDescending(y => y.timestamp).FirstOrDefault();
 }