} // DONE public string ListCoinTwoCountry(string FromCountry, string ToCountry) { var FromUpper = FromCountry.ToUpper(); var ToUpper = ToCountry.ToUpper(); CCResultMulti Result = new CCResultMulti(); string CoinList = ""; foreach (string CryptoCoin in TopCoinList) { CoinList += CryptoCoin + ","; } CoinList = CoinList.Substring(0, CoinList.Length - 1); string result = ""; if (CryptoCompareMultiGlobalQuery(CoinList, FromCountry + "," + ToCountry, ref Result)) { List <KeyValuePair <string, decimal> > ArbList = new List <KeyValuePair <string, decimal> >(); var PriceDict = Result.PriceDict; foreach (string CryptoCoin in TopCoinList) { if (PriceDict.ContainsKey(CryptoCoin) && PriceDict[CryptoCoin].Count == 2) { decimal FromPrice = PriceDict[CryptoCoin][FromUpper]; decimal ToPrice = PriceDict[CryptoCoin][ToUpper]; decimal FromPriceConverted = FromUpper == "USD" ? FromPrice : FromPrice / ExchangeList[FromUpper]; decimal ToPriceConverted = ToUpper == "USD" ? ToPrice : ToPrice / ExchangeList[ToUpper]; decimal Arbitrage = Math.Round((FromPriceConverted / ToPriceConverted - 1) * 100, 4); ArbList.Add(new KeyValuePair <string, decimal>(CryptoCoin, Arbitrage)); } } var ordered = ArbList.OrderByDescending(pair => pair.Value); result += "Results found. " + Environment.NewLine + "Below are arbitrage rates for the 20 most popular crypto-currencies." + Environment.NewLine + "Buying from : " + FromUpper + Environment.NewLine + "Selling to : " + ToUpper + Environment.NewLine + Environment.NewLine; foreach (KeyValuePair <string, decimal> kvp in ordered) { result += kvp.Key + " : " + kvp.Value + "%" + Environment.NewLine; } string firstkey = ordered.First().Key; decimal firstval = ordered.First().Value; result += Environment.NewLine + "Best Arbitrage Opportunity:" + Environment.NewLine; result += firstval >= 0 ? firstkey + " with gain of " + firstval + "%." : firstkey + " with lose of " + firstval + "%."; } else { result = "Error occured during the search." + Environment.NewLine + Result.PriceDict["Status"]; } return(result); }
public string ListCountryCointoUSD(string CryptoCurr) { CCResultMulti Result = new CCResultMulti(); string CurrencyList = ""; foreach (KeyValuePair <string, decimal> kvp in ExchangeList) { if (kvp.Key != "MYR" && kvp.Key != "ZAR" && kvp.Key != "THB" && kvp.Key != "TRY" && kvp.Key != "DKK" && kvp.Key != "ISK" && kvp.Key != "HRK" && kvp.Key != "RON") { CurrencyList += kvp.Key + ","; } } string result = ""; if (CryptoCompareMultiGlobalQuery(CryptoCurr, CurrencyList, ref Result)) { List <KeyValuePair <string, decimal> > ArbList = new List <KeyValuePair <string, decimal> >(); foreach (KeyValuePair <string, decimal> kvp in Result.PriceDict[CryptoCurr.ToUpper()]) { decimal newval = kvp.Key == "USD" ? 1 : kvp.Value / ExchangeList[kvp.Key] / Result.PriceDict[CryptoCurr.ToUpper()]["USD"]; decimal Arbitrage = Math.Round((newval - 1) * 100, 4); ArbList.Add(new KeyValuePair <string, decimal>(CryptoCurr.ToUpper() + "->" + kvp.Key, Arbitrage)); } var ordered = ArbList.OrderByDescending(pair => pair.Value); result += "Results found. " + Environment.NewLine + "Each calculated rate is a price relative to average market price in US." + Environment.NewLine; foreach (KeyValuePair <string, decimal> kvp in ordered) { result += kvp.Key + " : " + kvp.Value + "%" + Environment.NewLine; } string firstkey = ordered.First().Key; decimal firstval = ordered.First().Value; result += Environment.NewLine + "Best Arbitrage Opportunity:" + Environment.NewLine; result += firstval >= 0 ? firstkey + " with gain of " + firstval + "%." : firstkey + " with lose of " + firstval + "%."; } else { result = "Error occured during the search." + Environment.NewLine + Result.PriceDict["Status"]; } return(result); } // DONE
public string[] ListCoinListCountry() { CCResultMulti Result = new CCResultMulti(); string CurrencyList = ""; foreach (KeyValuePair <string, decimal> kvp in ExchangeList) { if (kvp.Key != "MYR" && kvp.Key != "ZAR" && kvp.Key != "THB" && kvp.Key != "TRY" && kvp.Key != "DKK" && kvp.Key != "ISK" && kvp.Key != "HRK" && kvp.Key != "RON") { CurrencyList += kvp.Key + ","; } } string CoinList = ""; foreach (string CryptoCoin in TopCoinList) { CoinList += CryptoCoin + ","; } CoinList = CoinList.Substring(0, CoinList.Length - 1); List <string> responses = new List <string>(); string result = ""; if (CryptoCompareMultiGlobalQuery(CoinList, CurrencyList, ref Result)) { List <KeyValuePair <string, decimal> > ArbList = new List <KeyValuePair <string, decimal> >(); var PriceDict = Result.PriceDict; foreach (KeyValuePair <string, dynamic> kvp in PriceDict) { string CryptoCurrKey = kvp.Key; foreach (KeyValuePair <string, decimal> kvpp in kvp.Value) { decimal newval = kvpp.Key == "USD" ? 1 : kvpp.Value / ExchangeList[kvpp.Key] / Result.PriceDict[CryptoCurrKey]["USD"]; decimal Arbitrage = Math.Round((newval - 1) * 100, 4); ArbList.Add(new KeyValuePair <string, decimal>(CryptoCurrKey + "->" + kvpp.Key, Arbitrage)); } } var ordered = ArbList.OrderByDescending(pair => pair.Value); result += "Results found. " + Environment.NewLine + "Below are top 100 results of arbitrage rates for the 20 most popular crypto-currencies across the world." + Environment.NewLine + "Each calculated rate is a price relative to average market price in US." + Environment.NewLine + "{XXX}->{YYY} means buying XXX coin in YYY country."; responses.Add(result); result = ""; int index = 1; foreach (KeyValuePair <string, decimal> kvp in ordered) { result += index + ". " + kvp.Key + " : " + kvp.Value + "%" + Environment.NewLine; if (index % 20 == 0) { responses.Add(result); result = ""; } ++index; if (index > 100) { break; } } responses.Add(result); result = ""; string firstkey = ordered.First().Key; decimal firstval = ordered.First().Value; result += Environment.NewLine + "Best Arbitrage Opportunity is:" + Environment.NewLine; result += firstval >= 0 ? firstkey + " with gain of " + firstval + "%." : firstkey + " with lose of " + firstval + "%."; responses.Add(result); } else { responses.Add("Error occured during the search." + Environment.NewLine + Result.PriceDict["Status"]); } return(responses.ToArray()); }
public bool CryptoCompareMultiGlobalQuery(string FromCurrSyms, string ToCurrSyms, ref CCResultMulti result) { string FromUpper = FromCurrSyms.ToUpper(); string ToUpper = ToCurrSyms.ToUpper(); HttpResponseMessage Response = CryptoCompareClient.GetAsync("data/pricemulti?fsyms=" + FromUpper + "&tsyms=" + ToUpper).Result; if (Response.IsSuccessStatusCode) { string Product = Response.Content.ReadAsStringAsync().Result; var Values = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(Product); if (Values.ContainsKey("Response") && Values["Response"] == "Error") { result.PriceDict.Add("Status", Values["Message"]); return(false); } else { var NewValue = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, decimal> > >(Product); foreach (KeyValuePair <string, Dictionary <string, decimal> > kvp in NewValue) { result.PriceDict.Add(kvp.Key, kvp.Value); } return(true); } } else { result.PriceDict.Add("Status", Response.ReasonPhrase); return(false); } }