private void GetFeed() { ForexFeeder forexFeeder = new ForexFeeder(_symbol, _interval, _periods, _price); try { List <GlobalPrice> feed = forexFeeder.GetFeed(); SqlServerSaverMgr saver = new SqlServerSaverMgr(_conStr); foreach (var gp in feed) { gp.SaveToEntity(); saver.SaveElement(gp.Entity); gp.Id = (int)saver.Outputs[0]; } TraderPricesChart traderPricesChart = new TraderPricesChart { GlobalPriceId = feed[0].Id }; traderPricesChart.SaveToEntity(); saver.UpdateTraderPricesChart(traderPricesChart.Entity); } catch (Exception ex) { Debug.Assert(true, ex.Message); } }
public void InsertTraderPricesChart(int traderId, DateTime date, decimal buyAvg, decimal sellAvg, decimal buyClose, decimal sellClose) { TraderPricesChart traderPricesChartObj = new TraderPricesChart(); traderPricesChartObj.TraderID = traderId; traderPricesChartObj.Date = date; traderPricesChartObj.BuyAverage = buyAvg; traderPricesChartObj.SellAverage = sellAvg; traderPricesChartObj.BuyClose = buyClose; traderPricesChartObj.SellClose = sellClose; _uow.TraderPricesChartRepo.Add(traderPricesChartObj); }
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 _GoldPricesChart(string chartType, int?pricetype, int?datetype, int global) { int?traderId = null; ViewBag.subtitle = Resources.General.globalmarket; decimal dollarSellPrice = uow.DollarRepo.GetDollarSellPrice(); if (global == 0 && Session["MainTraderChartId"] != null) { if (Session["MainTraderChartId"] == null) { return(RedirectToAction("Index", "Home")); } traderId = Convert.ToInt32(Session["MainTraderChartId"].ToString()); Trader objtrad = uow.TraderRepo.Find(int.Parse(traderId.ToString())); ViewBag.subtitle = objtrad.Name; } CalculateAverageBuySellService service = new CalculateAverageBuySellService(); if (string.IsNullOrEmpty(chartType)) { chartType = "Line"; } ChartType _chartType = new ChartType(); if (chartType == "Column") { ViewBag.ChartType = ChartType.Column; } if (chartType == "Line") { ViewBag.ChartType = ChartType.Line; } if (chartType == "Scatter") { ViewBag.ChartType = ChartType.Scatter; } if (datetype == null) { datetype = 1; } if (pricetype == null) { pricetype = 1; } //if (chartType == "column") ViewBag.ChartType = ChartType.Column; List <string> lstDays = new List <string>(); decimal[] arrdatabuy = { 0 }; decimal[] arrdatasell = { 0 }; List <ChartPoint> lstdatabuy = new List <ChartPoint>(); List <ChartPoint> lstdatasell = new List <ChartPoint>(); if (datetype == 1) { ViewBag.text = Resources.General.goldpricesweek + " " + DateTime.Now.AddDays(-6).ToShortDateString() + " " + Resources.General.to + DateTime.Now.ToShortDateString(); arrdatasell = new decimal[7]; arrdatabuy = new decimal[7]; for (var i = 6; i >= 0; i--) { lstDays.Add("(" + DateTime.Now.AddDays(-i).Day.ToString() + "/" + DateTime.Now.AddDays(-i).Month.ToString() + ")"); TraderPricesChart obj = uow.TraderPricesChartRepo.GetDayPrices(DateTime.Now.AddDays(-i), traderId); if (obj != null) { if (global == 1) { arrdatabuy[6 - i] = pricetype == 1 ? Math.Round(((decimal.Parse(obj.BuyAverage.ToString())) * dollarSellPrice), 2) : Math.Round(((decimal.Parse(obj.BuyClose.ToString())) * dollarSellPrice), 2); arrdatasell[6 - i] = pricetype == 1 ? Math.Round(((decimal.Parse(obj.SellAverage.ToString())) * dollarSellPrice), 2) : Math.Round(((decimal.Parse(obj.SellClose.ToString())) * dollarSellPrice), 2); } else { arrdatabuy[6 - i] = pricetype == 1 ? Math.Round((decimal.Parse(obj.BuyAverage.ToString())), 2) : Math.Round((decimal.Parse(obj.BuyClose.ToString())), 2); arrdatasell[6 - i] = pricetype == 1 ? Math.Round((decimal.Parse(obj.SellAverage.ToString())), 2) : Math.Round((decimal.Parse(obj.SellClose.ToString())), 2); } } else { arrdatabuy[6 - i] = 0; arrdatasell[6 - i] = 0; } } } else if (datetype == 2) { ViewBag.text = Resources.General.goldpricesmonth + " " + DateTime.Now.AddDays(-29).ToShortDateString() + " " + Resources.General.to + DateTime.Now.ToShortDateString(); arrdatasell = new decimal[30]; arrdatabuy = new decimal[30]; for (var i = 29; i >= 0; i--) { lstDays.Add(DateTime.Now.AddDays(-i).Day.ToString()); TraderPricesChart obj = uow.TraderPricesChartRepo.GetDayPrices(DateTime.Now.AddDays(-i), traderId); if (obj != null) { if (global == 1) { arrdatabuy[29 - i] = pricetype == 1 ? Math.Round(((decimal.Parse(obj.BuyAverage.ToString())) * dollarSellPrice), 2) : Math.Round(((decimal.Parse(obj.BuyClose.ToString())) * dollarSellPrice), 2); arrdatasell[29 - i] = pricetype == 1 ? Math.Round(((decimal.Parse(obj.SellAverage.ToString())) * dollarSellPrice), 2) : Math.Round(((decimal.Parse(obj.SellClose.ToString())) * dollarSellPrice), 2); } else { arrdatabuy[29 - i] = pricetype == 1 ? Math.Round((decimal.Parse(obj.BuyAverage.ToString())), 2) : Math.Round((decimal.Parse(obj.BuyClose.ToString())), 2); arrdatasell[29 - i] = pricetype == 1 ? Math.Round((decimal.Parse(obj.SellAverage.ToString())), 2) : Math.Round((decimal.Parse(obj.SellClose.ToString())), 2); } } else { arrdatabuy[29 - i] = 0; arrdatasell[29 - i] = 0; } } } else if (datetype == 3) { ViewBag.text = Resources.General.goldpricesmonth + " " + DateTime.Now.AddDays(-29).ToShortDateString() + " " + Resources.General.to + DateTime.Now.ToShortDateString(); arrdatasell = new decimal[4]; arrdatabuy = new decimal[4]; for (var i = 3; i >= 0; i--) { DateTime weekStart = DateTime.Now; DateTime weekEnd = DateTime.Now; decimal avgBuy, avgSell; decimal closeBuy, closeSell; service.GetWeekStartEnd(DateTime.Now.AddDays(-(i * 7)), out weekStart, out weekEnd); lstDays.Add("(" + weekStart.Day + "/" + weekStart.Month + "-" + weekEnd.Day + "/" + weekEnd.Month + ")"); uow.TraderPricesChartRepo.GetAvgPricesInWeek(weekStart, weekEnd, traderId, out avgBuy, out avgSell); uow.TraderPricesChartRepo.GetClosePricesInWeek(weekStart, weekEnd, traderId, out closeBuy, out closeSell); if (global == 1) { arrdatabuy[3 - i] = pricetype == 1 ? Math.Round((avgBuy * dollarSellPrice), 2) : Math.Round((closeBuy * dollarSellPrice), 2); arrdatasell[3 - i] = pricetype == 1 ? Math.Round((avgSell * dollarSellPrice), 2) : Math.Round((closeSell * dollarSellPrice), 2); } else { arrdatabuy[3 - i] = pricetype == 1 ? Math.Round(avgBuy, 2) : Math.Round(closeBuy, 2); arrdatasell[3 - i] = pricetype == 1 ? Math.Round(avgSell, 2) : Math.Round(closeSell, 2); } } } else if (datetype == 4) { ViewBag.text = Resources.General.goldpricesmonth + " " + DateTime.Now.AddDays(-364).ToShortDateString() + " " + Resources.General.to + DateTime.Now.ToShortDateString(); arrdatasell = new decimal[12]; arrdatabuy = new decimal[12]; for (var i = 11; i >= 0; i--) { DateTime MonthStart = DateTime.Now; DateTime MonthEnd = DateTime.Now; decimal avgBuy, avgSell; decimal closeBuy, closeSell; service.GetMonthStartEnd(DateTime.Now.AddDays(-(i * 30)), out MonthStart, out MonthEnd); lstDays.Add("(" + MonthStart.Day + "/" + MonthStart.Month + "-" + MonthEnd.Day + "/" + MonthEnd.Month + ")"); uow.TraderPricesChartRepo.GetAvgPricesInWeek(MonthStart, MonthEnd, traderId, out avgBuy, out avgSell); uow.TraderPricesChartRepo.GetClosePricesInWeek(MonthStart, MonthEnd, traderId, out closeBuy, out closeSell); if (global == 1) { arrdatabuy[11 - i] = pricetype == 1 ? Math.Round((avgBuy * dollarSellPrice), 2) : Math.Round((closeBuy * dollarSellPrice), 2); arrdatasell[11 - i] = pricetype == 1 ? Math.Round((avgSell * dollarSellPrice), 2) : Math.Round((closeSell * dollarSellPrice), 2); } else { arrdatabuy[11 - i] = pricetype == 1 ? Math.Round(avgBuy, 2) : Math.Round(closeBuy, 2); arrdatasell[11 - i] = pricetype == 1 ? Math.Round(avgSell, 2) : Math.Round(closeSell, 2); } } } ViewBag.Categories = lstDays; ViewBag.Data = new List <ChartPoint>().FromCollection( arrdatabuy); ViewBag.Series = new List <ChartSeriesSettings> { new ChartSeriesSettings { Name = Resources.General.Buy, Data = new List <ChartPoint>().FromCollection(arrdatabuy) }, new ChartSeriesSettings { Name = Resources.General.Sell, Data = new List <ChartPoint>().FromCollection(arrdatasell) } }; return(View("_GoldPricesChart")); }
public ActionResult ViewChart(int?trader, int?buySellType, int?datetype, int?pricetype, string chartType) { CalculateAverageBuySellService service = new CalculateAverageBuySellService(); //if (Session["traderID"] == null) // return RedirectToAction("Index", "Home"); //string[] tradersIds = trader.Split(','); Trader sessionTraderObj = new Trader(); Trader selectedTraderObj = new Trader(); int? traderId = null; //if (Session["traderID"] == null) // return RedirectToAction("Index", "Home"); if (Session["MainTraderChartId"] != null) { traderId = Convert.ToInt32(Session["MainTraderChartId"].ToString()); } else { traderId = 0; } _tradersComparisonVm.TraderList = uow.TraderRepo.GetAll().Where(x => x.TypeFlag == 1 && x.ID != traderId).ToList(); if (trader == null) { if (_tradersComparisonVm.TraderList.Count > 0) { trader = _tradersComparisonVm.TraderList[0].ID; } else { trader = 0; } } if (traderId != null) { sessionTraderObj = uow.TraderRepo.Find(traderId); ViewBag.subtitle = Resources.General.ComparasonTraders + " " + sessionTraderObj.Name + " " + Resources.General.OtherTraders; } if (trader != null) { selectedTraderObj = uow.TraderRepo.Find(trader); } if (string.IsNullOrEmpty(chartType)) { chartType = "Line"; } ChartType _chartType = new ChartType(); if (chartType == "Column") { ViewBag.ChartType = ChartType.Column; } if (chartType == "Line") { ViewBag.ChartType = ChartType.Line; } if (chartType == "Scatter") { ViewBag.ChartType = ChartType.Scatter; } if (datetype == null || datetype == null) { datetype = 1; } if (pricetype == null || pricetype == null) { pricetype = 1; } if (buySellType == 0 || buySellType == null) { buySellType = 1; } List <string> lstDays = new List <string>(); decimal[] arrdataSessionTrader = { 0 }; decimal[] arrdataSelectedTrader = { 0 }; List <ChartPoint> lstdatabuy = new List <ChartPoint>(); List <ChartPoint> lstdatasell = new List <ChartPoint>(); if (datetype == 1) { ViewBag.text = Resources.General.goldpricesweek + " " + DateTime.Now.AddDays(-6).ToShortDateString() + " " + Resources.General.to + DateTime.Now.ToShortDateString(); arrdataSessionTrader = new decimal[7]; arrdataSelectedTrader = new decimal[7]; for (var i = 6; i >= 0; i--) { lstDays.Add("(" + DateTime.Now.AddDays(-i).Day + "/" + DateTime.Now.AddDays(-i).Month + ")"); TraderPricesChart SessiontraderPriceChart = uow.TraderPricesChartRepo.GetDayPrices(DateTime.Now.AddDays(-i), traderId); TraderPricesChart SelectedTraderPriceChart = uow.TraderPricesChartRepo.GetDayPrices(DateTime.Now.AddDays(-i), trader); if (SessiontraderPriceChart == null) { arrdataSessionTrader[6 - i] = 0; } else { if (buySellType == 1) { arrdataSessionTrader[6 - i] = pricetype == 1 ?Math.Round((decimal.Parse(SessiontraderPriceChart.BuyAverage.ToString())), 2) :Math.Round((decimal.Parse(SessiontraderPriceChart.BuyClose.ToString())), 2); } else { arrdataSessionTrader[6 - i] = pricetype == 1 ?Math.Round((decimal.Parse(SessiontraderPriceChart.SellAverage.ToString())), 2) :Math.Round((decimal.Parse(SessiontraderPriceChart.SellClose.ToString())), 2); } } if (SelectedTraderPriceChart == null) { arrdataSelectedTrader[6 - i] = 0; } else { if (buySellType == 1) { arrdataSelectedTrader[6 - i] = pricetype == 1 ?Math.Round((decimal.Parse(SelectedTraderPriceChart.BuyAverage.ToString())), 2) :Math.Round((decimal.Parse(SelectedTraderPriceChart.BuyClose.ToString())), 2); } else { arrdataSelectedTrader[6 - i] = pricetype == 1 ?Math.Round((decimal.Parse(SelectedTraderPriceChart.SellAverage.ToString())), 2) :Math.Round((decimal.Parse(SelectedTraderPriceChart.SellClose.ToString())), 2); } } } } else if (datetype == 2) { ViewBag.text = Resources.General.goldpricesmonth + " " + DateTime.Now.AddDays(-29).ToShortDateString() + " " + Resources.General.to + DateTime.Now.ToShortDateString(); arrdataSessionTrader = new decimal[30]; arrdataSelectedTrader = new decimal[30]; for (var i = 29; i >= 0; i--) { lstDays.Add(DateTime.Now.AddDays(-i).Day.ToString()); TraderPricesChart SessiontraderPriceChart = uow.TraderPricesChartRepo.GetDayPrices(DateTime.Now.AddDays(-i), traderId); TraderPricesChart SelectedTraderPriceChart = uow.TraderPricesChartRepo.GetDayPrices(DateTime.Now.AddDays(-i), trader); if (SessiontraderPriceChart == null) { arrdataSessionTrader[29 - i] = 0; } else { if (buySellType == 1) { arrdataSessionTrader[29 - i] = pricetype == 1 ?Math.Round((decimal.Parse(SessiontraderPriceChart.BuyAverage.ToString())), 2) :Math.Round((decimal.Parse(SessiontraderPriceChart.BuyClose.ToString())), 2); } else { arrdataSessionTrader[29 - i] = pricetype == 1 ?Math.Round((decimal.Parse(SessiontraderPriceChart.SellAverage.ToString())), 2) :Math.Round((decimal.Parse(SessiontraderPriceChart.SellClose.ToString())), 2); } } if (SelectedTraderPriceChart == null) { arrdataSelectedTrader[29 - i] = 0; } else { if (buySellType == 1) { arrdataSelectedTrader[29 - i] = pricetype == 1 ?Math.Round((decimal.Parse(SelectedTraderPriceChart.BuyAverage.ToString())), 2) :Math.Round((decimal.Parse(SelectedTraderPriceChart.BuyClose.ToString())), 2); } else { arrdataSelectedTrader[29 - i] = pricetype == 1 ?Math.Round((decimal.Parse(SelectedTraderPriceChart.SellAverage.ToString())), 2) :Math.Round((decimal.Parse(SelectedTraderPriceChart.SellClose.ToString())), 2); } } } } else if (datetype == 3) { ViewBag.text = Resources.General.goldpricesmonth + " " + DateTime.Now.AddDays(-29).ToShortDateString() + " " + Resources.General.to + DateTime.Now.ToShortDateString(); arrdataSessionTrader = new decimal[4]; arrdataSelectedTrader = new decimal[4]; for (var i = 3; i >= 0; i--) { DateTime weekStart = DateTime.Now; DateTime weekEnd = DateTime.Now; decimal SessionavgBuy, SessionavgSell; decimal SelectedavgBuy, SelectedavgSell; decimal SessioncloseBuy, SessioncloseSell; decimal SelectedcloseBuy, SelectedcloseSell; service.GetWeekStartEnd(DateTime.Now.AddDays(-(i * 7)), out weekStart, out weekEnd); lstDays.Add("(" + weekStart.Day + "/" + weekStart.Month + "-" + weekEnd.Day + "/" + weekEnd.Month + ")"); uow.TraderPricesChartRepo.GetAvgPricesInWeek(weekStart, weekEnd, traderId, out SessionavgBuy, out SessionavgSell); uow.TraderPricesChartRepo.GetAvgPricesInWeek(weekStart, weekEnd, trader, out SelectedavgBuy, out SelectedavgSell); uow.TraderPricesChartRepo.GetClosePricesInWeek(weekStart, weekEnd, traderId, out SessioncloseBuy, out SessioncloseSell); uow.TraderPricesChartRepo.GetClosePricesInWeek(weekStart, weekEnd, trader, out SelectedcloseBuy, out SelectedcloseSell); if (buySellType == 1) { arrdataSessionTrader[3 - i] = pricetype == 1 ?Math.Round(SessionavgBuy, 2) :Math.Round(SessioncloseBuy, 2); arrdataSelectedTrader[3 - i] = pricetype == 1 ?Math.Round(SelectedavgBuy, 2) :Math.Round(SelectedcloseBuy, 2); } else { arrdataSessionTrader[3 - i] = pricetype == 1 ?Math.Round(SessionavgSell, 2) :Math.Round(SessioncloseSell, 2); arrdataSelectedTrader[3 - i] = pricetype == 1 ?Math.Round(SelectedavgSell, 2) :Math.Round(SelectedcloseSell, 2); } } } else if (datetype == 4) { ViewBag.text = Resources.General.goldpricesmonth + " " + DateTime.Now.AddDays(-364).ToShortDateString() + " " + Resources.General.to + DateTime.Now.ToShortDateString(); arrdataSessionTrader = new decimal[12]; arrdataSelectedTrader = new decimal[12]; for (var i = 11; i >= 0; i--) { DateTime MonthStart = DateTime.Now; DateTime MonthEnd = DateTime.Now; decimal SessionavgBuy, SessionavgSell; decimal SelectedavgBuy, SelectedavgSell; decimal SessioncloseBuy, SessioncloseSell; decimal SelectedcloseBuy, SelectedcloseSell; service.GetMonthStartEnd(DateTime.Now.AddDays(-(i * 30)), out MonthStart, out MonthEnd); lstDays.Add("(" + MonthStart.Day + "/" + MonthStart.Month + "-" + MonthEnd.Day + "/" + MonthEnd.Month + ")"); uow.TraderPricesChartRepo.GetAvgPricesInWeek(MonthStart, MonthEnd, traderId, out SessionavgBuy, out SessionavgSell); uow.TraderPricesChartRepo.GetAvgPricesInWeek(MonthStart, MonthEnd, trader, out SelectedavgBuy, out SelectedavgSell); uow.TraderPricesChartRepo.GetClosePricesInWeek(MonthStart, MonthEnd, traderId, out SessioncloseBuy, out SessioncloseSell); uow.TraderPricesChartRepo.GetClosePricesInWeek(MonthStart, MonthEnd, trader, out SelectedcloseBuy, out SelectedcloseSell); if (buySellType == 1) { arrdataSessionTrader[11 - i] = pricetype == 1 ?Math.Round(SessionavgBuy, 2) :Math.Round(SessioncloseBuy, 2); arrdataSelectedTrader[11 - i] = pricetype == 1 ?Math.Round(SelectedavgBuy, 2) :Math.Round(SelectedcloseBuy, 2); } else { arrdataSessionTrader[11 - i] = pricetype == 1 ?Math.Round(SessionavgSell, 2) :Math.Round(SessioncloseSell, 2); arrdataSelectedTrader[11 - i] = pricetype == 1 ?Math.Round(SelectedavgSell, 2) :Math.Round(SelectedcloseSell, 2); } } } ViewBag.Categories = lstDays; ViewBag.Series = new List <ChartSeriesSettings> { new ChartSeriesSettings { Name = sessionTraderObj == null?"": sessionTraderObj.Name, Data = new List <ChartPoint>().FromCollection(arrdataSessionTrader) }, new ChartSeriesSettings { Name = selectedTraderObj == null?"اختر تاجر": selectedTraderObj.Name, Data = new List <ChartPoint>().FromCollection(arrdataSelectedTrader) } }; return(View("_Chart")); }