public ActionResult GetForex(string id) { CurrenciesForList CurrenciesForBase = new CurrenciesForList(); id = id.Replace("-", "/"); CurrenciesForBase = ForexAPI.Currency_History_Caller(id); return(View(CurrenciesForBase)); }
private static CurrenciesForList Deserialize_The_String(string str) { CurrenciesForList ListOfCurrenciesForBase = new CurrenciesForList(); string[] str_splitted = str.Split(new string[] { "{" }, StringSplitOptions.RemoveEmptyEntries); Currency currency = new Currency(); List <Currency> currencies = new List <Currency>(); for (int i = 0; i < str_splitted.Length; i++) { string temp1 = str_splitted[i]; if (temp1.Contains("o") && !temp1.Contains("response") && !temp1.Contains("id")) { temp1 = temp1.Replace("\\", ""); string[] splitted = temp1.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); for (int j = 0; j < splitted.Length; j++) { string temp2 = splitted[j]; temp2 = temp2.Replace("\"", ""); int colon_index; if (temp2.Contains("o") && !temp2.Contains("info")) { colon_index = temp2.IndexOf(":"); currency.Open = double.Parse(temp2.Substring(colon_index + 1)); } else if (temp2.Contains("h")) { colon_index = temp2.IndexOf(":"); currency.High = double.Parse(temp2.Substring(colon_index + 1)); } else if (temp2.Contains("l")) { colon_index = temp2.IndexOf(":"); currency.Low = double.Parse(temp2.Substring(colon_index + 1)); } else if (temp2.Contains("c")) { colon_index = temp2.IndexOf(":"); currency.Close = double.Parse(temp2.Substring(colon_index + 1)); } else if (temp2.Contains("tm")) { temp2 = temp2.Replace("}", ""); temp2 = temp2.Replace("]", ""); colon_index = temp2.IndexOf(":"); currency.Time = temp2.Substring(colon_index + 1); currencies.Add(currency); currency = new Currency(); } } } } ListOfCurrenciesForBase.Currencies = currencies; return(ListOfCurrenciesForBase); }
public static CurrenciesForList Currency_History_Caller(string str = "GBP/USD") { string api_request_result = Request_The_History_Of_Currency_Pairs(str); CurrenciesForList CurrenciesForBase = new CurrenciesForList(); CurrenciesForBase = Deserialize_The_String(api_request_result); string MovingAvgStr = Request_The_Moving_Avgerages(str); CurrenciesForBase.MovingAverages = Get_The_Moving_Averages(MovingAvgStr); CurrenciesForBase.Symbol = str; CurrenciesForBase.Period = "1hr"; return(CurrenciesForBase); }