Beispiel #1
0
        public async Task <ManagerResult <Quote> > Add(Quote quote)
        {
            ManagerResult <Quote> mgrResult = new ManagerResult <Quote>();

            try
            {
                if (eqMgr.Get(quote.EquityId).Result.Entity == default(Equity))
                {
                    using (NpgsqlConnection db = new NpgsqlConnection(base.connString))
                    {
                        await db.InsertAsync(quote);
                    }
                }
                else
                {
                    quote = new Quote();
                }
            }
            catch (Exception ex)
            {
                mgrResult.Exception = ex;
                Log.Error("QuoteManager::Add", ex);
            }

            return(mgrResult);
        }
        public async Task <ManagerResult <List <ModelEquity> > > GetModelEquityListByDate(Guid modelId, DateTime quoteDate, int versionNumber = 0)
        {
            ManagerResult <List <ModelEquity> > mgrResult = new ManagerResult <List <ModelEquity> >();

            try
            {
                UserModel thisModel = GetModel(modelId, versionNumber).Result.Entity;

                decimal startValue = thisModel.StartValue;

                using (NpgsqlConnection db = new NpgsqlConnection(connString))
                {
                    List <ModelEquity> modelEquityList = db.QueryAsync <ModelEquity>(@" SELECT * 
                                                    FROM model_equities 
                                                    WHERE model_id = @p1 and version = @p2",
                                                                                     new { p1 = modelId, p2 = thisModel.Version }).Result.ToList();

                    foreach (ModelEquity modelEquity in modelEquityList)
                    {
                        modelEquity.Equity = eqMgr.Get(modelEquity.EquityID).Result.Entity;
                        Quote quote = qMgr.GetByEquityIdAndDate(modelEquity.EquityID, quoteDate).Result.Entity;
                        if (quote != null)
                        {
                            modelEquity.LastPrice     = quote.Price;
                            modelEquity.LastPriceDate = quote.Date;
                            modelEquity.CurrentValue  = Math.Round((modelEquity.Shares * quote.Price), 2);
                        }
                    }

                    mgrResult.Entity = modelEquityList;
                }
            }
            catch (Exception ex)
            {
                mgrResult.Exception = ex;
            }

            return(mgrResult);
        }