public Match Predict(Match match) { try { using (var ctx = new FootballEntities()) { var matchDb = ctx.Matches.First(m => m.Id == match.Id); string home = ctx.Teams.First(t => t.Id == matchDb.HomeId).Name; string away = ctx.Teams.First(t => t.Id == matchDb.AwayId).Name; RatioModel ratio = Calculator.CalculateTeamsRatio(home, away, match.Date); var res = Machine.PredictScore(ratio); matchDb.HomeGoalsPredicted = res.Item1; matchDb.AwayGoalsPredicted = res.Item2; ctx.SaveChanges(); return(matchDb); } } catch (Exception e) { logger.Error(string.Format("Error while predicting match: homeId = {0}, awayId = {1}, date = {2}", match.HomeId, match.AwayId, match.Date), e); return(null); } }
public RatioModel CalculateTeamsRatio(string home, string away, DateTime date) { RatioModel rm = new RatioModel(); rm.HOR = CalculateOffensiveRatio(GetArchiveScores(home, date)); rm.HDR = CalculateDefensiveRatio(GetArchiveScores(home, date)); rm.AOR = CalculateOffensiveRatio(GetArchiveScores(away, date)); rm.ADR = CalculateDefensiveRatio(GetArchiveScores(away, date)); rm.HORH = CalculateOffensiveRatio(GetArchiveScores(home, true, date)); rm.HDRH = CalculateDefensiveRatio(GetArchiveScores(home, true, date)); rm.AORA = CalculateOffensiveRatio(GetArchiveScores(away, false, date)); rm.ADRA = CalculateDefensiveRatio(GetArchiveScores(away, false, date)); return(rm); }
/// <summary> /// Метод возвращает RatioModel с данными полученными из Insurance.BL.Models.Ratio. /// </summary> /// <param name="policy">Insurance.BL.Models.Ratio по которому берутся данные.</param> /// <returns>RatioModel с данными из Insurance.BL.Models.Ratio. /// Если Ratio == null, метод вернет null.</returns> public RatioModel RatioToRatioModel(Ratio ratio) { if (ratio == null) { return(null); } var ratioModel = new RatioModel() { CarAge = ratio.CarAge, DrivingExperience = ratio.DrivingExperience, DriverAge = ratio.DriverAge, EnginePower = ratio.EnginePower }; return(ratioModel); }
/// <summary> /// Метод возвращает Insurance.BL.Models.Ratio с данными полученными из RatioModel. /// </summary> /// <param name="policyModel">RatioModel по которому берутся данные.</param> /// <returns>Insurance.BL.Models.Ratio с данными из RatioModel. /// Если ratioModel == null, метод вернет null.</returns> public Ratio RatioModelToRatio(RatioModel ratioModel) { if (ratioModel == null) { return(null); } var ratio = new Ratio ( ratioModel.CarAge, ratioModel.DrivingExperience, ratioModel.DriverAge, ratioModel.EnginePower ); return(ratio); }
/// <summary> /// Метод возвращает PolicyModel с данными полученными из Insurance.BL.Models.Policy. /// </summary> /// <param name="policy">Insurance.BL.Models.Policy по которому берутся данные.</param> /// <returns>PolicyModel с данными из Insurance.BL.Models.Policy. Свойство Client = null.</returns> public PolicyModel PolicyToPolicyModel(Policy policy) { if (policy == null) { return(null); } CarModel carModel = null; RatioModel ratioModel = null; if (policy.Car != null) { var carRepository = new CarRepository(_context); carModel = carRepository.CarToCarModel(policy.Car); } if (policy.Ratio != null) { var ratioRepository = new RatioRepository(_context); ratioModel = ratioRepository.RatioToRatioModel(policy.Ratio); } var policyModel = new PolicyModel() { policyCost = policy.Cost, Client = null, ClientEmail = policy.UsersEmail, PolicyDate = policy.PolicyDate, Car = carModel, Ratio = ratioModel }; if (carModel != null) { carModel.Policy = policyModel; } if (ratioModel != null) { ratioModel.Policy = policyModel; } return(policyModel); }
public Tuple <int, int> PredictScore(RatioModel ratio) { try { var input = new double[] { ratio.HOR, ratio.HDR, ratio.AOR, ratio.ADR, ratio.HORH, ratio.HDRH, ratio.AORA, ratio.ADRA }; //double[] input = Codebook.Translate(query.ToArray()).ToDouble(); int result = Predictor.Decide(input); var decodedResult = Codebook.First(x => x.Value == result).Key; return(decodedResult); } catch (Exception e) { logger.Error("Error while predicting score.", e); return(null); } }
public void RatioModelToRatioTest() { var expectedRatio = new Ratio ( 1.2, 1.8, 0.5, 2.0 ); var ratioModel = new RatioModel() { CarAge = 1.2, DrivingExperience = 1.8, DriverAge = 0.5, EnginePower = 2.0 }; var ratio = _ratioRepository.RatioModelToRatio(ratioModel); Assert.AreEqual(expectedRatio, ratio); }
public void RatioToRatioModelTest() { var expectedRatioModel = new RatioModel() { CarAge = 0.9, DrivingExperience = 1.1, DriverAge = 1.0, EnginePower = 0.8 }; var ratio = new Ratio ( 0.9, 1.1, 1.0, 0.8 ); var ratioModel = _ratioRepository.RatioToRatioModel(ratio); Assert.AreEqual(expectedRatioModel, ratioModel); }
private RatioModel GetGoldenRatio(MeasureModel me) { RatioModel ratio = new RatioModel(); // check if using local gender if (bIsMale) { ratio.Neck = me.Neck - (me.Wrist * 2.5); ratio.Shoulder = me.Shoulder - (me.Waist * 1.618); ratio.Chest = me.Chest - (me.Wrist * 6.5); ratio.Arm = me.Arm - (me.Wrist * 2.5); ratio.Forearm = me.Forearm - (me.Wrist * 1.88); ratio.Calf = me.Calf - (me.Wrist * 2.5); ratio.Thigh = me.Knee - (me.Knee * 1.75); } else { double dWaist = this.CalculateGoldenWaist(); ratio.Shoulder = me.Shoulder - (dWaist * 1.618); ratio.Waist = me.Waist - dWaist; ratio.Hips = me.Hips - (dWaist * 1.42); } return(ratio); }
public List <BinanceModel> Binance30F() { string allData; try { allData = webClient.DownloadString("https://www.binance.com/api/v3/ticker/24hr"); } catch (Exception ee) { ////Timer timer2 = new Timer(); //timer2.Stop(); MessageBox.Show("Bağlanamadı! İnternet bağlantınızı kontrol edip uygulamayı tekrar çalıştırmayı deneyin.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); return(new List <BinanceModel>()); } JArray allDataArray = JArray.Parse(allData); BRatio ethBtc = JsonConvert.DeserializeObject <BRatio>(allDataArray[0].ToString()); decimal ethBtcLastPrice = Convert.ToDecimal(ethBtc.LastPrice, System.Globalization.CultureInfo.InvariantCulture); BRatio bnbEth = JsonConvert.DeserializeObject <BRatio>(allDataArray[10].ToString()); decimal bnbEthLastPrice = Convert.ToDecimal(bnbEth.LastPrice, System.Globalization.CultureInfo.InvariantCulture); BRatio ethUsdt = JsonConvert.DeserializeObject <BRatio>(allDataArray[12].ToString()); decimal ethUsdtLastPrice = Convert.ToDecimal(ethUsdt.LastPrice, System.Globalization.CultureInfo.InvariantCulture); List <RatioModel> bRatiosOverBTC = new List <RatioModel>(); List <BRatio> bRatiosOverETH = new List <BRatio>(); List <RatioModel> bRatiosOverBNB = new List <RatioModel>(); List <RatioModel> bRatiosOverUSDT = new List <RatioModel>(); foreach (var item in allDataArray) { BRatio bRatio = JsonConvert.DeserializeObject <BRatio>(item.ToString()); if (bRatio.Symbol.Substring(bRatio.Symbol.Length - 3).Contains("BTC")) { RatioModel ratioModel = new RatioModel { Symbol = bRatio.Symbol, LastPrice = bRatio.LastPrice, QuoteVolume = bRatio.QuoteVolume }; bRatiosOverBTC.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value1 = (ratioModelLastPrice / ethBtcLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (bRatio.Symbol.Substring(bRatio.Symbol.Length - 3).Contains("ETH")) { bRatiosOverETH.Add(bRatio); //decimal ratioModelLastPrice = Convert.ToDecimal(bRatio.LastPrice, System.Globalization.CultureInfo.InvariantCulture); } if (bRatio.Symbol.Substring(bRatio.Symbol.Length - 3).Contains("BNB")) { RatioModel ratioModel = new RatioModel { Symbol = bRatio.Symbol, LastPrice = bRatio.LastPrice, QuoteVolume = bRatio.QuoteVolume }; bRatiosOverBNB.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value3 = (ratioModelLastPrice * bnbEthLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (bRatio.Symbol.Substring(bRatio.Symbol.Length - 4).Contains("USDT")) { RatioModel ratioModel = new RatioModel { Symbol = bRatio.Symbol, LastPrice = bRatio.LastPrice, QuoteVolume = bRatio.QuoteVolume }; bRatiosOverUSDT.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value4 = (ratioModelLastPrice / ethUsdtLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } } var bRatiosOverBtcInOrder = bRatiosOverBTC.OrderBy(ratioModel => decimal.Parse(ratioModel.QuoteVolume)).Reverse(); IDictionary <string, RatioModel> btcDict = new Dictionary <string, RatioModel>(); foreach (var item in bRatiosOverBtcInOrder) { btcDict.Add(item.Symbol.Substring(0, item.Symbol.Length - 3), item); } foreach (var ethItem in bRatiosOverETH) { if (btcDict.Keys.Contains(ethItem.Symbol.Substring(0, ethItem.Symbol.Length - 3))) { btcDict[ethItem.Symbol.Substring(0, ethItem.Symbol.Length - 3)].XxxEth = ethItem.LastPrice; } } foreach (var bnbItem in bRatiosOverBNB) { if (btcDict.Keys.Contains(bnbItem.Symbol.Substring(0, bnbItem.Symbol.Length - 3))) { btcDict[bnbItem.Symbol.Substring(0, bnbItem.Symbol.Length - 3)].Value3 = bnbItem.Value3; } } foreach (var usdtItem in bRatiosOverUSDT) { if (btcDict.Keys.Contains(usdtItem.Symbol.Substring(0, usdtItem.Symbol.Length - 4))) { btcDict[usdtItem.Symbol.Substring(0, usdtItem.Symbol.Length - 4)].Value4 = usdtItem.Value4; } } foreach (var ratioModel in bRatiosOverBtcInOrder) { if (Convert.ToDecimal(ratioModel.QuoteVolume, System.Globalization.CultureInfo.InvariantCulture) > 0) { decimal[] valuesInRow = { Convert.ToDecimal(ratioModel.Value1, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.XxxEth, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value3, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value4, System.Globalization.CultureInfo.InvariantCulture) }; decimal[] valuesInRowNoZero = { }; int i = 0; foreach (decimal value in valuesInRow) { if (value != 0) { Array.Resize(ref valuesInRowNoZero, i + 1); valuesInRowNoZero[i] = value; i++; } } ; int indexOfMin = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Min()); int indexOfMax = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Max()); int[] rankOfIndex = { indexOfMin, indexOfMax }; decimal difference = valuesInRowNoZero[rankOfIndex.Min()] - valuesInRowNoZero[rankOfIndex.Max()]; ratioModel.Difference = difference.ToString(System.Globalization.CultureInfo.InvariantCulture); ratioModel.ResultValue = (difference / valuesInRowNoZero[rankOfIndex.Min()]).ToString("0.##########", System.Globalization.CultureInfo.InvariantCulture); } else { ratioModel.ResultValue = "0"; } } IEnumerable <RatioModel> bRatiosOverBtcOrderedByResultValue = bRatiosOverBTC.OrderBy(ratioModel => decimal.Parse(ratioModel.ResultValue)); IEnumerable <RatioModel> bRatiosOverBtcOrderedByResultValueLast30 = bRatiosOverBtcOrderedByResultValue.Take(30); IEnumerable <RatioModel> bRatiosOverBtcOrderedByResultValueTop30 = bRatiosOverBtcOrderedByResultValue.Reverse().Take(30); IEnumerable <RatioModel> bRatiosOverBtcOrderedByResultValueTop30Last30 = bRatiosOverBtcOrderedByResultValueTop30.Concat(bRatiosOverBtcOrderedByResultValueLast30.Reverse()); var bRatiosOverBtcOrderedByResultValueTop30Last30List = bRatiosOverBtcOrderedByResultValueTop30Last30.ToList(); List <BinanceModel> FinalList = new List <BinanceModel>(); foreach (var item in bRatiosOverBtcOrderedByResultValueTop30Last30List) { BinanceModel binanceModel = new BinanceModel { Symbol = item.Symbol.Substring(0, item.Symbol.Length - 3), Difference = item.Difference, ResultValue = item.ResultValue, Value1 = item.Value1, Value3 = item.Value3, Value4 = item.Value4, XxxEth = item.XxxEth, QuoteVolume = item.QuoteVolume }; FinalList.Add(binanceModel); } ////DataGridView dgvMain = new DataGridView(); //dgvMain.DataSource = FinalList; //TODO: BURDAN dgvMain'i ya da timer2'yi nasıl kullanırım? //dgvMain.Columns[0].HeaderText = "Sembol"; //dgvMain.Columns[1].HeaderText = "(XXX/BTC) / (ETH/BTC)"; //dgvMain.Columns[2].HeaderText = "(XXX/ETH)"; //dgvMain.Columns[3].HeaderText = "(XXX/BNB) × (BNB/ETH)"; //dgvMain.Columns[4].HeaderText = "(XXX/USDT) / (ETH/USDT)"; //dgvMain.Columns[5].HeaderText = "Fark"; //dgvMain.Columns[6].HeaderText = "Sonuç"; //dgvMain.Columns[7].HeaderText = "BTC Piyasası İşlem Hacmi"; return(FinalList); }
public List <BitzModel> BitzF() { string allData; try { allData = webClient.DownloadString("https://api.bitzapi.com/Market/tickerall"); } catch (Exception ee) { MessageBox.Show("Bağlanamadı! İnternet bağlantınızı kontrol edip uygulamayı tekrar çalıştırmayı deneyin.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); return(new List <BitzModel>()); } JArray allDataArray = JArray.Parse("[" + allData + "]"); BitZJson bitZJson = JsonConvert.DeserializeObject <BitZJson>(allDataArray[0].ToString()); JArray dataArray = JArray.Parse("[" + bitZJson.data.ToString() + "]"); Data data = JsonConvert.DeserializeObject <Data>(dataArray[0].ToString()); List <Ratio> ratiosList = new List <Ratio>(); foreach (KeyValuePair <string, JToken> item in (JObject)bitZJson.data) { Ratio nesne = JsonConvert.DeserializeObject <Ratio>(item.Value.ToString()); ratiosList.Add(nesne); } // Information about the process above: https://www.newtonsoft.com/json/help/html/JObjectProperties.htm Ratio btcDkkt = ratiosList[3]; decimal btcDkktLastPrice = Convert.ToDecimal(btcDkkt.Now, System.Globalization.CultureInfo.InvariantCulture); Ratio ethDkkt = ratiosList[4]; decimal ethDkktLastPrice = Convert.ToDecimal(ethDkkt.Now, System.Globalization.CultureInfo.InvariantCulture); Ratio usdtDkkt = ratiosList[1]; decimal usdtDkktLastPrice = Convert.ToDecimal(usdtDkkt.Now, System.Globalization.CultureInfo.InvariantCulture); List <RatioModel> ratiosOverBTC = new List <RatioModel>(); List <RatioModel> ratiosOverETH = new List <RatioModel>(); List <RatioModel> ratiosOverUSDT = new List <RatioModel>(); List <Ratio> ratiosOverDKKT = new List <Ratio>(); foreach (var ratio in ratiosList) { //BRatio bRatio = JsonConvert.DeserializeObject<BRatio>(item.ToString()); if (ratio.Symbol.Substring(ratio.Symbol.Length - 3).Contains("btc")) { RatioModel ratioModel = new RatioModel { Symbol = ratio.Symbol, LastPrice = ratio.Now, QuoteVolume = ratio.QuoteVolume }; ratiosOverBTC.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value1 = (ratioModelLastPrice * btcDkktLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (ratio.Symbol.Substring(ratio.Symbol.Length - 3).Contains("eth")) { RatioModel ratioModel = new RatioModel { Symbol = ratio.Symbol, LastPrice = ratio.Now, QuoteVolume = ratio.QuoteVolume }; ratiosOverETH.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value2 = (ratioModelLastPrice * ethDkktLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (ratio.Symbol.Substring(ratio.Symbol.Length - 4).Contains("usdt")) { RatioModel ratioModel = new RatioModel { Symbol = ratio.Symbol, LastPrice = ratio.Now, QuoteVolume = ratio.QuoteVolume }; ratiosOverUSDT.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value3 = (ratioModelLastPrice * usdtDkktLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (ratio.Symbol.Substring(ratio.Symbol.Length - 4).Contains("dkkt")) { ratiosOverDKKT.Add(ratio); //decimal ratioModelLastPrice = Convert.ToDecimal(bRatio.LastPrice, System.Globalization.CultureInfo.InvariantCulture); } } IEnumerable <RatioModel> ratiosOverBtcInOrder = ratiosOverBTC.OrderBy(ratioModel => decimal.Parse(ratioModel.QuoteVolume)).Reverse(); IDictionary <string, RatioModel> btcDict = new Dictionary <string, RatioModel>(); foreach (var item in ratiosOverBtcInOrder) { btcDict.Add(item.Symbol.Substring(0, item.Symbol.Length - 4), item); } foreach (var ethItem in ratiosOverETH) { if (btcDict.Keys.Contains(ethItem.Symbol.Substring(0, ethItem.Symbol.Length - 4))) { btcDict[ethItem.Symbol.Substring(0, ethItem.Symbol.Length - 4)].Value2 = ethItem.Value2; } } foreach (var usdtItem in ratiosOverUSDT) { if (btcDict.Keys.Contains(usdtItem.Symbol.Substring(0, usdtItem.Symbol.Length - 5))) { btcDict[usdtItem.Symbol.Substring(0, usdtItem.Symbol.Length - 5)].Value3 = usdtItem.Value3; } } foreach (var dkktItem in ratiosOverDKKT) { if (btcDict.Keys.Contains(dkktItem.Symbol.Substring(0, dkktItem.Symbol.Length - 5))) { btcDict[dkktItem.Symbol.Substring(0, dkktItem.Symbol.Length - 5)].Value4 = dkktItem.Now; } } foreach (var ratioModel in ratiosOverBtcInOrder) { if (Convert.ToDecimal(ratioModel.QuoteVolume, System.Globalization.CultureInfo.InvariantCulture) > 0) { decimal[] valuesInRow = { Convert.ToDecimal(ratioModel.Value1, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value2, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value3, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value4, System.Globalization.CultureInfo.InvariantCulture) }; decimal[] valuesInRowNoZero = { }; int i = 0; foreach (decimal value in valuesInRow) { if (value != 0) { Array.Resize(ref valuesInRowNoZero, i + 1); valuesInRowNoZero[i] = value; i++; } } ; int indexOfMin = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Min()); int indexOfMax = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Max()); int[] rankOfIndex = { indexOfMin, indexOfMax }; decimal difference = valuesInRowNoZero[rankOfIndex.Min()] - valuesInRowNoZero[rankOfIndex.Max()]; ratioModel.Difference = difference.ToString(System.Globalization.CultureInfo.InvariantCulture); ratioModel.ResultValue = (difference / valuesInRowNoZero[rankOfIndex.Min()]).ToString("0.##########", System.Globalization.CultureInfo.InvariantCulture); } else { ratioModel.ResultValue = "0"; } } var bRatiosOverBtcInOrderList = ratiosOverBtcInOrder.ToList(); List <BitzModel> finalList = new List <BitzModel>(); foreach (var item in bRatiosOverBtcInOrderList) { BitzModel bitzModel = new BitzModel { Symbol = item.Symbol.Substring(0, item.Symbol.Length - 4).ToUpper(), Difference = item.Difference, ResultValue = item.ResultValue, Value1 = item.Value1, Value2 = item.Value2, Value3 = item.Value3, Value4 = item.Value4, QuoteVolume = item.QuoteVolume }; finalList.Add(bitzModel); } return(finalList); }
public List <UpbitModel> Upbit30F() { string allMarketsString; try { allMarketsString = webClient.DownloadString("https://api.upbit.com/v1/market/all"); } catch (Exception ee) { MessageBox.Show("Bağlanamadı! İnternet bağlantınızı kontrol edip uygulamayı tekrar çalıştırmayı deneyin.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); return(new List <UpbitModel>()); } JArray allMarketsArray = JArray.Parse(allMarketsString); string pairsString = null; foreach (JToken item in allMarketsArray) { UpbitPair pair = JsonConvert.DeserializeObject <UpbitPair>(item.ToString()); pairsString = pairsString + "," + pair.Market; } string allTickersString = webClient.DownloadString($"https://api.upbit.com/v1/ticker?markets= {pairsString.Substring(1)}"); JArray allTickersArray = JArray.Parse(allTickersString); //Decimals in allTickersString are normal but they turn to scientific notation in allTickersArray over here. // !!! Pairs notation is reversed at Upbit API. e.g. BTC/KRW symbolized by KRW-BTC. // But variable naming are not reversed below. e.g btcKrw for BTC/KRW. Ticker btcUsdt = JsonConvert.DeserializeObject <Ticker>(allTickersArray[75].ToString()); decimal btcUsdtLastPrice = Convert.ToDecimal(btcUsdt.Trade_price, System.Globalization.CultureInfo.InvariantCulture); List <RatioModel> ratiosOverBTC = new List <RatioModel>(); List <Ticker> ratiosOverUSDT = new List <Ticker>(); foreach (var item in allTickersArray) { Ticker ticker = JsonConvert.DeserializeObject <Ticker>(item.ToString()); if (ticker.Market.Substring(0, 3).Contains("BTC")) { RatioModel ratioModel = new RatioModel { Symbol = ticker.Market, LastPrice = decimal.Parse(ticker.Trade_price, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture).ToString(), QuoteVolume = decimal.Parse(ticker.Acc_trade_price_24h, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture).ToString(), }; ratiosOverBTC.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice); ratioModel.Value1 = (ratioModelLastPrice * btcUsdtLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (ticker.Market.Substring(0, 4).Contains("USDT")) { ratiosOverUSDT.Add(ticker); } } IEnumerable <RatioModel> ratiosOverBtcInOrder = ratiosOverBTC.OrderBy(ratioModel => decimal.Parse(ratioModel.QuoteVolume)).Reverse(); IDictionary <string, RatioModel> btcDict = new Dictionary <string, RatioModel>(); foreach (var item in ratiosOverBtcInOrder) { btcDict.Add(item.Symbol.Substring(4), item); } foreach (var usdtItem in ratiosOverUSDT) { if (btcDict.Keys.Contains(usdtItem.Market.Substring(5))) { btcDict[usdtItem.Market.Substring(5)].Value2 = usdtItem.Trade_price; } } foreach (var ratioModel in ratiosOverBtcInOrder) { if (Convert.ToDecimal(ratioModel.QuoteVolume, System.Globalization.CultureInfo.InvariantCulture) > 0) { decimal[] valuesInRow = { Convert.ToDecimal(ratioModel.Value1, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value2, System.Globalization.CultureInfo.InvariantCulture) }; decimal[] valuesInRowNoZero = { }; int i = 0; foreach (decimal value in valuesInRow) { if (value != 0) { Array.Resize(ref valuesInRowNoZero, i + 1); valuesInRowNoZero[i] = value; i++; } } ; int indexOfMin = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Min()); int indexOfMax = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Max()); int[] rankOfIndex = { indexOfMin, indexOfMax }; decimal difference = valuesInRowNoZero[rankOfIndex.Min()] - valuesInRowNoZero[rankOfIndex.Max()]; ratioModel.Difference = difference.ToString(System.Globalization.CultureInfo.InvariantCulture); ratioModel.ResultValue = (difference / valuesInRowNoZero[rankOfIndex.Min()]).ToString("0.##########", System.Globalization.CultureInfo.InvariantCulture); } else { ratioModel.ResultValue = "0"; } } IEnumerable <RatioModel> ratiosOverBtcOrderedByResultValue = ratiosOverBTC.OrderBy(ratioModel => decimal.Parse(ratioModel.ResultValue)); IEnumerable <RatioModel> ratiosOverBtcOrderedByResultValueLast10 = ratiosOverBtcOrderedByResultValue.Take(30); IEnumerable <RatioModel> ratiosOverBtcOrderedByResultValueTop10 = ratiosOverBtcOrderedByResultValue.Reverse().Take(30); IEnumerable <RatioModel> ratiosOverBtcOrderedByResultValueTop10Last10 = ratiosOverBtcOrderedByResultValueTop10.Concat(ratiosOverBtcOrderedByResultValueLast10.Reverse()); var ratiosOverBtcOrderedByResultValueTop10Last10List = ratiosOverBtcOrderedByResultValueTop10Last10.ToList(); List <UpbitModel> finalList = new List <UpbitModel>(); foreach (var item in ratiosOverBtcOrderedByResultValueTop10Last10List) { UpbitModel upbitModel = new UpbitModel { Symbol = item.Symbol.Substring(4), Value1 = item.Value1, Value2 = item.Value2, Difference = item.Difference, ResultValue = item.ResultValue, QuoteVolume = item.QuoteVolume }; finalList.Add(upbitModel); } return(finalList); }
public IActionResult Upbit() { string allMarketsString = c.DownloadString("https://api.upbit.com/v1/market/all"); JArray allMarketsArray = JArray.Parse(allMarketsString); string pairsString = null; foreach (JToken item in allMarketsArray) { UpbitPair pair = JsonConvert.DeserializeObject <UpbitPair>(item.ToString()); pairsString = pairsString + "," + pair.Market; } string allTickersString = c.DownloadString($"https://api.upbit.com/v1/ticker?markets= {pairsString.Substring(1)}"); JArray allTickersArray = JArray.Parse(allTickersString); //Decimals in allTickersString are normal but they turn to scientific notation in allTickersArray over here. // !!! Pairs notation is reversed at Upbit API. e.g. BTC/KRW symbolized by KRW-BTC. // But variable naming are not reversed below. e.g btcKrw for BTC/KRW. Ticker btcUsdt = JsonConvert.DeserializeObject <Ticker>(allTickersArray[75].ToString()); decimal btcUsdtLastPrice = Convert.ToDecimal(btcUsdt.Trade_price, System.Globalization.CultureInfo.InvariantCulture); List <RatioModel> ratiosOverBTC = new List <RatioModel>(); List <Ticker> ratiosOverUSDT = new List <Ticker>(); foreach (var item in allTickersArray) { Ticker ticker = JsonConvert.DeserializeObject <Ticker>(item.ToString()); if (ticker.Market.Substring(0, 3).Contains("BTC")) { RatioModel ratioModel = new RatioModel { Symbol = ticker.Market, LastPrice = decimal.Parse(ticker.Trade_price, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture).ToString(), QuoteVolume = decimal.Parse(ticker.Acc_trade_price_24h, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture).ToString(), }; ratiosOverBTC.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice); ratioModel.Value1 = (ratioModelLastPrice * btcUsdtLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (ticker.Market.Substring(0, 4).Contains("USDT")) { ratiosOverUSDT.Add(ticker); } } IEnumerable <RatioModel> ratiosOverBtcInOrder = ratiosOverBTC.OrderBy(ratioModel => decimal.Parse(ratioModel.QuoteVolume)).Reverse(); IDictionary <string, RatioModel> btcDict = new Dictionary <string, RatioModel>(); foreach (var item in ratiosOverBtcInOrder) { btcDict.Add(item.Symbol.Substring(4), item); } foreach (var usdtItem in ratiosOverUSDT) { if (btcDict.Keys.Contains(usdtItem.Market.Substring(5))) { btcDict[usdtItem.Market.Substring(5)].Value2 = usdtItem.Trade_price; } } foreach (var ratioModel in ratiosOverBtcInOrder) { if (Convert.ToDecimal(ratioModel.QuoteVolume, System.Globalization.CultureInfo.InvariantCulture) > 0) { decimal[] valuesInRow = { Convert.ToDecimal(ratioModel.Value1, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value2, System.Globalization.CultureInfo.InvariantCulture) }; decimal[] valuesInRowNoZero = { }; int i = 0; foreach (decimal value in valuesInRow) { if (value != 0) { Array.Resize(ref valuesInRowNoZero, i + 1); valuesInRowNoZero[i] = value; i++; } } ; int indexOfMin = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Min()); int indexOfMax = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Max()); int[] rankOfIndex = { indexOfMin, indexOfMax }; decimal difference = valuesInRowNoZero[rankOfIndex.Min()] - valuesInRowNoZero[rankOfIndex.Max()]; ratioModel.Difference = difference.ToString(System.Globalization.CultureInfo.InvariantCulture); ratioModel.ResultValue = (difference / valuesInRowNoZero[rankOfIndex.Min()]).ToString("0.##########", System.Globalization.CultureInfo.InvariantCulture); } else { ratioModel.ResultValue = "0"; } } return(View(ratiosOverBtcInOrder)); }
public IActionResult Bitz10() { string allData = c.DownloadString("https://api.bitzapi.com/Market/tickerall"); JArray allDataArray = JArray.Parse("[" + allData + "]"); BitZJson bitZJson = JsonConvert.DeserializeObject <BitZJson>(allDataArray[0].ToString()); JArray dataArray = JArray.Parse("[" + bitZJson.data.ToString() + "]"); Data data = JsonConvert.DeserializeObject <Data>(dataArray[0].ToString()); List <Ratio> ratiosList = new List <Ratio>(); foreach (KeyValuePair <string, JToken> item in (JObject)bitZJson.data) { Ratio nesne = JsonConvert.DeserializeObject <Ratio>(item.Value.ToString()); ratiosList.Add(nesne); } // Information about the process above: https://www.newtonsoft.com/json/help/html/JObjectProperties.htm Ratio btcDkkt = ratiosList[3]; decimal btcDkktLastPrice = Convert.ToDecimal(btcDkkt.Now, System.Globalization.CultureInfo.InvariantCulture); Ratio ethDkkt = ratiosList[4]; decimal ethDkktLastPrice = Convert.ToDecimal(ethDkkt.Now, System.Globalization.CultureInfo.InvariantCulture); Ratio usdtDkkt = ratiosList[1]; decimal usdtDkktLastPrice = Convert.ToDecimal(usdtDkkt.Now, System.Globalization.CultureInfo.InvariantCulture); List <RatioModel> ratiosOverBTC = new List <RatioModel>(); List <RatioModel> ratiosOverETH = new List <RatioModel>(); List <RatioModel> ratiosOverUSDT = new List <RatioModel>(); List <Ratio> ratiosOverDKKT = new List <Ratio>(); foreach (var ratio in ratiosList) { //BRatio bRatio = JsonConvert.DeserializeObject<BRatio>(item.ToString()); if (ratio.Symbol.Substring(ratio.Symbol.Length - 3).Contains("btc")) { RatioModel ratioModel = new RatioModel { Symbol = ratio.Symbol, LastPrice = ratio.Now, QuoteVolume = ratio.QuoteVolume }; ratiosOverBTC.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value1 = (ratioModelLastPrice * btcDkktLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (ratio.Symbol.Substring(ratio.Symbol.Length - 3).Contains("eth")) { RatioModel ratioModel = new RatioModel { Symbol = ratio.Symbol, LastPrice = ratio.Now, QuoteVolume = ratio.QuoteVolume }; ratiosOverETH.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value2 = (ratioModelLastPrice * ethDkktLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (ratio.Symbol.Substring(ratio.Symbol.Length - 4).Contains("usdt")) { RatioModel ratioModel = new RatioModel { Symbol = ratio.Symbol, LastPrice = ratio.Now, QuoteVolume = ratio.QuoteVolume }; ratiosOverUSDT.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value3 = (ratioModelLastPrice * usdtDkktLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (ratio.Symbol.Substring(ratio.Symbol.Length - 4).Contains("dkkt")) { ratiosOverDKKT.Add(ratio); //decimal ratioModelLastPrice = Convert.ToDecimal(bRatio.LastPrice, System.Globalization.CultureInfo.InvariantCulture); } } IEnumerable <RatioModel> ratiosOverBtcInOrder = ratiosOverBTC.OrderBy(ratioModel => decimal.Parse(ratioModel.QuoteVolume)).Reverse(); IDictionary <string, RatioModel> btcDict = new Dictionary <string, RatioModel>(); foreach (var item in ratiosOverBtcInOrder) { btcDict.Add(item.Symbol.Substring(0, item.Symbol.Length - 4), item); } foreach (var ethItem in ratiosOverETH) { if (btcDict.Keys.Contains(ethItem.Symbol.Substring(0, ethItem.Symbol.Length - 4))) { btcDict[ethItem.Symbol.Substring(0, ethItem.Symbol.Length - 4)].Value2 = ethItem.Value2; } } foreach (var usdtItem in ratiosOverUSDT) { if (btcDict.Keys.Contains(usdtItem.Symbol.Substring(0, usdtItem.Symbol.Length - 5))) { btcDict[usdtItem.Symbol.Substring(0, usdtItem.Symbol.Length - 5)].Value3 = usdtItem.Value3; } } foreach (var dkktItem in ratiosOverDKKT) { if (btcDict.Keys.Contains(dkktItem.Symbol.Substring(0, dkktItem.Symbol.Length - 5))) { btcDict[dkktItem.Symbol.Substring(0, dkktItem.Symbol.Length - 5)].Value4 = dkktItem.Now; } } foreach (var ratioModel in ratiosOverBtcInOrder) { if (Convert.ToDecimal(ratioModel.QuoteVolume, System.Globalization.CultureInfo.InvariantCulture) > 0) { decimal[] valuesInRow = { Convert.ToDecimal(ratioModel.Value1, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value2, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value3, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value4, System.Globalization.CultureInfo.InvariantCulture) }; decimal[] valuesInRowNoZero = { }; int i = 0; foreach (decimal value in valuesInRow) { if (value != 0) { Array.Resize(ref valuesInRowNoZero, i + 1); valuesInRowNoZero[i] = value; i++; } } ; int indexOfMin = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Min()); int indexOfMax = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Max()); int[] rankOfIndex = { indexOfMin, indexOfMax }; decimal difference = valuesInRowNoZero[rankOfIndex.Min()] - valuesInRowNoZero[rankOfIndex.Max()]; ratioModel.Difference = difference.ToString(System.Globalization.CultureInfo.InvariantCulture); ratioModel.ResultValue = (difference / valuesInRowNoZero[rankOfIndex.Min()]).ToString("0.##########", System.Globalization.CultureInfo.InvariantCulture); } else { ratioModel.ResultValue = "0"; } } IEnumerable <RatioModel> ratiosOverBtcOrderedByResultValue = ratiosOverBTC.OrderBy(ratioModel => decimal.Parse(ratioModel.ResultValue)); IEnumerable <RatioModel> ratiosOverBtcOrderedByResultValueLast10 = ratiosOverBtcOrderedByResultValue.Take(10); IEnumerable <RatioModel> ratiosOverBtcOrderedByResultValueTop10 = ratiosOverBtcOrderedByResultValue.Reverse().Take(10); IEnumerable <RatioModel> ratiosOverBtcOrderedByResultValueTop10Last10 = ratiosOverBtcOrderedByResultValueTop10.Concat(ratiosOverBtcOrderedByResultValueLast10.Reverse()); return(View(ratiosOverBtcOrderedByResultValueTop10Last10)); }
public IActionResult Binance() { string allData = c.DownloadString("https://www.binance.com/api/v3/ticker/24hr"); JArray allDataArray = JArray.Parse(allData); BRatio ethBtc = JsonConvert.DeserializeObject <BRatio>(allDataArray[0].ToString()); decimal ethBtcLastPrice = Convert.ToDecimal(ethBtc.LastPrice, System.Globalization.CultureInfo.InvariantCulture); BRatio bnbEth = JsonConvert.DeserializeObject <BRatio>(allDataArray[10].ToString()); decimal bnbEthLastPrice = Convert.ToDecimal(bnbEth.LastPrice, System.Globalization.CultureInfo.InvariantCulture); BRatio ethUsdt = JsonConvert.DeserializeObject <BRatio>(allDataArray[12].ToString()); decimal ethUsdtLastPrice = Convert.ToDecimal(ethUsdt.LastPrice, System.Globalization.CultureInfo.InvariantCulture); List <RatioModel> bRatiosOverBTC = new List <RatioModel>(); List <BRatio> bRatiosOverETH = new List <BRatio>(); List <RatioModel> bRatiosOverBNB = new List <RatioModel>(); List <RatioModel> bRatiosOverUSDT = new List <RatioModel>(); foreach (var item in allDataArray) { BRatio bRatio = JsonConvert.DeserializeObject <BRatio>(item.ToString()); if (bRatio.Symbol.Substring(bRatio.Symbol.Length - 3).Contains("BTC")) { RatioModel ratioModel = new RatioModel { Symbol = bRatio.Symbol, LastPrice = bRatio.LastPrice, QuoteVolume = bRatio.QuoteVolume }; bRatiosOverBTC.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value1 = (ratioModelLastPrice / ethBtcLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (bRatio.Symbol.Substring(bRatio.Symbol.Length - 3).Contains("ETH")) { bRatiosOverETH.Add(bRatio); //decimal ratioModelLastPrice = Convert.ToDecimal(bRatio.LastPrice, System.Globalization.CultureInfo.InvariantCulture); } if (bRatio.Symbol.Substring(bRatio.Symbol.Length - 3).Contains("BNB")) { RatioModel ratioModel = new RatioModel { Symbol = bRatio.Symbol, LastPrice = bRatio.LastPrice, QuoteVolume = bRatio.QuoteVolume }; bRatiosOverBNB.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value3 = (ratioModelLastPrice * bnbEthLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } if (bRatio.Symbol.Substring(bRatio.Symbol.Length - 4).Contains("USDT")) { RatioModel ratioModel = new RatioModel { Symbol = bRatio.Symbol, LastPrice = bRatio.LastPrice, QuoteVolume = bRatio.QuoteVolume }; bRatiosOverUSDT.Add(ratioModel); decimal ratioModelLastPrice = Convert.ToDecimal(ratioModel.LastPrice, System.Globalization.CultureInfo.InvariantCulture); ratioModel.Value4 = (ratioModelLastPrice / ethUsdtLastPrice).ToString("0.########", System.Globalization.CultureInfo.InvariantCulture); } } IEnumerable <RatioModel> bRatiosOverBtcInOrder = bRatiosOverBTC.OrderBy(ratioModel => decimal.Parse(ratioModel.QuoteVolume)).Reverse(); IDictionary <string, RatioModel> btcDict = new Dictionary <string, RatioModel>(); foreach (var item in bRatiosOverBtcInOrder) { btcDict.Add(item.Symbol.Substring(0, item.Symbol.Length - 3), item); } foreach (var ethItem in bRatiosOverETH) { if (btcDict.Keys.Contains(ethItem.Symbol.Substring(0, ethItem.Symbol.Length - 3))) { btcDict[ethItem.Symbol.Substring(0, ethItem.Symbol.Length - 3)].XxxEth = ethItem.LastPrice; } } foreach (var bnbItem in bRatiosOverBNB) { if (btcDict.Keys.Contains(bnbItem.Symbol.Substring(0, bnbItem.Symbol.Length - 3))) { btcDict[bnbItem.Symbol.Substring(0, bnbItem.Symbol.Length - 3)].Value3 = bnbItem.Value3; } } foreach (var usdtItem in bRatiosOverUSDT) { if (btcDict.Keys.Contains(usdtItem.Symbol.Substring(0, usdtItem.Symbol.Length - 4))) { btcDict[usdtItem.Symbol.Substring(0, usdtItem.Symbol.Length - 4)].Value4 = usdtItem.Value4; } } foreach (var ratioModel in bRatiosOverBtcInOrder) { if (Convert.ToDecimal(ratioModel.QuoteVolume, System.Globalization.CultureInfo.InvariantCulture) > 0) { decimal[] valuesInRow = { Convert.ToDecimal(ratioModel.Value1, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.XxxEth, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value3, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDecimal(ratioModel.Value4, System.Globalization.CultureInfo.InvariantCulture) }; decimal[] valuesInRowNoZero = { }; int i = 0; foreach (decimal value in valuesInRow) { if (value != 0) { Array.Resize(ref valuesInRowNoZero, i + 1); valuesInRowNoZero[i] = value; i++; } } ; int indexOfMin = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Min()); int indexOfMax = Array.IndexOf(valuesInRowNoZero, valuesInRowNoZero.Max()); int[] rankOfIndex = { indexOfMin, indexOfMax }; decimal difference = valuesInRowNoZero[rankOfIndex.Min()] - valuesInRowNoZero[rankOfIndex.Max()]; ratioModel.Difference = difference.ToString(System.Globalization.CultureInfo.InvariantCulture); ratioModel.ResultValue = (difference / valuesInRowNoZero[rankOfIndex.Min()]).ToString("0.##########", System.Globalization.CultureInfo.InvariantCulture); } else { ratioModel.ResultValue = "0"; } } //IEnumerable<RatioModel> bRatiosOverBtcOrderedByResultValue = bRatiosOverBTC.OrderBy(ratioModel => decimal.Parse(ratioModel.ResultValue)).Reverse(); return(View(bRatiosOverBtcInOrder)); }