Exemplo n.º 1
0
 public void IQuoteProperties()
 {
     IQuote q = new Quote();
     q.price = 1.25;
     Assert.AreEqual(q.price, 1.25);
     q.timestamp = new DateTime(2013, 1, 1);
     Assert.AreEqual(q.timestamp, new DateTime(2013, 1, 1));
 }
Exemplo n.º 2
0
 public void QuoteProperties()
 {
     Quote q = new Quote();
     q.QuoteId = 1;
     Assert.AreEqual(q.QuoteId, 1);
     q.price = 1.25;
     Assert.AreEqual(q.price, 1.25);
     q.SymbolName = "GOOG";
     Assert.AreEqual(q.SymbolName, "GOOG");
     q.timestamp = new DateTime(2013, 1, 1);
     Assert.AreEqual(q.timestamp, new DateTime(2013, 1, 1));
 }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Testing the entity framework...");
            TraderContext db = new TraderContext();

            Console.WriteLine("Clearing the database...");
            var d_quotes = from q in db.Quotes select q;
            foreach (var i in d_quotes) db.Quotes.Remove(i);
            var d_symbol = from s in db.Symbols select s;
            foreach (var i in d_symbol) db.Symbols.Remove(i);
            var d_position = from p in db.Positions select p;
            foreach (var i in d_position) db.Positions.Remove(i);
            var d_trade = from t in db.Trades select t;
            foreach (var i in d_trade) db.Trades.Remove(i);

            Console.WriteLine("Adding records to database...");
            db.Symbols.Add(new Symbol("GOOG"));
            db.Symbols.Add(new Symbol("LNC"));

            db.SaveChanges();

            Quote q1 = new Quote();
            q1.timestamp = DateTime.Now;
            q1.price = 50.47;
            q1.Symbol = db.Symbols.First();
            db.Quotes.Add(q1);

            Position p1 = new Position();
            p1.SymbolName = "GOOG";
            p1.price = 5000;
            p1.quantity = 150;
            p1.status = positionStatus.Open;
            db.Positions.Add(p1);

            db.SaveChanges();

            Trade t1 = new Trade();
            t1.timestamp = DateTime.Now;
            t1.quantity = 40;
            t1.price = 10.10;
            t1.type = tradeTypes.Buy;
            t1.SymbolName = "GOOG";
            db.Trades.Add(t1);

            var q_addtopos = from p in db.Positions.Include("Trades") where p.SymbolName == "GOOG" select p;
            Position goog_pos = q_addtopos.FirstOrDefault();
            goog_pos.Trades.Add(t1);

            db.SaveChanges();

            WatchList w = new WatchList();
            w.ListName = "Default";
            db.WatchLists.Add(w);
            db.SaveChanges();

            WatchListItem wi1 = new WatchListItem();
            wi1.ListName = "Default";
            wi1.SymbolName = "GOOG";
            db.WatchListItems.Add(wi1);

            WatchListItem wi2 = new WatchListItem();
            wi2.ListName = "Default";
            wi2.SymbolName = "LNC";
            db.WatchListItems.Add(wi2);

            db.SaveChanges();

            Console.WriteLine("Retrieving records from database...");
            Console.WriteLine("\nSymbols");
            var query = from s in db.Symbols orderby s.name select s;
            foreach (var i in query)
            {
                Console.WriteLine("Symbol: " + i.name);
            }

            Console.WriteLine("\nQuotes");
            var q_search = from q in db.Quotes select q;
            foreach (var i in q_search)
            {
                Console.WriteLine("Record: " + i.QuoteId.ToString());
                Console.WriteLine("Symbol: " + i.Symbol.name);
                Console.WriteLine("Timestamp: " + i.timestamp.ToString());
                Console.WriteLine("Price: " + i.price.ToString());
            }

            Console.WriteLine("\nPositions");
            var p_search = from p in db.Positions select p;
            foreach (var i in p_search)
            {
                Console.WriteLine("Record: " + i.PositionId.ToString());
                Console.WriteLine("Symbol: " + i.Symbol.name);
                Console.WriteLine("Trade count: " + i.Trades.Count.ToString());
                foreach (var t in i.Trades)
                {
                    Console.WriteLine("\tTrade Id: " + t.TradeId.ToString());
                    Console.WriteLine("\tType: " + t.type.ToString());
                    Console.WriteLine("\tPrice: " + t.price.ToString());
                    Console.WriteLine("\tQuantity: " + t.quantity.ToString());
                    Console.WriteLine("\tTimestamp: " + t.timestamp.ToString());
                }
            }

            Console.WriteLine("\nWatchlist");
            var wlist = from l in db.WatchLists.Include("Items") select l;
            WatchList deflist = wlist.FirstOrDefault();
            foreach (var i in deflist.Items)
            {
                Console.WriteLine("\t" + i.Symbol.name);
            }
            Console.WriteLine("\nTesting complete.");
            Console.ReadLine();
            db.Dispose();
        }