public bool QueueMaintence(IAccountHandlerInterface AccountHandler) { //remove sell orders where the holding dont exists on the account try { List <OrderType> SellStoploss = new List <OrderType>(); SellStoploss.Add(OrderType.Sell); SellStoploss.Add(OrderType.StopLoss); var OrderQuery = from t in m_oOrders join ssl in SellStoploss on t.OrderType equals ssl select t; var ObseleteOrders = from o in OrderQuery from a in AccountHandler.Accounts() .Where(a => a.Identifier.Equals(o.AccountIdentifier) && a.GetSymbolInHoldings().Contains(o.Symbol) ).DefaultIfEmpty() where a == null select o; /* * var ObseleteOrders = from a in AccountHandler.Accounts() * from o in OrderQuery * .Where(x => a.Identifier.Equals(x.AccountIdentifier) * && * a.GetSymbolInHoldings().Contains(x.Symbol) * ).DefaultIfEmpty() * select o; */ /* * var ObseleteOrders = from o in OrderQuery * from a in AccountHandler.Accounts() * .Where(a => a.Identifier.Equals(o.AccountIdentifier) * && * a.GetSymbolInHoldings().Contains(o.Symbol) * ).DefaultIfEmpty() * select o;*/ int gfgf = ObseleteOrders.Count(); List <IOrder> sds = ObseleteOrders.ToList(); //string[] sdfsd = ObseleteOrders.Select(x => x.Identifier.ToString()).ToArray(); if (ObseleteOrders == null || ObseleteOrders.Count() == 0) { return(true); } RemoveFilesFromStorage(ObseleteOrders.Where(o => o != null).ToList()); m_oOrders.RemoveRange(ObseleteOrders.Where(o => o != null).ToList()); } catch (Exception ex) { ImperaturGlobal.GetLog().Error("Error in OrderQueue.QueueMaintence", ex); } return(true); }
private List <IOrder> GetBuyOrdersFromTradingRecommencation(List <InstrumentRecommendation> TradingRecommendations) { var BuyRecommendations = TradingRecommendations.Where(x => x.TradingRecommendations.Where(tr => tr.TradingForecastMethod != TradingForecastMethod.Undefined && tr.BuyPrice.Amount > 0 && tr.SellPrice.Amount == 0).Count() > 0).ToList(); var BuyForecastMethods = TradingRecommendations.Where(x => x.TradingRecommendations.Where(tr => tr.TradingForecastMethod != TradingForecastMethod.Undefined && tr.BuyPrice.Amount > 0 && tr.SellPrice.Amount == 0).Count() > 0) .Select(x => new { ForeCastMethod = x.TradingRecommendations.First().TradingForecastMethod, Symbol = x.InstrumentInfo.Symbol } ); var BuyCounts = BuyRecommendations.GroupBy(x => x.InstrumentInfo.Symbol) .Select(g => new { g.Key, Count = g.Count() }); var SearchCounts = BuyRecommendations.GroupBy(x => x.InstrumentInfo.Symbol) .Select(g => new { g.Key, Sum = g.Sum(x => x.ExternalSearchHits) }); var VolumeIndicator = BuyRecommendations.Where(x => !x.VolumeIndication.VolumeIndicatorType.Equals(VolumeIndicatorType.VolumeClimaxUp)).GroupBy(x => x.InstrumentInfo.Symbol) .Select(g => new { g.Key, Count = g.Count() }); var CondensedBuyData = from bc in BuyCounts join sc in SearchCounts on bc.Key equals sc.Key join vi in VolumeIndicator on bc.Key equals vi.Key select new { bc.Key, BuyCounts = bc.Count, SearchSum = sc.Sum, VolumeCount = vi.Count }; var BuyDenseRanked = CondensedBuyData .GroupBy(rec => new { rec.Key, rec.SearchSum, rec.BuyCounts, rec.VolumeCount }) .Where(@group => @group.Any()) .OrderBy(@group => @group.Key.BuyCounts) .ThenBy(@group => @group.Key.VolumeCount) .ThenBy(@group => @group.Key.SearchSum) .AsEnumerable() .Select((@group, i) => new { Items = @group, Rank = ++i }) .SelectMany(v => v.Items, (s, i) => new { Item = i, DenseRank = s.Rank }).ToList(); var ActualBuyPositions = from b in BuyDenseRanked join i in ImperaturGlobal.Instruments on b.Item.Key equals i.Symbol select new { SecAnalysis = ImperaturGlobal.Kernel.Get <ISecurityAnalysis>(new Ninject.Parameters.ConstructorArgument("Instrument", i)), }; //här kommer parallellen in igen på accounts return(GetBuyOrdersFromRecommentdationPerAccount(m_oAccountHandler.Accounts().Where(a => a.GetAccountType().Equals(AccountType.Customer)).ToArray(), ActualBuyPositions.Select(ab => ab.SecAnalysis).ToList(), BuyForecastMethods.Select(b => new Tuple <string, string>(b.Symbol, b.ForeCastMethod.ToString())).ToList() )); }