private void CheckHighLow() { try { var stockLastPrice = _kite.GetLTP(_stockSymbols); foreach (var stockLTP in stockLastPrice) { if (_stockSybolsHighLow.ContainsKey(stockLTP.Key)) { if (!_breakOutPrice.ContainsKey(stockLTP.Key)) { _breakOutPrice[stockLTP.Key] = stockLTP.Value.LastPrice; continue; } //if (_breakOutPrice[stockLTP.Key] == stockLTP.Value.LastPrice) // continue; _breakOutPrice[stockLTP.Key] = stockLTP.Value.LastPrice; var highLow = _stockSybolsHighLow[stockLTP.Key]; decimal min = highLow.Item1 == 0 ? stockLTP.Value.LastPrice : Math.Min(highLow.Item1, stockLTP.Value.LastPrice); decimal max = highLow.Item2 == 0 ? stockLTP.Value.LastPrice : Math.Max(highLow.Item2, stockLTP.Value.LastPrice); _stockSybolsHighLow[stockLTP.Key] = new Tuple <decimal, decimal>(min, max); Events.RaiseStockHighLowChangeEvent(new KeyValuePair <string, Tuple <decimal, decimal> >(stockLTP.Key, new Tuple <decimal, decimal>(min, max))); } } } catch (Exception ex) { // Stop(); } }
private void OrderStockWhenItBreaksRange() { try { var orderWhichIsNotPlaced = _configurations.Where(s => s.OrderStatus == OrderStatus.YetToPlaceOrder); if (!orderWhichIsNotPlaced.Any()) { Stop(); } var stockSymbols = orderWhichIsNotPlaced.Select(s => s.StockSymbol).Distinct().ToArray(); var stocksLTP = _kite.GetLTP(stockSymbols); foreach (var stockLTP in stocksLTP) { var buyStock = orderWhichIsNotPlaced.FirstOrDefault(s => s.StockSymbol == stockLTP.Key && s.OrderMode == OrderMode.BUY); var sellStock = orderWhichIsNotPlaced.FirstOrDefault(s => s.StockSymbol == stockLTP.Key && s.OrderMode == OrderMode.SELL); bool isPlaced = false; if (buyStock != null) { if (IsEligible(buyStock, stockLTP.Value)) { if (PlaceOrder(buyStock, stockLTP.Value)) { buyStock.OrderStatus = OrderStatus.OrderPlaced; } } } if (sellStock != null && !isPlaced) { if (IsEligible(sellStock, stockLTP.Value)) { if (PlaceOrder(sellStock, stockLTP.Value)) { sellStock.OrderStatus = OrderStatus.OrderPlaced; } } } } } catch (Exception ex) { } }