public NotificationSummary(DataAccessor.Subscription subscription) : base(subscription) { CloseButton = new PictureBox(); CloseButton.Image = new System.Drawing.Bitmap(System.Drawing.Bitmap.FromFile("Content/GUI/Button_Close.png"), new System.Drawing.Size(12, 12)); CloseButton.Size = CloseButton.Image.Size; CloseButton.Location = new System.Drawing.Point(45, 0); CloseButton.MouseUp += (sender, e) => { ParentLine.ParentList.Remove(ParentLine); }; this.Controls.Add(CloseButton); this.Controls.SetChildIndex(CloseButton, 0); // Automatically open the buy/sell window when the notification is clicked this.MouseUp += (sender, e) => { if (PositionSubscription.PositionInfo.Shares > 0) { BuySellPanel.Instance.ShowOrderMenu(StockSubscription.Symbol, Broker.Order.BuySellType.SELL); } else { BuySellPanel.Instance.ShowOrderMenu(StockSubscription.Symbol, Broker.Order.BuySellType.BUY); } }; base.PriceLabel.MouseUp += (sender, e) => { this.OnMouseUp(e); }; base.PercentageLabel.MouseUp += (sender, e) => { this.OnMouseUp(e); }; }
/// <summary> /// Sets the chart to be updated by the specified subscription /// </summary> /// <param name="sub">The subscription to set</param> public void SetSubscritpion(DataAccessor.Subscription sub) { this.PriceChangeNotifier = sub; // Set the data source again to ensure that the final data point tied to the subscription is created this.SetChartData(Source); // Set the notification callback this.PriceChangeNotifier.Notify += (DataAccessor.Subscription s) => { if (CurrentPriceRow != null) { CurrentPriceRow[TIME_DATA_TAG] = s.LastUpdated; CurrentPriceRow[PRICE_DATA_TAG] = s.Price; // Check if a new point needs to be added DateTime lastPoint = (DateTime)Source.Rows[Source.Rows.Count - 2][TIME_DATA_TAG]; TimeSpan span = (lastPoint - (DateTime)Source.Rows[Source.Rows.Count - 3][TIME_DATA_TAG]); if (((DateTime)CurrentPriceRow[TIME_DATA_TAG] - lastPoint) >= span) { RequestData(lastPoint + span, lastPoint + span, span); } Canvas.BeginInvoke((Action)(() => { UpdateChartData(); })); } }; }
public virtual void Destroy() { if (StockSubscription != null) { DataAccessor.Unsubscribe(StockSubscription); StockSubscription = null; } }
/// <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(); }
/// <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)); } }
public PercentageChangeSummary(DataAccessor.Subscription subscription) : base(subscription) { PriceLabel = new Label(); //PriceLabel.Font = GuiStyle.Font; //PriceLabel.ForeColor = GuiStyle.DARK_GREY; PriceLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter; PriceLabel.Size = new System.Drawing.Size(60, 15); PriceLabel.Location = new System.Drawing.Point(0, 5); Controls.Add(PriceLabel); PercentageLabel = new Label(); //PercentageLabel.Font = GuiStyle.Font; //PercentageLabel.ForeColor = GuiStyle.DARK_GREY; PercentageLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter; PercentageLabel.Size = PriceLabel.Size; PercentageLabel.Location = new System.Drawing.Point(PriceLabel.Location.X, PriceLabel.Location.Y + PriceLabel.Height + 5); Controls.Add(PercentageLabel); }
public SummaryPanel(DataAccessor.Subscription subscription) { this.StockSubscription = subscription; }
public PositionChangeSummary(DataAccessor.Subscription subscription) : base(subscription) { }