public async Task <IActionResult> ConfirmBuy([Bind("ID,NrOfTradeItems,StockSymbol")] Order trade)
        {
            var identity = User.Identity as System.Security.Claims.ClaimsIdentity;

            _currentUser = identity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;

            trade.TradeDate   = DateTime.Now;
            trade.objectId    = _currentUser;
            trade.OrderStatus = "open";
            trade.Action      = "buy";

            if (ModelState.IsValid)
            {
                _context.Add(trade);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Orders)));
            }
            return(View());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Name,StartDate,BenchmarkId,Description,CreatedOn,ModifiedOn")] Strategy strategy)
        {
            if (ModelState.IsValid)
            {
                _context.Add(strategy);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(strategy));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Date,StockId,Open,High,Low,Close,LastClose,Volume,Amount,Change,ChangePercentage,ContinueTrend,TurnoverRate,CreatedOn,ModifiedOn")] StockPerf stockPerf)
        {
            if (ModelState.IsValid)
            {
                _context.Add(stockPerf);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stockPerf));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,StrategyId,StockId,TXDate,TXPrice,Shares,Amount")] Statement statement)
        {
            if (ModelState.IsValid)
            {
                _context.Add(statement);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StrategyId"] = new SelectList(_context.Strategys, "Id", "Id", statement.StrategyId);
            return(View(statement));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,StrategyId,StockId,CreatedOn,ModifiedOn")] StrategySubject strategySubject)
        {
            if (ModelState.IsValid)
            {
                _context.Add(strategySubject);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StrategyId"] = new SelectList(_context.Strategys, "Id", "Id", strategySubject.StrategyId);
            return(View(strategySubject));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,Name,BriefName,Symbol,Market,Price,Date,Status,Type")] StockInfo stockInfo)
        {
            if (ModelState.IsValid)
            {
                string    id    = string.Format("{0}{1}", stockInfo.Market, stockInfo.Symbol);
                StockInfo exist = _context.StockInfos.Find(id);
                if (exist != null)
                {
                    return(View(stockInfo));
                }
                stockInfo.Id        = id;
                stockInfo.CreatedOn = stockInfo.ModifiedOn = DateTime.Now;
                _context.Add(stockInfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stockInfo));
        }
Ejemplo n.º 7
0
        public void ProcessDataAsync(string market, string symbol)
        {
            log.Info($"start retrieve stock info(market={market},symbol={symbol}");
            string stockInfo = api.GetStockInfo(market + symbol);

            if (String.IsNullOrEmpty(stockInfo))
            {
                log.Warn($"Can not retrieve any data for stock(market={market},symbol={symbol}");
                return;
            }
            log.InfoFormat($"retrieved data({stockInfo}) for stock(market={market},symbol={symbol}");
            string key = $"{market}{symbol}";

            string[] values = stockInfo.Split(new char[] { ',' });
            if (values.Length < 5)
            {
                return;
            }
            StockInfo si = stockDb.StockInfos.Find(key);

            if (si == null)
            {
                si           = new StockInfo();
                si.Id        = key;
                si.CreatedOn = DateTime.Now;
                si.Status    = StockStatus.Active;
                stockDb.Add(si);
            }
            si.Name       = values[0];
            si.Symbol     = symbol;
            si.Market     = market;
            si.Price      = decimal.Parse(values[3]);
            si.Date       = DateTime.Parse(values[30]);
            si.ModifiedOn = DateTime.Now;
            stockDb.SaveChanges();
            log.Info($"successfully retrieved stock info(market={market},symbol={symbol}");
        }
Ejemplo n.º 8
0
 public void AddUser(User item)
 {
     context.Add(item);
     context.SaveChanges();
 }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("Id,Date,Benchmark,BaseAmount,Name")] MasterPortfolio masterPortfolio, string holdings)
        {
            if (masterPortfolio.Benchmark == null || !masterPortfolio.BaseAmount.HasValue)
            {
                return(View(masterPortfolio));
            }
            StockInfo si = _context.StockInfos.Find(masterPortfolio.Benchmark);

            if (si == null)
            {
                return(View(masterPortfolio));
            }
            if (masterPortfolio.BaseAmount.HasValue)
            {
                masterPortfolio.BaseAmount = 100000;
            }
            if (ModelState.IsValid)
            {
                //masterPortfolio.Name = string.Format("{0}-{1}",si.Name,masterPortfolio.Date.ToString("yyyyMMdd"));
                masterPortfolio.Status    = MasterPortfolioStatus.Pending;
                masterPortfolio.CreatedOn = masterPortfolio.ModifiedOn = DateTime.Now;
                _context.Add(masterPortfolio);
                await _context.SaveChangesAsync();

                if (!String.IsNullOrEmpty(holdings))
                {
                    string[] holdingVals = holdings.Split(new char[] { ',', ';' });
                    List <PortfolioHolding> holdingList = new List <PortfolioHolding>();
                    foreach (string val in holdingVals)
                    {
                        if (String.IsNullOrEmpty(val))
                        {
                            continue;
                        }
                        PortfolioHolding ph = new PortfolioHolding()
                        {
                            MasterPortfolioId = masterPortfolio.Id,
                            StockId           = val.Split(new char[] { '_' })[0],
                        };
                        holdingList.Add(ph);
                    }
                    foreach (PortfolioHolding ph in holdingList)
                    {
                        ph.Weight = 100.0m / holdingList.Count;
                        si        = _context.StockInfos.Find(ph.StockId);
                        if (si == null)
                        {
                            return(View(masterPortfolio));
                        }
                        string    key   = String.Format("{0}_{1}", si.Id, masterPortfolio.Date.ToString("yyyyMMdd"));
                        StockPerf price = _context.StockPerfs.Find(key);
                        if (price == null)
                        {
                            return(View(masterPortfolio));
                        }
                        ph.ModifiedOn   = ph.CreatedOn = DateTime.Now;
                        ph.Shares       = (int)Math.Floor(ph.Weight.Value * masterPortfolio.BaseAmount.Value / price.Close.Value / 100 / 100) * 100;//整手
                        ph.ActualWeight = 100 * ph.Shares * price.Close.Value / masterPortfolio.BaseAmount;
                        _context.Add(ph);
                    }
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(masterPortfolio));
        }