Ejemplo n.º 1
0
        public StockChartPanel(string symbol)
        {
            this.Symbol  = symbol;
            this.Resize += StockChartPanel_Resize;

            // Create the summary bar
            SummaryBarPanel           = new Panel();
            SummaryBarPanel.Location  = new System.Drawing.Point(0, 0);
            SummaryBarPanel.Size      = new System.Drawing.Size(600, 25);
            SummaryBarPanel.BackColor = GuiStyle.BACKGROUND_COLOR;

            BuyButton          = new GuiButton("Buy");
            BuyButton.Location = new System.Drawing.Point(0, 5);
            SummaryBarPanel.Controls.Add(BuyButton);

            SellButton          = new GuiButton("Sell");
            SellButton.Location = new System.Drawing.Point(0, BuyButton.Location.Y);
            SummaryBarPanel.Controls.Add(SellButton);

            SummaryLabel           = new Label();
            SummaryLabel.ForeColor = GuiStyle.TEXT_COLOR;
            SummaryLabel.Size      = new System.Drawing.Size(200, 20);
            SummaryLabel.BackColor = System.Drawing.Color.Transparent;
            SummaryLabel.Location  = new System.Drawing.Point(10, 5);
            SummaryBarPanel.Controls.Add(SummaryLabel);

            CollapseButton           = new PictureBox();
            CollapseButton.Image     = System.Drawing.Bitmap.FromFile("Content/GUI/Button_Collapse.png");
            CollapseButton.BackColor = System.Drawing.Color.Transparent;
            CollapseButton.Size      = CollapseButton.Image.Size;
            CollapseButton.Location  = new System.Drawing.Point(SummaryLabel.Location.X + SummaryLabel.Width, 5);
            CollapseButton.MouseUp  += CollapseButton_MouseUp;
            SummaryBarPanel.Controls.Add(CollapseButton);

            CloseButton           = new PictureBox();
            CloseButton.Image     = System.Drawing.Bitmap.FromFile("Content/GUI/Button_Close.png");
            CloseButton.BackColor = System.Drawing.Color.Transparent;
            CloseButton.Size      = CollapseButton.Image.Size;
            CloseButton.Location  = new System.Drawing.Point(CollapseButton.Location.X + CollapseButton.Width, 5);
            SummaryBarPanel.Controls.Add(CloseButton);
            this.Controls.Add(SummaryBarPanel);

            this.Canvas = new Panel();
            this.Chart  = new StockChart(symbol);
            Canvas.Controls.Add(Chart.Canvas);

            // Request data to fill the stock chart
            Chart.RequestData(DateTime.Now.Date.AddHours(-48), DateTime.Now.Date.AddHours(16), new TimeSpan(0, 1, 0));
            Chart.SetSubscritpion(DataAccessor.Subscribe(Chart.Symbol, DataAccessor.SUBSCRIBE_FIVE_SEC));

            Canvas.Resize  += (sender, e) => { Chart.Canvas.Size = Canvas.Size; };
            Canvas.Location = new System.Drawing.Point(SummaryBarPanel.Location.X - 6, SummaryBarPanel.Location.Y + SummaryBarPanel.Height);
            this.Controls.Add(Canvas);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Brings up the order menu
        /// </summary>
        /// <param name="symbol">The stock the order is for</param>
        /// <param name="buySell">Indicates if the order is a buy or sell</param>
        public void ShowOrderMenu(string symbol, Broker.Order.BuySellType buySell)
        {
            this.Symbol      = symbol;
            this.BuySell     = buySell;
            this.BuyingPower = 0;

            DataAccessor.Search(symbol, (Dictionary <string, string> results) => {
                string stockName;
                if (results.TryGetValue(Symbol, out stockName))
                {
                    this.BeginInvoke((Action)(() =>
                    {
                        BuySellLabel.Text = ((buySell == Broker.Order.BuySellType.BUY) ? "Buy" : "Sell");
                        OrderInfoLabel.Text = string.Format("{0} Order: {1}\n{2}", (buySell == Broker.Order.BuySellType.BUY) ? "Buy" : "Sell", Symbol, stockName);
                        this.Visible = true;
                    }));
                }
            });

            Broker.Instance.GetAccountInfo((account) => { this.BuyingPower = account.BuyingPower; });

            MarketPrice         = DataAccessor.Subscribe(symbol, DataAccessor.SUBSCRIBE_ONE_SEC);
            MarketPrice.Notify += (DataAccessor.Subscription s) =>
            {
                this.BeginInvoke((Action)(() =>
                {
                    PricePerShareTextbox.Text = string.Format("{0:c}", s.Price);
                    UpdateTransaction();
                }));
            };

            // Select the default order type
            SelectedOrderType = Broker.Order.OrderType.MARKET;
            RefreshOrderTypeButtons();
            RefreshOrderOptionList();

            // Select the default number of shares for the order
            Broker.Instance.GetPositions().TryGetValue(Symbol, out OwnedShares);
            Shares = ((BuySell == Broker.Order.BuySellType.SELL) ? OwnedShares : 0);

            // Clear the target values initially
            TargetShares     = 0;
            TargetTotalValue = 0;

            // Ensure the order review menu is closed
            ReviewOrderButton.Show();
            OrderInfoLabel.Hide();
            EditOrderButton.Hide();
            SubmitOrderButton.Hide();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a new symbol to the list
        /// </summary>
        /// <param name="group">The group the symbol should be added as part of</param>
        /// <param name="symbol">The ticker symbol to add</param>
        /// <param name="infoPanel">A panel that displays information about the stock</param>
        private void AddInternal(string group, string symbol, SummaryPanel infoPanel)
        {
            DataAccessor.Subscription sub = null;
            if (infoPanel == null)
            {
                sub       = DataAccessor.Subscribe(symbol, DataAccessor.SUBSCRIBE_FIVE_SEC);
                infoPanel = new PercentageChangeSummary(sub);
            }

            // Ensure the symbol is not already in the list
            bool             isNew = true;
            List <StockLine> stockList;

            if (!Stocks.TryGetValue(group, out stockList))
            {
                stockList = new List <StockLine>();
                Stocks.Add(group, stockList);
                if (!GroupOrder.Contains(group))
                {
                    GroupOrder.Add(group);
                }
                GroupLabels.Add(group, new Label());
                Controls.Add(GroupLabels[group]);
            }
            for (int i = 0; i < stockList.Count; i++)
            {
                if (stockList[i].Symbol.Equals(symbol))
                {
                    isNew = false;
                    break;
                }
            }
            if (isNew)
            {
                StockLine newLine = new StockLine(symbol, this, infoPanel);
                newLine.Location = new System.Drawing.Point(5, (int)((Stocks.Count + 0.5) * (newLine.Height + 5)));
                newLine.MouseUp += (sender, e) => { AddStockUi(symbol); };
                stockList.Add(newLine);
                this.Controls.Add(newLine);
                this.Refresh();

                // Request data to fill the summary chart
                newLine.SummaryChart.RequestData(DateTime.Now.Date.AddHours(-12), DateTime.Now.Date.AddHours(16), new TimeSpan(0, 1, 0));
            }
        }
Ejemplo n.º 4
0
            public OrderSummary(Broker.Order orderInfo) : base(DataAccessor.Subscribe(orderInfo.Symbol, DataAccessor.SUBSCRIBE_FIVE_SEC))
            {
                this.OrderInfo = orderInfo;

                OrderLabel = new Label();
                //OrderLabel.Font = GuiStyle.Font;
                //OrderLabel.ForeColor = GuiStyle.DARK_GREY;
                OrderLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
                OrderLabel.Text      = string.Format("{0} {1}", orderInfo.BuySell == Broker.Order.BuySellType.BUY ? "Buy" : "Sell", orderInfo.Quantity);
                OrderLabel.Size      = new System.Drawing.Size(60, 15);
                OrderLabel.Location  = new System.Drawing.Point(5, 5);
                Controls.Add(OrderLabel);

                CancelOrderButton             = new GuiButton("Cancel");
                CancelOrderButton.Location    = new System.Drawing.Point(OrderLabel.Location.X, OrderLabel.Location.Y + OrderLabel.Height + 5);
                CancelOrderButton.MouseClick += (sender, e) =>
                {
                    Broker.Instance.CancelOrder(OrderInfo.Symbol);
                };
                Controls.Add(CancelOrderButton);
            }