/// <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> /// Performs a search on symbols close to the specified string /// </summary> /// <param name="symbol"></param> public void Search(string symbol) { DataAccessor.Search(symbol, (Dictionary <string, string> r) => { this.BeginInvoke((Action <Dictionary <string, string> >)((Dictionary <string, string> results) => { this.SuspendLayout(); ClearSearchResults(); int yPos = 35; foreach (var pair in results) { StockListItem item = new StockListItem(this, pair.Key, pair.Value); item.Location = new System.Drawing.Point(5, yPos); Controls.Add(item); yPos += 35; } this.ResumeLayout(); }), new object[] { r }); }); }