public void CanGetBuyOrSellFromTraderGeneralPricesList() { ClearReatedTables(); TraderPrices tp = new TraderPrices() { TraderID = 1, BuyPrice = 100M, SellPrice = 200M, priceDate = DateTime.Now }; Uow.TradePricesRepo.Add(tp); Basket basket = AddTestBasket(); BasketPrices aPrice = AddPriceToTraderBasket(basket.ID, 1400.0M, 7000.0M, DateTime.Now.AddDays(-1), false); BasketPrices bPrice = AddPriceToTraderBasket(basket.ID, 1500.0M, 8000.0M, DateTime.Now.AddDays(-1), false); Uow.BasketPricesRepo.Add(aPrice); Uow.BasketPricesRepo.Add(bPrice); Uow.SaveChanges(); var state = Uow.BasketPricesRepo.CheckPrices("", "", aPrice); Assert.AreEqual(0, state); }
public void CanGetBasketSellPrice() { ClearReatedTables(); Basket b = AddTestBasket(); TraderPrices tp = new TraderPrices() { TraderID = 1, BuyPrice = 100M, SellPrice = 200M, priceDate = DateTime.Now }; _uow.TradePricesRepo.Add(tp); BasketPrices aPrice = AddPriceToTraderBasket(b.ID, 1400.0M, 7000.0M, DateTime.Now.AddDays(-1), false); BasketPrices bPrice = AddPriceToTraderBasket(b.ID, 1500.0M, 8000.0M, DateTime.Now, true); _uow.BasketPricesRepo.Add(aPrice); _uow.BasketPricesRepo.Add(bPrice); _uow.SaveChanges(); var lastValue = _uow.BasketPricesRepo.GetLastBuySellPriceToday(b.ID, "s"); Assert.AreEqual(8000.0M, lastValue); }
public void CanAddPrice() { DeleteAllPrices(); TraderPrices openingBalance = AddPriceToTrader(1, 12.9M, 12.8M,DateTime.Now); uow.TradePricesRepo.Add(openingBalance); uow.SaveChanges(); Assert.AreEqual(1, uow.TradePricesRepo.GetAll().Count); }
public void CanCheckPricesNoPriceForTodayAndNullSell() { DeleteAllPrices(); uow.SaveChanges(); TraderPrices openingBalance = new TraderPrices() { TraderID = 1 }; int res = uow.TradePricesRepo.CheckPrices("2", "", openingBalance); Assert.AreEqual(3, res); }
private TraderPrices AddPriceToTrader(int traderID, decimal buyPrice, decimal sellPrice,DateTime date) { TraderPrices tp = new TraderPrices() { TraderID = traderID, BuyPrice = buyPrice, SellPrice = sellPrice, priceDate = date, }; return tp; }
public void CanGetCurrentSell() { DeleteAllPrices(); TraderPrices openingBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.10M, sellPrice: 2.00M, date: DateTime.Now); _uow.TradePricesRepo.Add(openingBalance); _uow.SaveChanges(); decimal currentSell = _uow.PriceViewerRepo.GetCurrentSell(1); Assert.AreEqual(2.00, double.Parse(currentSell.ToString(CultureInfo.InvariantCulture))); }
public void CanCheckPriceswithPriceForTodayAndNullSell() { DeleteAllPrices(); TraderPrices openingBalance = AddPriceToTrader(1, 12.9M, 12.8M, DateTime.Now); uow.TradePricesRepo.Add(openingBalance); uow.SaveChanges(); TraderPrices price1 = new TraderPrices() { TraderID = 1 }; int res = uow.TradePricesRepo.CheckPrices("2", "", price1); Assert.AreEqual(0, res); }
public void CanGetAllTodayTraderPrices() { DeleteAllPrices(); TraderPrices openingBalance = AddPriceToTrader(1, 12.9M, 12.8M, DateTime.Now); TraderPrices price1 = AddPriceToTrader(1, 1234.9M, 5345.8M, DateTime.Now); TraderPrices price2 = AddPriceToTrader(1, 1234.9M, 5345.8M, DateTime.Now.AddDays(-1)); uow.TradePricesRepo.Add(openingBalance); uow.TradePricesRepo.Add(price1); uow.TradePricesRepo.Add(price2); uow.SaveChanges(); Assert.AreEqual(2, uow.TradePricesRepo.FindByTrader(1).Count); }
public void CanGetTraderMaxBuyPriceDayBefore() { DeleteAllPrices(); TraderPrices openingBalance = AddPriceToTrader(1, 12.9M, 12.8M, DateTime.Now.AddDays(-1)); TraderPrices price1 = AddPriceToTrader(1, 114.9M, 5345.88M, DateTime.Now); TraderPrices price2 = AddPriceToTrader(1, 1234.9M, 5345.8M, DateTime.Now.AddDays(-1)); uow.TradePricesRepo.Add(openingBalance); uow.TradePricesRepo.Add(price1); uow.TradePricesRepo.Add(price2); uow.SaveChanges(); decimal price = uow.TradePricesRepo.GetBasketMaxBuyPrice(1, DateTime.Now.Date.AddDays(-1)); Assert.AreEqual(1234.9M, price); }
public void CanGetMinSellPerTrader() { DeleteAllPrices(); TraderPrices openingBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.10M, sellPrice: 2.10M, date: DateTime.Now); TraderPrices secondBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.90M, sellPrice: 2.90M, date: DateTime.Now); _uow.TradePricesRepo.Add(openingBalance); _uow.TradePricesRepo.Add(secondBalance); _uow.SaveChanges(); decimal minSellPerTrader = _uow.PriceViewerRepo.GetMinSellPerTrader(1); Assert.AreEqual(2.10, double.Parse(minSellPerTrader.ToString(CultureInfo.InvariantCulture))); }
public void CanGetAllPrices() { DeleteAllPrices(); TraderPrices yesterdayBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.50M, sellPrice: 2.00M, date: DateTime.Now.AddDays(-1)); TraderPrices openingBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.10M, sellPrice: 2.50M, date: DateTime.Now); TraderPrices secondBalance = AddPriceToTrader(traderId: 2, buyPrice: 1.90M, sellPrice: 2.30M, date: DateTime.Now); _uow.TradePricesRepo.Add(yesterdayBalance); _uow.TradePricesRepo.Add(openingBalance); _uow.TradePricesRepo.Add(secondBalance); _uow.SaveChanges(); List <Prices> pricesLst = (List <Prices>)_uow.PriceViewerRepo.GetAllPrices(0); Assert.AreEqual(2.5, double.Parse(pricesLst[0].CurrentSell.ToString(CultureInfo.InvariantCulture))); }
public void CanGetCurrentBestBuyForApplicationHeader() { DeleteAllPrices(); TraderPrices aBalance = AddPriceToTrader(1, 1.50M, 2.00M, DateTime.Now); TraderPrices bBalance = AddPriceToTrader(2, 1.10M, 2.50M, DateTime.Now); TraderPrices cBalance = AddPriceToTrader(3, 1.90M, 2.30M, DateTime.Now); _uow.TradePricesRepo.Add(aBalance); _uow.TradePricesRepo.Add(bBalance); _uow.TradePricesRepo.Add(cBalance); _uow.SaveChanges(); decimal bestSell = _uow.PriceViewerRepo.GetCurrentBestBuy(); Assert.AreEqual(1.90M, bestSell); }
public void CanGetLastPriceDate() { DeleteAllPrices(); TraderPrices yesterdayBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.50M, sellPrice: 2.00M, date: DateTime.Now.AddDays(-1)); TraderPrices openingBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.10M, sellPrice: 2.50M, date: DateTime.Now); TraderPrices secondBalance = AddPriceToTrader(traderId: 2, buyPrice: 1.90M, sellPrice: 2.30M, date: DateTime.Now); _uow.TradePricesRepo.Add(yesterdayBalance); _uow.TradePricesRepo.Add(openingBalance); _uow.TradePricesRepo.Add(secondBalance); _uow.SaveChanges(); DateTime lastPriceDate = _uow.PriceViewerRepo.GetLastPriceDate(1); Assert.AreEqual(DateTime.Now.ToShortDateString(), lastPriceDate.ToShortDateString()); }
public void CanGetTraderWithMinSell() { DeleteAllPrices(); TraderPrices yesterdayBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.50M, sellPrice: 2.00M, date: DateTime.Now.AddDays(-1)); TraderPrices openingBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.10M, sellPrice: 2.50M, date: DateTime.Now); TraderPrices secondBalance = AddPriceToTrader(traderId: 2, buyPrice: 1.90M, sellPrice: 2.30M, date: DateTime.Now); _uow.TradePricesRepo.Add(yesterdayBalance); _uow.TradePricesRepo.Add(openingBalance); _uow.TradePricesRepo.Add(secondBalance); _uow.SaveChanges(); int traderId = _uow.PriceViewerRepo.GetTraderWithMinSell(); Assert.AreEqual(2, traderId); }
public void CanGetOpenBuy() { DeleteAllPrices(); TraderPrices yesterdayBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.50M, sellPrice: 2.50M, date: DateTime.Now.AddDays(-1)); TraderPrices openingBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.10M, sellPrice: 2.10M, date: DateTime.Now); TraderPrices secondBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.90M, sellPrice: 2.90M, date: DateTime.Now); _uow.TradePricesRepo.Add(yesterdayBalance); _uow.TradePricesRepo.Add(openingBalance); _uow.TradePricesRepo.Add(secondBalance); _uow.SaveChanges(); decimal openBuy = _uow.PriceViewerRepo.GetOpenBuy(1); Assert.AreEqual(1.10, double.Parse(openBuy.ToString(CultureInfo.InvariantCulture))); }
public void CanGetTraderPricesForCertainDay() { DeleteAllPrices(); TraderPrices openingBalance = AddPriceToTrader(1, 12.9M, 12.8M, DateTime.Now); TraderPrices price1 = AddPriceToTrader(1, 1234.9M, 5345.8M, DateTime.Now); TraderPrices price2 = AddPriceToTrader(1, 1244.9M, 56865.8M, DateTime.Now.AddDays(-1)); uow.TradePricesRepo.Add(openingBalance); uow.TradePricesRepo.Add(price1); uow.TradePricesRepo.Add(price2); uow.TradePricesRepo.Add(AddPriceToTrader(1, 122.9M, 5333.8M, DateTime.Now.AddDays(-1))); uow.SaveChanges(); List<TraderPrices> tp= uow.TradePricesRepo.GetDayPrices(DateTime.Now.AddDays(-1), 1); Assert.AreEqual(2,tp.Count); }
public void CanGetAllPricesWithoutFav() { DeleteAllPrices(); DeleteTraders(); TraderPrices yesterdayBalance = AddPriceToTrader(1, 1.50M, 2.00M, DateTime.Now.AddDays(-1)); TraderPrices openingBalance = AddPriceToTrader(1, 1.10M, 2.50M, DateTime.Now); TraderPrices secondBalance = AddPriceToTrader(2, 1.90M, 2.30M, DateTime.Now); _uow.TradePricesRepo.Add(yesterdayBalance); _uow.TradePricesRepo.Add(openingBalance); _uow.TradePricesRepo.Add(secondBalance); _uow.SaveChanges(); List <Prices> pricesLst = (List <Prices>)_uow.PriceViewerRepo.GetAllPrices(1); Assert.AreEqual(10, pricesLst.Count); }
public void CanGetTradersWithMinSell() { DeleteAllPrices(); TraderPrices firstBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.90M, sellPrice: 2.50M, date: DateTime.Now); TraderPrices newerBalance = AddPriceToTrader(traderId: 1, buyPrice: 1.90M, sellPrice: 2.90M, date: DateTime.Now.AddHours(1)); TraderPrices secondBalance = AddPriceToTrader(traderId: 2, buyPrice: 1.90M, sellPrice: 2.50M, date: DateTime.Now); TraderPrices thirddayBalance = AddPriceToTrader(traderId: 3, buyPrice: 1.90M, sellPrice: 2.50M, date: DateTime.Now); _uow.TradePricesRepo.Add(firstBalance); _uow.TradePricesRepo.Add(newerBalance); _uow.TradePricesRepo.Add(secondBalance); _uow.TradePricesRepo.Add(thirddayBalance); _uow.SaveChanges(); List <TraderPrices> allWithMaxBuy = _uow.PriceViewerRepo.GetTradersWithMinSell(_uow.TraderRepo.GetAll()); Assert.AreEqual(2, allWithMaxBuy.Count); }
public void CanGetTheLastSellPriceInDay() { DeleteAllPrices(); TraderPrices openingBalance = AddPriceToTrader(1, 12.9M, 12.8M, DateTime.Now); TraderPrices price1 = AddPriceToTrader(1, 114.9M, 5345.8M, DateTime.Now); TraderPrices price2 = AddPriceToTrader(1, 1234.9M, 5345.8M, DateTime.Now.AddDays(-1)); uow.TradePricesRepo.Add(openingBalance); uow.TradePricesRepo.Add(price1); uow.TradePricesRepo.Add(price2); uow.SaveChanges(); var sell = ""; TraderPrices emptyBuyPrice = AddPriceToTrader(1, 23.3M, sell == "" ? uow.TradePricesRepo.GetLastBuySellPriceToday(1, "s") : Convert.ToDecimal(sell), DateTime.Now); uow.TradePricesRepo.Add(emptyBuyPrice); uow.SaveChanges(); decimal x =Convert.ToDecimal( uow.TradePricesRepo.Find(emptyBuyPrice.ID).SellPrice); Assert.AreEqual(5345.8M, x); }
public int CheckPrices(string buyPrice, string sellPrice, TraderPrices objTPrice) { int res = 0; decimal buy = 0M, sell = 0M; if (buyPrice == "") { buy = GetLastBuySellPriceToday(objTPrice.TraderID, "b"); objTPrice.BuyPrice = buy; res = buy == 0M ? 2 : 0; } if (sellPrice == "") { sell = GetLastBuySellPriceToday(objTPrice.TraderID, "s"); objTPrice.SellPrice = sell; res = sell == 0M ? 3 : 0; } return(res); }
public void CanGetAllPricesFavOnly() { DeleteAllPrices(); int[] superTraderIds = new int[2]; superTraderIds[0] = 1; superTraderIds[1] = 2; _favLstSrvc.SaveAssignedUsers(11, superTraderIds); TraderPrices yesterdayBalance = AddPriceToTrader(1, 1.50M, 2.00M, DateTime.Now.AddDays(-1)); TraderPrices openingBalance = AddPriceToTrader(1, 1.10M, 2.50M, DateTime.Now); TraderPrices secondBalance = AddPriceToTrader(2, 1.90M, 2.30M, DateTime.Now); _uow.TradePricesRepo.Add(yesterdayBalance); _uow.TradePricesRepo.Add(openingBalance); _uow.TradePricesRepo.Add(secondBalance); _uow.SaveChanges(); List <Prices> pricesLst = (List <Prices>)_uow.PriceViewerRepo.GetAllPrices(11, true); Assert.AreEqual(2, pricesLst.Count); }
public ActionResult Create(string sellPrice, string buyPrice) { //if (Session["traderID"] == null) // return RedirectToAction("Index", "Home"); int traderId = GetLoggedTraderOrUser();// Convert.ToInt32(Session["traderID"].ToString()); if (sellPrice == "0.00" || buyPrice == "0.00") { return(new HttpStatusCodeResult(1, Messages.ZeroPrice)); } TraderPrices traderprice = new TraderPrices() { TraderID = traderId, priceDate = DateTime.Now }; if (string.IsNullOrEmpty(sellPrice) || string.IsNullOrEmpty(buyPrice)) { int objState = _uow.TradePricesRepo.CheckPrices(buyPrice, sellPrice, traderprice); if (sellPrice == "" && buyPrice == "" && objState > 0) { return(new HttpStatusCodeResult(3, Messages.NoPriceBefore)); } else if (sellPrice == "" && buyPrice == "" && objState == 0) { return(new HttpStatusCodeResult(2, Messages.nullablePrices)); } if (objState == 2 || objState == 3) { return(new HttpStatusCodeResult(3, Messages.NoPriceBefore)); } else { traderprice.BuyPrice = buyPrice == "" ? _uow.TradePricesRepo.GetLastBuySellPriceToday(traderprice.TraderID, "b") : Convert.ToDecimal(buyPrice); traderprice.SellPrice = sellPrice == "" ? _uow.TradePricesRepo.GetLastBuySellPriceToday(traderprice.TraderID, "s") : Convert.ToDecimal(sellPrice); } } else { traderprice.BuyPrice = Convert.ToDecimal(buyPrice); traderprice.SellPrice = Convert.ToDecimal(sellPrice); } if (ModelState.IsValid) { traderprice.priceDate = DateTime.Now.ToLocalTime(); _uow.TradePricesRepo.Add(traderprice); List <TraderPrices> lst = _uow.TradePricesRepo.GetDayPrices(traderprice.priceDate, traderprice.TraderID); TraderPricesChart newobj = _uow.TraderPricesChartRepo.GetDayPrices(traderprice.priceDate, traderprice.TraderID); decimal buyAvg = 0; decimal sellAvg = 0; if (newobj == null) { newobj = new TraderPricesChart(); } if (lst.Count == 0) { newobj.BuyAverage = traderprice.BuyPrice; newobj.SellAverage = traderprice.SellPrice; } else { foreach (TraderPrices price in lst) { buyAvg += decimal.Parse(price.BuyPrice.ToString()); sellAvg += decimal.Parse(price.SellPrice.ToString()); } newobj.BuyAverage = (buyAvg + traderprice.BuyPrice) / (lst.Count + 1); newobj.SellAverage = (sellAvg + traderprice.SellPrice) / (lst.Count + 1); } newobj.BuyClose = traderprice.BuyPrice; newobj.SellClose = traderprice.SellPrice; if (newobj.ID == 0) { newobj.TraderID = traderprice.TraderID; newobj.Date = traderprice.priceDate; _uow.TraderPricesChartRepo.Add(newobj); } else if (newobj.ID != 0) { _uow.TraderPricesChartRepo.Update(newobj); } _uow.SaveChanges(); decimal minBuy = _uow.TradePricesRepo.GetTraderMinBuyPrice(traderId); decimal maxSell = _uow.TradePricesRepo.GetTraderMaxSellPrice(traderId); //call the hub to broadcast the price changes to all clients IHubContext context = GlobalHost.ConnectionManager.GetHubContext <PricesHub>(); context.Clients.All.updatePrices(); context.Clients.All.updateHeader(); return(Json(new { traderprice, maxSell, minBuy }, JsonRequestBehavior.AllowGet)); } else { return(new HttpStatusCodeResult(404, Messages.UpdateFailed)); } }
public ActionResult ValidateIsBetterPrice(string sellPrice, string buyPrice) { if (Session["BasketID"] == null) { return(RedirectToAction("Index", "Home")); } int res = 0; if (string.IsNullOrEmpty(sellPrice) && string.IsNullOrEmpty(buyPrice)) { res = 1; } int basketId = Convert.ToInt32(Session["BasketID"].ToString()); Basket basket = _uow.BasketRepo.Find(basketId); List <TraderPrices> traderPrices = _uow.TradePricesRepo.FindByTrader(basket.BasketOwner); TraderPrices currentPrice = traderPrices.LastOrDefault(); decimal userBuyPrice = 0M, userSellPrice = 0M; if (currentPrice == null) { res = 1; } if (res != 1) { if (string.IsNullOrEmpty(buyPrice)) { userBuyPrice = _uow.BasketPricesRepo.GetLastBuySellPriceToday(basketId, "b"); } else { var string2Decimal = Helpers.UsefulMethods.string2decimal(buyPrice); if (string2Decimal != null) { userBuyPrice = string2Decimal.Value; } } if (string.IsNullOrEmpty(sellPrice)) { userSellPrice = _uow.BasketPricesRepo.GetLastBuySellPriceToday(basketId, "s"); } else { var string2Decimal = Helpers.UsefulMethods.string2decimal(sellPrice); if (string2Decimal != null) { userSellPrice = string2Decimal.Value; } } // ReSharper disable once PossibleNullReferenceException if (userBuyPrice < currentPrice.BuyPrice) { res = 2; } else if (userSellPrice > currentPrice.SellPrice) { res = 3; } if (userBuyPrice == currentPrice.BuyPrice && userSellPrice == currentPrice.SellPrice) { res = 4; } } return(Json(new { isBetter = res, crntBuy = currentPrice == null ? 0 : currentPrice.BuyPrice, crntSell = currentPrice == null ? 0 : currentPrice.SellPrice }, JsonRequestBehavior.AllowGet)); }