Exemple #1
0
        /// <summary>
        /// Adds WatchListPlusQuote items to the a list from the portfolio, watchlist, and quotes.
        /// </summary>
        public void generateWatchLists()
        {
            IWatchList             wl = new WatchList();
            PortfolioManagerClient pm = new PortfolioManagerClient();

            allitems.Clear();

            foreach (WatchList w in watchlists)             // add all the real watchlist items
            {
                wl.items.AddRange(wlm.GetWatchList(w.ListName).items);
            }
            foreach (PositionMessage msg in pm.GetOpenPositions())             // add the portfolio items
            {
                wl.items.Add(new WatchListItem(new Symbol(msg.SymbolName), portfolioName));
            }
            foreach (WatchListItem item in wl.items)             // join all the items together into a list of WatchlistPlusQuote objects
            {
                var    quotes = wlm.GetQuotes(item.SymbolName).OrderByDescending(x => x.timestamp).ToList();
                double price1 = 0;
                double price2 = 0;

                price1 = quotes.Select(x => x.price).FirstOrDefault();
                price2 = quotes.Select(x => x.price).Skip(1).FirstOrDefault();

                if (quotes.Count() == 1)
                {
                    price2 = price1;
                }

                string companyName = wlm.GetLongName(item.SymbolName);

                DateTime date = quotes.Select(x => x.timestamp).FirstOrDefault();
                allitems.Add(new WatchlistPlusQuote(item.SymbolName, companyName, item.ListName, date, price1, price2));
            }
        }
        /// <summary>
        /// Adds WatchListPlusQuote items to the a list from the portfolio, watchlist, and quotes.
        /// </summary>
        public void generateWatchLists()
        {
            IWatchList wl = new WatchList();
            PortfolioManagerClient pm = new PortfolioManagerClient();
            allitems.Clear();

            foreach (WatchList w in watchlists) // add all the real watchlist items
            {
                wl.items.AddRange(wlm.GetWatchList(w.ListName).items);
            }
            foreach (PositionMessage msg in pm.GetOpenPositions()) // add the portfolio items
            {
                wl.items.Add(new WatchListItem(new Symbol(msg.SymbolName), portfolioName));
            }
            foreach (WatchListItem item in wl.items) // join all the items together into a list of WatchlistPlusQuote objects
            {
                var quotes = wlm.GetQuotes(item.SymbolName).OrderByDescending(x => x.timestamp).ToList();
                double price1 = 0;
                double price2 = 0;

                price1 = quotes.Select(x => x.price).FirstOrDefault();
                price2 = quotes.Select(x => x.price).Skip(1).FirstOrDefault();

                if (quotes.Count() == 1)
                {
                    price2 = price1;
                }

                string companyName = wlm.GetLongName(item.SymbolName);

                DateTime date = quotes.Select(x => x.timestamp).FirstOrDefault();
                allitems.Add(new WatchlistPlusQuote(item.SymbolName, companyName, item.ListName, date, price1, price2));
            }
        }
 /// <summary>
 /// Executes the trade based on the selected buy/sell picker and the input value.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void ExecuteTrade_Click(object sender, EventArgs e)
 {
     portfolio = new PortfolioManagerClient();
     if (BuySellPicker.SelectedValue == "Buy")
     {
         try
         {
             portfolio.buy(SymbolLabel.Text, Int32.Parse(QuantityBox.Value));
         }
         catch (FaultException <AlgoTraderSite.Portfolio.Client.InsufficientFundsFault> ex)
         {
             ErrorMsg.Text    = String.Format("Insufficient funds error. Available: ${0}  Requested: ${1}", ex.Detail.AvailableAmount, ex.Detail.TransactionAmount);
             ErrorMsg.Visible = true;
             return;
         }
         catch (FaultException <AlgoTraderSite.Portfolio.Client.AllocationViolationFault> ex)
         {
             ErrorMsg.Text    = ex.Detail.FaultMessage;
             ErrorMsg.Visible = true;
             return;
         }
     }
     else
     {
         try
         {
             portfolio.sell(SymbolLabel.Text, Int32.Parse(QuantityBox.Value));
         }
         catch (FaultException <AlgoTraderSite.Portfolio.Client.InsufficientQuantityFault> ex)
         {
             ErrorMsg.Text    = String.Format("Not enough shares to sell. Available {0} Requested: {1}", ex.Detail.AvailableQuantity, ex.Detail.RequestedQuantity);
             ErrorMsg.Visible = true;
             return;
         }
     }
     Response.Redirect("Portfolio.aspx");
 }