removed excessive whitespace

This commit is contained in:
HojouFotytu 2021-01-31 22:41:21 +09:00
parent 84ce76a162
commit db05efbd7b
1 changed files with 0 additions and 47 deletions

View File

@ -18,7 +18,6 @@ namespace Core.MarketAnalyzer
public static string GetJsonStringFromURL(string url, LogHelper log, (string header, string value)[] headers = null)
{
HttpClient webClient = null;
if (webClient == null)
{
webClient = new HttpClient();
@ -52,9 +51,7 @@ namespace Core.MarketAnalyzer
{
// log.DoLogInfo("Calling URL: " + url);
var response = webClient.GetAsync(url).Result;
string repsonseString = response.Content.ReadAsStringAsync().Result;
if (response.IsSuccessStatusCode)
{
return repsonseString;
@ -63,9 +60,7 @@ namespace Core.MarketAnalyzer
{
// Error
var message = string.Format("Error whilst calling {0} - {1}", url, repsonseString);
log.DoLogError(message);
throw new Exception(message);
}
}
@ -73,13 +68,11 @@ namespace Core.MarketAnalyzer
{
// Conneciton timeout
log.DoLogError(string.Format("Timeout whilst calling {0} - {1}", url, tcEx.Message));
throw;
}
catch (Exception ex)
{
log.DoLogError(string.Format("Error whilst calling {0} \nError: {1}", url, ex.Message));
throw;
}
}
@ -87,45 +80,34 @@ namespace Core.MarketAnalyzer
public static Dictionary<string, dynamic> GetJsonFromURL(string url, LogHelper log, (string header, string value)[] headers = null)
{
Dictionary<string, dynamic> jsonObject = null;
string jsonString = GetJsonStringFromURL(url, log, headers);
// Convert the response to JSON
jsonObject = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(jsonString);
return jsonObject;
}
public static Newtonsoft.Json.Linq.JObject GetSimpleJsonObjectFromURL(string url, LogHelper log, (string header, string value)[] headers = null)
{
Newtonsoft.Json.Linq.JObject jsonObject = null;
string jsonString = GetJsonStringFromURL(url, log, headers);
jsonObject = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(jsonString);
return jsonObject;
}
public static List<dynamic> GetSimpleJsonListFromURL(string url, LogHelper log)
{
List<dynamic> jsonObject = null;
string jsonString = GetJsonStringFromURL(url, log, null);
jsonObject = JsonConvert.DeserializeObject<List<dynamic>>(jsonString);
return jsonObject;
}
public static Newtonsoft.Json.Linq.JArray GetSimpleJsonArrayFromURL(string url, LogHelper log)
{
Newtonsoft.Json.Linq.JArray jsonObject = null;
string jsonString = GetJsonStringFromURL(url, log, null);
jsonObject = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JArray>(jsonString);
return jsonObject;
}
@ -138,7 +120,6 @@ namespace Core.MarketAnalyzer
string baseUrl = "https://api.github.com/repos/PTMagicians/PTMagic/releases/latest";
Newtonsoft.Json.Linq.JObject jsonObject = GetSimpleJsonObjectFromURL(baseUrl, log, new (string header, string value)[] { ("User-Agent", "PTMagic.Import") });
if (jsonObject != null)
{
result = jsonObject.GetValue("tag_name").ToString();
@ -152,14 +133,12 @@ namespace Core.MarketAnalyzer
{
log.DoLogDebug("GitHub version check error: " + ex.Message);
}
return result;
}
public static double GetMainFiatCurrencyRate(string currency, string FreeCurrencyAPI, LogHelper log)
{
double result = 1;
string baseUrl = "http://free.currencyconverterapi.com/api/v5/convert?q=USD_" + currency + "&compact=y&apiKey=" + FreeCurrencyAPI;
log.DoLogDebug("http://free.currencyconverterapi.com - Getting latest exchange rates...");
@ -171,7 +150,6 @@ namespace Core.MarketAnalyzer
result = (double)jsonObject["USD_" + currency]["val"];
log.DoLogInfo("http://free.currencyconverterapi.com - Latest exchange rate for USD to " + currency + " is " + result);
}
return result;
}
@ -191,12 +169,10 @@ namespace Core.MarketAnalyzer
log.DoLogDebug(ex.Message);
}
}
if (result == null)
{
result = new Dictionary<string, MarketInfo>();
}
return result;
}
@ -208,7 +184,6 @@ namespace Core.MarketAnalyzer
public static Dictionary<string, Market> GetMarketDataFromFile(PTMagicConfiguration systemConfiguration, LogHelper log, string platform, DateTime maxDateTime, string marketCaption)
{
Dictionary<string, Market> result = new Dictionary<string, Market>();
DirectoryInfo dataDirectory = new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + Constants.PTMagicPathData + Path.DirectorySeparatorChar + platform + Path.DirectorySeparatorChar);
// Get market files older than max datetime in descending order (newest file up top)
@ -239,7 +214,6 @@ namespace Core.MarketAnalyzer
log.DoLogDebug(platform + " - " + marketCaption + " market data loaded (" + marketFile.LastWriteTimeUtc.ToString() + ")");
}
}
try
{
// Get JSON object
@ -249,7 +223,6 @@ namespace Core.MarketAnalyzer
{
log.DoLogCritical(ex.Message, ex);
}
return result;
}
@ -312,7 +285,6 @@ namespace Core.MarketAnalyzer
{
sortedMarkets = new SortedDictionary<string, Market>(recentMarkets).OrderByDescending(m => m.Value.Volume24h);
}
int marketCount = 1;
foreach (KeyValuePair<string, Market> recentMarketPair in sortedMarkets)
{
@ -336,7 +308,6 @@ namespace Core.MarketAnalyzer
}
Market recentMarket;
if (recentMarkets.TryGetValue(recentMarketPair.Key, out recentMarket))
{
List<string> ignoredMarkets = SystemHelper.ConvertTokenStringToList(marketTrend.IgnoredMarkets, ",");
@ -345,7 +316,6 @@ namespace Core.MarketAnalyzer
log.DoLogDebug(platform + " - Market trend '" + marketTrend.Name + "' for '" + recentMarketPair.Key + "' is ignored in this trend.");
continue;
}
List<string> allowedMarkets = SystemHelper.ConvertTokenStringToList(marketTrend.AllowedMarkets, ",");
if (allowedMarkets.Count > 0 && !allowedMarkets.Contains(recentMarketPair.Value.Symbol))
{
@ -361,12 +331,10 @@ namespace Core.MarketAnalyzer
}
Market trendMarket;
if (trendMarkets.TryGetValue(recentMarketPair.Key, out trendMarket))
{
double recentMarketPrice = recentMarket.Price;
double trendMarketPrice = trendMarket.Price;
if (!platform.Equals("CoinMarketCap", StringComparison.InvariantCulture) && marketTrend.TrendCurrency.Equals("Fiat", StringComparison.InvariantCultureIgnoreCase))
{
if (recentMarket.MainCurrencyPriceUSD > 0 && trendMarket.MainCurrencyPriceUSD > 0)
@ -388,9 +356,7 @@ namespace Core.MarketAnalyzer
mtc.TrendDateTime = DateTime.UtcNow;
result.Add(mtc);
log.DoLogDebug(platform + " - Market trend '" + marketTrend.Name + "' for '" + recentMarketPair.Key + "' (Vol. " + recentMarket.Volume24h.ToString("#,#0.00") + ") is " + trendMarketChange.ToString("#,#0.00") + "% in " + SystemHelper.GetProperDurationTime(marketTrend.TrendMinutes * 60).ToLower() + ".");
marketCount++;
}
else
@ -401,14 +367,11 @@ namespace Core.MarketAnalyzer
}
}
}
if (marketTrend.MaxMarkets > 0 && isGlobal)
{
int maxMarkets = (marketTrend.MaxMarkets <= result.Count) ? marketTrend.MaxMarkets : result.Count;
result = result.GetRange(0, maxMarkets);
}
return result;
}
@ -422,17 +385,13 @@ namespace Core.MarketAnalyzer
foreach (MarketTrend marketTrend in marketTrends)
{
log.DoLogInfo("Building market trend average for '" + marketTrend.Name + "'");
if (globalMarketTrendChanges.ContainsKey(marketTrend.Name))
{
List<MarketTrendChange> marketTrendChanges = globalMarketTrendChanges[marketTrend.Name];
if (marketTrendChanges != null && marketTrendChanges.Count > 0)
{
double totalTrendChange = 0;
int trendChangeCount = marketTrendChanges.Count;
foreach (MarketTrendChange marketTrendChange in marketTrendChanges)
{
if (marketTrend.IgnoreOutlier != 0)
@ -452,29 +411,23 @@ namespace Core.MarketAnalyzer
totalTrendChange += marketTrendChange.TrendChange;
}
}
double averageTrendChange = totalTrendChange / trendChangeCount;
result.Add(marketTrend.Name, averageTrendChange);
log.DoLogInfo("Built average market trend change '" + marketTrend.Name + "' (" + averageTrendChange.ToString("#,#0.00") + "% in " + marketTrend.TrendMinutes.ToString() + " minutes) for " + marketTrendChanges.Count.ToString() + " markets.");
}
else
{
result.Add(marketTrend.Name, 0);
log.DoLogWarn("No market trend changes found for '" + marketTrend.Name + "' - returning 0%");
}
}
else
{
result.Add(marketTrend.Name, 0);
log.DoLogWarn("Market trend '" + marketTrend.Name + "' not found in globalMarketTrendChanges[] - returning 0%");
}
}
}
return result;
}
}