コード例 #1
0
        public IActionResult GetPricePredictionViewComponent(int id, bool isDisabled, string coinBase)
        {
            var viewModel = new PricePredictionViewComponentViewModel();

            viewModel.Id         = id;
            viewModel.IsDisabled = isDisabled;
            viewModel.SysUserId  = HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser")?.Id;
            viewModel.Coinbase   = coinBase;
            viewModel.BTCPricePredictionChartTitle = ((EnumCurrencyPair)Enum.Parse(typeof(EnumCurrencyPair), coinBase)) == EnumCurrencyPair.BTCUSDT ? LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "BTCPricePredictionChartTitle") : ""; // TODO: Add more chart title if there are more coinbases
            viewModel.BTCPricePredictionSeriesName = ((EnumCurrencyPair)Enum.Parse(typeof(EnumCurrencyPair), coinBase)) == EnumCurrencyPair.BTCUSDT ? LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "BTCPricePredictionSeriesName") : ""; // TODO: Add more chart title if there are more coinbases
            if (viewModel.SysUserId.HasValue)
            {
                viewModel.TokenAmount = _sysUserService.Queryable().FirstOrDefault(x => x.Id == viewModel.SysUserId).TokenAmount;
            }
            return(ViewComponent("PricePrediction", viewModel));
        }
コード例 #2
0
        public IViewComponentResult Invoke(PricePredictionViewComponentViewModel viewModel)
        {
            var tokenAmount    = viewModel.TokenAmount;
            var predictedTrend = viewModel.PredictedTrend;
            var isDisabled     = viewModel.IsDisabled;
            var coinBase       = viewModel.Coinbase;

            viewModel = _pricePredictionService.Queryable().Where(x => x.Id == viewModel.Id)
                        .Select(x => Mapper.Map <PricePredictionViewComponentViewModel>(x)).FirstOrDefault();
            viewModel.TokenAmount    = tokenAmount;
            viewModel.PredictedTrend = predictedTrend;
            viewModel.IsDisabled     = isDisabled;
            viewModel.BTCPricePredictionChartTitle = ((EnumCurrencyPair)Enum.Parse(typeof(EnumCurrencyPair), coinBase)) == EnumCurrencyPair.BTCUSDT ? LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "BTCPricePredictionChartTitle") : ""; // TODO: Add more chart title if there are more coinbases
            viewModel.BTCPricePredictionSeriesName = ((EnumCurrencyPair)Enum.Parse(typeof(EnumCurrencyPair), coinBase)) == EnumCurrencyPair.BTCUSDT ? LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "BTCPricePredictionSeriesName") : ""; // TODO: Add more chart title if there are more coinbases

            //Calculate percentage
            decimal highPrediction = _pricePredictionHistoryService
                                     .Queryable()
                                     .Where(x => x.PricePredictionId == viewModel.Id && x.Prediction == EnumPricePredictionStatus.HIGH.ToBoolean() && x.Result != EnumGameResult.REFUND.ToString())
                                     .Count();

            decimal lowPrediction = _pricePredictionHistoryService
                                    .Queryable()
                                    .Where(x => x.PricePredictionId == viewModel.Id && x.Prediction == EnumPricePredictionStatus.LOW.ToBoolean() && x.Result != EnumGameResult.REFUND.ToString())
                                    .Count();


            if (highPrediction + lowPrediction == 0)
            {
                viewModel.HighPercentage = viewModel.LowPercentage = 50;
            }
            else
            {
                viewModel.HighPercentage = Math.Round((highPrediction / (highPrediction + lowPrediction) * 100), 2);
                viewModel.LowPercentage  = 100 - viewModel.HighPercentage;
            }
            //////////////////////////

            var btcCurrentPriceResult = ServiceClient.BTCCurrentPriceClient.GetBTCCurrentPriceAsync();

            btcCurrentPriceResult.Wait();
            if (btcCurrentPriceResult.Result.Status.Code == 0)
            {
                viewModel.CurrentBTCRate         = btcCurrentPriceResult.Result.Price;
                viewModel.CurrentBTCRateInString = btcCurrentPriceResult.Result.Price.ToString("#,##0.00");
            }

            // Get btc previous rates 12h before until now
            var btcPriceInUTC = _btcPriceService.Queryable()
                                .Where(x => x.Time >= viewModel.OpenBettingTime.AddHours(-CPLConstant.HourBeforeInChart).ToUTCUnixTimeInSeconds())
                                .ToList();
            var lowestRate = btcPriceInUTC.Min(x => x.Price) - CPLConstant.LowestRateBTCInterval;

            if (lowestRate < 0)
            {
                lowestRate = 0;
            }
            viewModel.PreviousBtcRate = JsonConvert.SerializeObject(btcPriceInUTC);
            viewModel.LowestBtcRate   = lowestRate;
            return(View(viewModel));
        }