Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("PriceTrendId,ItemName,DateOfUpdate,AveragePrice,LowestPrice,HighestPrice")] PriceTrend priceTrend)
        {
            if (id != priceTrend.PriceTrendId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(priceTrend);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PriceTrendExists(priceTrend.PriceTrendId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(priceTrend));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("PriceTrendId,ItemName,DateOfUpdate,AveragePrice,LowestPrice,HighestPrice")] PriceTrend priceTrend)
        {
            if (ModelState.IsValid)
            {
                _context.Add(priceTrend);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(priceTrend));
        }
Ejemplo n.º 3
0
        void InitializePriceTrend()
        {
            PriceTrend priceTrend = new PriceTrend
            {
                ItemName     = "PS5",
                DateOfUpdate = Convert.ToDateTime("2020-10-02"),
                AveragePrice = 500,
                HighestPrice = 9999,
                LowestPrice  = 1
            };

            context.Add(priceTrend);
        }
Ejemplo n.º 4
0
            public static int GetTrendLength(StockData data, int index, int minPeriod)
            {
                PriceTrend trend = GetPriceTrend(data, index, minPeriod);
                int        i     = 1;

                while (trend == GetPriceTrend(data, index, minPeriod + i))
                {
                    i++;
                    if (index + 1 - minPeriod - i < 0)
                    {
                        break;
                    }
                }
                i--;

                return(minPeriod + i);
            }
Ejemplo n.º 5
0
            public static PriceTrend GetPriceTrend(StockData data, int index, int period)
            {
                int        startIndex = index + 1 - period;
                PriceTrend result     = PriceTrend.Flat;

                if (startIndex >= 0)
                {
                    PriceTrend highTrend = GetTrend(data, index, period, PricePoint.High);
                    PriceTrend lowTrend  = GetTrend(data, index, period, PricePoint.Low);

                    if (highTrend == PriceTrend.Up && lowTrend == PriceTrend.Up)
                    {
                        result = PriceTrend.Up;
                    }
                    if (highTrend == PriceTrend.Down && lowTrend == PriceTrend.Down)
                    {
                        result = PriceTrend.Down;
                    }
                }
                return(result);
            }
Ejemplo n.º 6
0
            private static PriceTrend GetTrend(StockData data, int index, int period, PricePoint pricePoint)
            {
                int        startIndex = index + 1 - period;
                PriceTrend result     = PriceTrend.Flat;

                if (startIndex >= 0)
                {
                    int      sectorCount         = 3;
                    int      sectorSize          = period / sectorCount;
                    double[] sectorSMAs          = new double[sectorCount];
                    int      remaininglastSector = period % sectorSize;

                    //get sector SMAs
                    for (int i = 0; i < sectorCount; i++)
                    {
                        switch (pricePoint)
                        {
                        case PricePoint.Close:
                            sectorSMAs[i] = GetAverage(data, startIndex + i * sectorSize, sectorSize + remaininglastSector, PricePoint.Close);
                            break;

                        case PricePoint.Low:
                            sectorSMAs[i] = GetAverage(data, startIndex + i * sectorSize, sectorSize + remaininglastSector, PricePoint.Low);
                            break;

                        case PricePoint.High:
                            sectorSMAs[i] = GetAverage(data, startIndex + i * sectorSize, sectorSize + remaininglastSector, PricePoint.High);
                            break;

                        case PricePoint.Open:
                            sectorSMAs[i] = GetAverage(data, startIndex + i * sectorSize, sectorSize + remaininglastSector, PricePoint.Open);
                            break;
                        }
                    }

                    //compare sector SMAs
                    double lastSMA = sectorSMAs[0];
                    bool   isUp    = true;
                    bool   isDown  = true;
                    for (int i = 1; i < sectorCount; i++)
                    {
                        if (sectorSMAs[i] < lastSMA)
                        {
                            isUp = false;
                        }
                        if (sectorSMAs[i] > lastSMA)
                        {
                            isDown = false;
                        }
                        lastSMA = sectorSMAs[i];
                    }
                    if (isUp)
                    {
                        result = PriceTrend.Up;
                    }
                    if (isDown)
                    {
                        result = PriceTrend.Down;
                    }
                }
                return(result);
            }
 private SolidColorBrush GetBrush(PriceTrend trend)
 {
     if (trend == PriceTrend.Up)
     {
         return Brushes.LimeGreen;
     }
     else if (trend == PriceTrend.Down)
     {
         return Brushes.OrangeRed;
     }
     else
     {
         return Brushes.Transparent;
     }
 }
 private void SetPriceTrend(string propertyName, string newValue)
 {
     double oldPrice;
     if (!string.IsNullOrEmpty(newValue))
     {
         double newPrice = double.Parse(newValue);
         if (propertyName == "bid")
         {
             if (!string.IsNullOrEmpty(this._BidSchedulerId))
             {
                 this._Scheduler.Remove(this._BidSchedulerId);
             }
             oldPrice = double.Parse(this._Bid);
             if (newPrice > oldPrice)
             {
                 this._BidTrend = PriceTrend.Up;
                 this._BidSchedulerId = this._Scheduler.Add(this.ResetTrendState, "Bid", DateTime.Now.AddSeconds(2));
             }
             else if (newPrice < oldPrice)
             {
                 this._BidTrend = PriceTrend.Down;
                 this._BidSchedulerId = this._Scheduler.Add(this.ResetTrendState, "Bid", DateTime.Now.AddSeconds(2));
             }
             else
             {
                 this._BidTrend = PriceTrend.NoChange;
             }
             this.NotifyPropertyChanged("BidTrendBrush");
         }
         else
         {
             if (!string.IsNullOrEmpty(this._AskSchedulerId))
             {
                 this._Scheduler.Remove(this._AskSchedulerId);
             }
             oldPrice = double.Parse(this._Ask);
             if (newPrice > oldPrice)
             {
                 this._AskTrend = PriceTrend.Up;
                 this._AskSchedulerId = this._Scheduler.Add(this.ResetTrendState, "Ask", DateTime.Now.AddSeconds(2));
             }
             else if (newPrice < oldPrice)
             {
                 this._AskTrend = PriceTrend.Down;
                 this._AskSchedulerId = this._Scheduler.Add(this.ResetTrendState, "Ask", DateTime.Now.AddSeconds(2));
             }
             else
             {
                 this._AskTrend = PriceTrend.NoChange;
             }
             this.NotifyPropertyChanged("AskTrendBrush");
         }
     }
 }
 private void ResetTrendState(object sender, object actionArgs)
 {
     App.MainFrameWindow.Dispatcher.BeginInvoke((Action<string>)delegate(string propName)
     {
         if (propName.Equals("Ask"))
         {
             this._AskTrend = PriceTrend.NoChange;
             this.NotifyPropertyChanged("AskTrendBrush");
             //Logger.AddEvent(TraceEventType.Information, "Ask:{0}, this.AskTrend = PriceTrend.NoChange;", this.Ask);
         }
         else
         {
             this._BidTrend = PriceTrend.NoChange;
             this.NotifyPropertyChanged("BidTrendBrush");
             //Logger.AddEvent(TraceEventType.Information, "Ask:{0}, this.BidTrend = PriceTrend.NoChange;", this.Ask);
         }
     }, (string)actionArgs);
 }
Ejemplo n.º 10
0
        public async Task <IActionResult> CreateSell([Bind("SellListingId,SellerId,PriceTrendId,SellTitle,SellDescription,SellPrice,SellDate,SellItemType,SellQuantity,ImageFile,Display")] SellListing sellListing)
        {
            sellListing.SellDate = DateTime.Now;
            sellListing.Display  = true;
            string userId = "";

            try
            {
                userId = HttpContext.Session.GetString("userId");
            }
            catch (Exception)
            {
                // Do nothing
            }

            // We need the seller ID associated with this account ID
            var sellerAccountId = await _context.SellerAccounts
                                  .Include(s => s.Account)
                                  .FirstOrDefaultAsync(s => s.Account.AccountId.ToString() == userId);

            //Find price trend items with same title as new sell listing title
            var priceTrend = await _context.PriceTrends
                             .Where(m => m.ItemName == sellListing.SellTitle)
                             .ToListAsync();


            if (ModelState.IsValid)
            {
                try
                {
                    sellListing.SellerId = sellerAccountId.SellerId;
                    //Check if a price trend exists for the sell listing, and create one if it does not exist
                    if (priceTrend.Count == 0)
                    {
                        PriceTrend trend = new PriceTrend();
                        trend.ItemName     = sellListing.SellTitle;
                        trend.DateOfUpdate = DateTime.Now;
                        trend.AveragePrice = sellListing.SellPrice;
                        trend.HighestPrice = sellListing.SellPrice;
                        trend.LowestPrice  = sellListing.SellPrice;

                        PriceTrendsController priceTrendsController = new PriceTrendsController(_context);
                        await priceTrendsController.Create(trend);
                    }

                    if (sellListing.ImageFile != null)
                    {
                        //Save image to wwwroot/images
                        string wwwRootPath = _hostEnvironment.WebRootPath;
                        string fileName    = Path.GetFileNameWithoutExtension(sellListing.ImageFile.FileName);
                        string extension   = Path.GetExtension(sellListing.ImageFile.FileName);
                        sellListing.SellImage = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                        string path = Path.Combine(wwwRootPath + "/Images/", fileName);
                        using (var fileStream = new FileStream(path, FileMode.Create))
                        {
                            await sellListing.ImageFile.CopyToAsync(fileStream);
                        }
                    }
                    else
                    {
                        sellListing.SellImage = "buy-icon.png";
                    }

                    _context.Add(sellListing);
                    await _context.SaveChangesAsync();
                }
                catch (Exception)
                {
                    return(RedirectToAction(nameof(Index)));
                }

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

            ViewData["PriceTrendId"] = new SelectList(_context.PriceTrends, "PriceTrendId", "PriceTrendId", sellListing.PriceTrendId);
            ViewData["SellerId"]     = new SelectList(_context.SellerAccounts, "SellerId", "SellerId", sellListing.SellerId);
            return(View(sellListing));
        }