Ejemplo n.º 1
0
        private static List <Shape_Indicator> GetSymbolShapes(ctaCOMMON.Charts.Symbol symbol, int shapesCount, bool initializeFromDatabase, out bool shapeUpdate)
        {
            List <Shape_Indicator> shapes = new List <Shape_Indicator>();

            shapeUpdate = false;

            using (ctaDBEntities entities = new ctaDBEntities())
            {
                entities.Database.Connection.Open();
                var shapes_entities = entities.Portfolio_Stock_Shape.Where(pss => pss.portfolio_id == symbol.Portfolio_ID && pss.stock_id == symbol.Symbol_ID);

                if (shapes_entities.Count() != shapesCount)
                {
                    shapeUpdate = true;
                    foreach (var shape_entitie in shapes_entities)
                    {
                        Shape_Indicator shape = Shape_Indicator_Builder.BuildShapeInstance(shape_entitie.Shape.name);
                        shape.ID          = shape_entitie.Id;
                        shape.Color       = shape_entitie.color;
                        shape.Name        = shape_entitie.name;
                        shape.End_Date    = shape_entitie.date2.Value;
                        shape.End_Value   = shape_entitie.value2.Value;
                        shape.Start_Date  = shape_entitie.date1;
                        shape.Start_Value = shape_entitie.value1;
                        shape.Data_Source = symbol.Quotes;
                        shape.ApplyFormula();
                        shapes.Add(shape);
                    }
                }

                entities.Database.Connection.Close();
            }
            return(shapes);
        }
Ejemplo n.º 2
0
        private static List <Chart_Indicator> GetSymbolIndicators(ctaCOMMON.Charts.Symbol symbol, int indicatorsCount, bool initializeFromDatabase, CandelRange candelRange, out bool indicatorUpdate)
        {
            List <Chart_Indicator> indicators = new List <Chart_Indicator>();

            indicatorUpdate = false;

            using (ctaDBEntities entities = new ctaDBEntities())
            {
                entities.Database.Connection.Open();

                var indicators_entities = entities.Portfolio_Stock_Indicator.Where(psi => psi.portfolio_id == symbol.Portfolio_ID && psi.stock_id == symbol.Symbol_ID);

                if (indicators_entities.Count() != indicatorsCount)
                {
                    indicatorUpdate = true;
                    foreach (var indicator_entitie in indicators_entities)
                    {
                        Chart_Indicator indicator = Chart_Indicator_Builder.BuildIndicatorInstance(indicator_entitie.Indicator.name);
                        indicator.ID = indicator_entitie.Id;
                        if (initializeFromDatabase)
                        {
                            indicator.InitializeFromDataBaseValues(symbol.Quotes, indicator_entitie.param1, indicator_entitie.color1, indicator_entitie.param2, indicator_entitie.color2, indicator_entitie.param3, indicator_entitie.color3, candelRange);
                        }
                        indicators.Add(indicator);
                    }
                }

                entities.Database.Connection.Close();
            }

            return(indicators);
        }
Ejemplo n.º 3
0
        public static UserDashboard GetDashboard(string username)
        {
            using (ctaDBEntities entities = new ctaDBEntities())
            {
                UserDashboard result = new UserDashboard(username);
                entities.Database.Connection.Open();

                int    user_id         = UserService.GetUserId(username);
                string user_type       = entities.Tenants.Where(t => t.Id == user_id).Select(t => t.Tenant_Type.Name).First();
                var    user_portfolios = entities.Portfolios.Where(ptfolio => ptfolio.user_id == user_id);

                foreach (var portfolio in user_portfolios)
                {
                    DashboardItem dashboard_item = new DashboardItem()
                    {
                        Portfolio = portfolio.name, Symbols = new List <ctaCOMMON.Charts.Symbol>(), Portfolio_Id = portfolio.Id
                    };
                    foreach (var stock in portfolio.Portfolio_Stock)
                    {
                        List <Candel> quotes       = new List <Candel>();
                        Candel        today_candel = null;
                        foreach (var quote in stock.Stock.Stock_Quote.Where(s => s.date_round < DateTime.Now.AddDays(-1) || user_type != "FREE").OrderBy(itm => itm.date_round))
                        {
                            Candel candel = new Candel()
                            {
                                Date = quote.date_round, Open = quote.opening, Close = quote.closing, Minimun = quote.minimun, Maximun = quote.maximun, Volume = (double)quote.volume
                            };
                            quotes.Add(candel);
                            today_candel = candel;
                        }
                        SymbolIntradiaryInfo symbolIntradiaryInfo = QuotesService.GetSymbolIntradiaryInfo(stock.stock_id);
                        if (today_candel != null)
                        {
                            symbolIntradiaryInfo.Volume  = today_candel.Volume;
                            symbolIntradiaryInfo.Maximun = today_candel.Maximun;
                            symbolIntradiaryInfo.Minimun = today_candel.Minimun;
                        }

                        ctaCOMMON.Charts.Symbol dashboard_item_symbol = new ctaCOMMON.Charts.Symbol()
                        {
                            Symbol_ID = stock.stock_id, Symbol_Name = stock.Stock.symbol, Symbol_Company_Name = stock.Stock.name, Symbol_Market_ID = stock.Stock.Market.Id, Symbol_Market = stock.Stock.Market.name, Quotes = quotes.OrderBy(q => q.Date).ToList(), Intradiary_Info = symbolIntradiaryInfo
                        };
                        dashboard_item.Symbols.Add(dashboard_item_symbol);
                    }

                    result.AddDashboardItem(dashboard_item);
                }

                entities.Database.Connection.Close();

                DashBoardCache = result;
                return(result);
            }
        }
Ejemplo n.º 4
0
        private static ctaCOMMON.Charts.Symbol GetSymbol(int portfolio_id, int symbol_id, ChartRange chartRange, CandelRange candelRange, bool withQuotes)
        {
            if (DashBoardCache != null && DashBoardCache.DashboardItems.Count > 0 && false)
            {
                var symbol = DashBoardCache.DashboardItems.Where(x => x.Portfolio_Id == portfolio_id)
                             .SelectMany(x => x.Symbols)
                             .Where(x => x.Symbol_ID == symbol_id)
                             .FirstOrDefault();

                return(symbol);
            }
            else
            {
                ctaCOMMON.Charts.Symbol symbol = new ctaCOMMON.Charts.Symbol();

                using (ctaDBEntities entities = new ctaDBEntities())
                {
                    entities.Database.Connection.Open();
                    string user_type    = (portfolio_id == 0) ? "FREE" : entities.Portfolios.Where(p => p.Id == portfolio_id).Select(p => p.Tenant.Tenant_Type.Name).First();
                    var    stock_entity = entities.Stocks.Where(s => s.Id == symbol_id).First();

                    symbol.Portfolio_ID        = portfolio_id;
                    symbol.Symbol_ID           = stock_entity.Id;
                    symbol.Symbol_Name         = stock_entity.symbol;
                    symbol.Symbol_Company_Name = stock_entity.name;
                    symbol.Symbol_Market_ID    = stock_entity.market_id;
                    symbol.Symbol_Market       = stock_entity.Market.name;
                    symbol.Intradiary_Info     = QuotesService.GetSymbolIntradiaryInfo(symbol_id);
                    if (withQuotes)
                    {
                        symbol.Quotes = QuotesService.GetSymbolQuotes(symbol.Symbol_ID, chartRange, candelRange, user_type);
                    }

                    entities.Database.Connection.Close();
                }

                return(symbol);
            }
        }
Ejemplo n.º 5
0
        public static List <DashboardItem> GetMenuItems(string username)
        {
            using (ctaDBEntities entities = new ctaDBEntities())
            {
                List <DashboardItem> result = new List <DashboardItem>();

                entities.Database.Connection.Open();

                int user_id = UserService.GetUserId(username);

                var user_portfolios = entities.Portfolios.Where(ptfolio => ptfolio.user_id == user_id);

                foreach (var portfolio in user_portfolios)
                {
                    DashboardItem dashboard_item = new DashboardItem()
                    {
                        Portfolio = portfolio.name, Symbols = new List <ctaCOMMON.Charts.Symbol>(), Portfolio_Id = portfolio.Id
                    };

                    foreach (var stock in portfolio.Portfolio_Stock)
                    {
                        Symbol symbol = new ctaCOMMON.Charts.Symbol()
                        {
                            Symbol_ID = stock.stock_id, Symbol_Name = stock.Stock.symbol
                        };
                        dashboard_item.Symbols.Add(symbol);
                    }

                    result.Add(dashboard_item);
                }

                entities.Database.Connection.Close();

                return(result);
            }
        }