Пример #1
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);
            }
        }
Пример #2
0
 /// <summary>
 /// Button event that adds cash to the user's available cash.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnAddCash_Click(object sender, EventArgs e)
 {
     double value = double.Parse(InputAddCash.Value);
     TraderContext db = new TraderContext();
     db.Portfolios.FirstOrDefault().Cash += value;
     AvailableCash.Text = String.Format("{0:C}", (double.Parse(AvailableCash.Text.TrimStart('$')) + value));
     db.SaveChanges();
     update();
 }
Пример #3
0
        bool IWatchListManager.AddWatchList(string listName)
        {
            TraderContext db = new TraderContext();
            string l = listName;
            if (listName.Length == 0)
            {
                l = "Default";
            }
            var query = db.WatchLists.Where(x => x.ListName.Equals(l));
            if (query.Count() == 0)
            {
                WatchList w = new WatchList(l);
                db.WatchLists.Add(w);
                db.SaveChanges();
                return true;
            }

            return false;
        }
Пример #4
0
        /// <summary>
        /// Called by the UI to remove an item from the watchlist.
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="listName"></param>
        /// <returns></returns>
        bool IWatchList.RemoveFromList(ISymbol symbol, string listName)
        {
            TraderContext db    = new TraderContext();
            var           query = db.WatchListItems.Where(x => (x.SymbolName.Equals(symbol.name) && x.ListName.Equals(listName)));

            if (query.Count() > 0)
            {
                foreach (WatchListItem item in query)
                {
                    db.WatchListItems.Remove(item);
                }
                db.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #5
0
        protected void btnResetDefault_Click(object sender, EventArgs e)
        {
            try
            {
                string module = "ThreeDuckStrategy";

                // Remove the old settings
                TraderContext db = new TraderContext();
                var query = db.SystemSettings.Where(x => x.Module.Equals(module)).Select(x => x);
                foreach (SystemSetting setting in query)
                {
                    db.SystemSettings.Remove(setting);
                }

                var q_username = db.SystemSettings.Where(x => x.Name.Equals("USERNAME")).Select(x => x);
                if (q_username.Count() > 0)
                {
                    SystemSetting s = q_username.FirstOrDefault();
                    db.SystemSettings.Remove(s);
                }

                // Restore the default settings
                SystemSetting _duck1 = new SystemSetting(module, "FIRST_DUCK_SECONDS", "300");
                SystemSetting _duck2 = new SystemSetting(module, "SECOND_DUCK_SECONDS", "3600");
                SystemSetting _duck3 = new SystemSetting(module, "THIRD_DUCK_SECONDS", "14400");
                SystemSetting _movingavg = new SystemSetting(module, "MOVING_AVERAGE_WINDOW", "60");
                db.SystemSettings.Add(_duck1);
                db.SystemSettings.Add(_duck2);
                db.SystemSettings.Add(_duck3);
                db.SystemSettings.Add(_movingavg);
                db.SaveChanges();

                // Display success message
                setStatus("Settings saved successfully.", true);
            }
            catch
            {
                // Display fail message
                setStatus("Settings could not be saved. Please try again.", false);
            }
        }
Пример #6
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;
            }
        }
Пример #7
0
 /// <summary>
 /// Called by the UI to remove an item from the watchlist.
 /// </summary>
 /// <param name="symbol"></param>
 /// <param name="listName"></param>
 /// <returns></returns>
 bool IWatchList.RemoveFromList(ISymbol symbol, string listName)
 {
     TraderContext db = new TraderContext();
     var query = db.WatchListItems.Where(x => (x.SymbolName.Equals(symbol.name) && x.ListName.Equals(listName)));
     if (query.Count() > 0)
     {
         foreach (WatchListItem item in query)
         {
             db.WatchListItems.Remove(item);
         }
         db.SaveChanges();
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #8
0
        bool IWatchListManager.DeleteWatchList(string listName)
        {
            TraderContext db = new TraderContext();
            string l = listName;
            var query = db.WatchLists.Where(x => x.ListName.Equals(l)).ToList();

            if (query.Count > 0)
            {
                foreach (WatchList w in query)
                {
                    db.WatchLists.Remove(w);
                }
                db.SaveChanges();
                return true;
            }
            return false;
        }
Пример #9
0
        /// <summary>
        /// Saves the changes made to the settings.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string module = "ThreeDuckStrategy";

                // Remove the old settings
                TraderContext db = new TraderContext();
                var query = db.SystemSettings.Where(x => x.Module.Equals(module)).Select(x => x);
                foreach (SystemSetting setting in query)
                {
                    db.SystemSettings.Remove(setting);
                }

                var q_username = db.SystemSettings.Where(x => x.Name.Equals("USERNAME")).Select(x=>x);
                if (q_username.Count() > 0)
                {
                    SystemSetting s = q_username.FirstOrDefault();
                    db.SystemSettings.Remove(s);
                }

                // Add the new settings
                SystemSetting _duck1 = new SystemSetting(module, "FIRST_DUCK_SECONDS", InputFirstDuck.Value);
                SystemSetting _duck2 = new SystemSetting(module, "SECOND_DUCK_SECONDS", InputSecondDuck.Value);
                SystemSetting _duck3 = new SystemSetting(module, "THIRD_DUCK_SECONDS", InputThirdDuck.Value);
                SystemSetting _movingavg = new SystemSetting(module, "MOVING_AVERAGE_WINDOW", InputAvgWindow.Value);
                SystemSetting _username = new SystemSetting("User", "USERNAME", InputName.Value);
                db.SystemSettings.Add(_duck1);
                db.SystemSettings.Add(_duck2);
                db.SystemSettings.Add(_duck3);
                db.SystemSettings.Add(_movingavg);
                db.SystemSettings.Add(_username);
                db.SaveChanges();

                setStatus("Settings saved successfully.", true);
            }
            catch
            {
                setStatus("Settings could not be saved. Please try again.", false);
            }
        }
Пример #10
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();
        }