Example #1
0
        protected void getDataPoints()
        {
            IWatchListManager wlm = new WatchListManager();
            var query = wlm.GetQuotes(symbolName);
            DateTime dstart = new DateTime(1970, 1, 1);
            query = query.OrderBy(x => x.timestamp).ToList();

            data = "[";
            foreach (Quote q in query)
            {
                DateTime qdate = q.timestamp;
                TimeSpan ts = q.timestamp - dstart;
                //plot.Add(new PlotPoint(ts.TotalMilliseconds, q.price));
                data += "[" + (ts.TotalMilliseconds - ts.Milliseconds-15000) + ", " + q.price + "],";
            }
            data = data.TrimEnd(',');
            data += "]";
        }
        public void OnTick(object source, ElapsedEventArgs e)
        {
            PortfolioManager pm = new PortfolioManager();
            List<PositionMessage> pos = pm.GetOpenPositions();
            List<string> owned = pos.Select(x => x.SymbolName).ToList<string>();
            _owner.WatchForSell = owned;

            SortedSet<string> watched = new SortedSet<string>();
            IWatchListManager wlm = new WatchListManager();
            List<WatchList> lists = wlm.GetAllWatchLists();
            foreach (WatchList wl in lists)
            {
                foreach (WatchListItem i in wl.Items)
                {
                    watched.Add(i.SymbolName);
                }
            }
            _owner.WatchForBuy = watched.ToList<string>();
        }
        /// <summary>
        /// Creates the position table.
        /// </summary>
        /// <param name="pm">PositionMessage</param>
        /// <returns>Table</returns>
        private Table createPositionTable(PositionMessage pm)
        {
            string fullName = string.Empty;
            double gain = 0;
            double gainPercent = 0;
            string classname = string.Empty;

            IWatchListManager wlm = new WatchListManager();
            fullName = wlm.GetLongName(pm.SymbolName);

            TraderContext db = new TraderContext();
            double latestQuote = db.Quotes.Where(x => x.SymbolName.Equals(pm.SymbolName)).OrderByDescending(x => x.timestamp).Select(x => x.price).FirstOrDefault();
            gain = (latestQuote * pm.Quantity) - pm.Price;
            gainPercent = gain / (pm.Price);

            if (gain > 0)
            {
                classname = "green";
            }
            if (gain < 0)
            {
                classname = "red";
            }

            Table tbl = new Table();
            TableRow row = new TableRow();

            for (int i = 0; i < columns; i++)
            {
                TableCell cell = new TableCell();
                cell.Width = new Unit(widths[i]);
                row.Cells.Add(cell);
            }

            row.Cells[1].Text += new HtmlString(String.Format("{0} <span class='subtext'>({1})</span>", pm.SymbolName, fullName));
            row.Cells[2].Text = String.Format("{0:N0}", pm.Quantity);
            row.Cells[3].Text = new HtmlString(String.Format("{0:C} / <span class='{3}'>{1:C}</span> / <span class='{3}'>{2:P2}</span>", pm.Price, gain, gainPercent, classname)).ToString();
            row.Cells[4].Text = String.Format("{0:C}", pm.Trades.Sum(x => x.PaidCommission));
            row.Cells[5].Text = pm.Status.ToString();
            row.Cells[5].CssClass = getCssClass(pm.Status.ToString());

            // BUTTONS
            HtmlGenericControl btnToggle = new HtmlGenericControl("div");
            btnToggle.Attributes.Add("class", "toggle icon-plus-sign");
            row.Cells[0].Controls.Add(btnToggle);

            Button btnAction = new Button();
            btnAction.CssClass = "symbol-button";
            btnAction.ToolTip = "Buy/sell";
            btnAction.Text = HttpUtility.HtmlDecode("&#xe015;");
            btnAction.Attributes["SymbolName"] = pm.SymbolName;
            btnAction.Click += new EventHandler(btnClick);
            row.Cells[columns - 1].Controls.Add(btnAction);

            // css stuff
            tbl.CssClass = "main";
            row.CssClass = "main";
            row.Cells[(radioSortType.SelectedIndex / 2) + 1].CssClass = "bold";

            tbl.Rows.Add(row);
            return tbl;
        }