/// <summary> /// Order validation. /// </summary> private bool validateOrder(Order order) { bool isValid = true; //Buy side validation if (order.Action == Action.Buy) { //See if we can afford the buy order if (AvailableCash < (order.Quantity * order.FillPrice)) { if (!_allowMargin) { isValid = false; } } } //Sell side validation else if (order.Action == Action.Sell) { //Make sure we have the stock befoe we sell it if (!StockPortfolio.Exists(p => p.Symbol == order.Symbol && p.Quantity >= order.Quantity)) { isValid = false; } } //Cancel order if (isValid == false) { order.Status = OrderStatus.Cancelled; order.FillPrice = 0; order.Quantity = 0; TotalTradesCancelled++; } return(isValid); }
/// <summary> /// /// </summary> /// <param name="symbol"></param> /// <returns></returns> public bool IsHoldingStock(string symbol) { return(StockPortfolio.Exists(p => p.Symbol == symbol)); }