diff --git a/Core/Main/PTMagic.cs b/Core/Main/PTMagic.cs index 06070ba..73217da 100644 --- a/Core/Main/PTMagic.cs +++ b/Core/Main/PTMagic.cs @@ -63,7 +63,7 @@ namespace Core.Main private Dictionary> _globalMarketTrendChanges = new Dictionary>(); private Dictionary _singleMarketSettingsCount = new Dictionary(); Dictionary> _triggeredSingleMarketSettings = new Dictionary>(); - private static readonly object _lockObj = new object(); + private static volatile object _lockObj = new object(); public LogHelper Log { diff --git a/Core/MarketAnalyzer/BaseAnalyzer.cs b/Core/MarketAnalyzer/BaseAnalyzer.cs index 70648d8..b007201 100644 --- a/Core/MarketAnalyzer/BaseAnalyzer.cs +++ b/Core/MarketAnalyzer/BaseAnalyzer.cs @@ -26,16 +26,20 @@ namespace Core.MarketAnalyzer request.ContentType = "application/json"; request.UserAgent = "PTMagic.Import"; request.KeepAlive = true; + request.Timeout = 60000; HttpWebResponse httpResponse = null; + string jsonString = string.Empty; try { httpResponse = (HttpWebResponse)request.GetResponse(); - StreamReader jsonReader = new StreamReader(httpResponse.GetResponseStream()); - string jsonString = jsonReader.ReadToEnd(); - jsonReader.Close(); + using (StreamReader jsonReader = new StreamReader(httpResponse.GetResponseStream())) + { + jsonString = jsonReader.ReadToEnd(); + jsonReader.Close(); + } jsonObject = JsonConvert.DeserializeObject>(jsonString); @@ -43,26 +47,32 @@ namespace Core.MarketAnalyzer } catch (WebException ex) { - // Error calling the service but we got a response so dump it. - string responseString = string.Empty; - var encoding = httpResponse.CharacterSet == "" ? Encoding.UTF8 : Encoding.GetEncoding(httpResponse.CharacterSet); + log.DoLogCritical(string.Format("Error whilst calling {0} \nError: {1}", url, ex.Message), ex); - using (var stream = httpResponse.GetResponseStream()) + if (ex.Response != null) { - var reader = new StreamReader(stream, encoding); - responseString = reader.ReadToEnd(); + // Error calling the service but we got a response so dump it. + string responseString = string.Empty; + var response = ((HttpWebResponse)ex.Response); + var encoding = response.CharacterSet == "" ? Encoding.UTF8 : Encoding.GetEncoding(response.CharacterSet); + + using (var stream = response.GetResponseStream()) + { + var reader = new StreamReader(stream, encoding); + responseString = reader.ReadToEnd(); + } + + log.DoLogCritical(String.Format("{0} - Response: ({1}) {2} : {3}", ex.Message, response.StatusCode, response.StatusDescription, responseString), ex); } - log.DoLogCritical(String.Format("{0} - Response: ({1}) {2} : {3}", ex.Message, httpResponse.StatusCode, httpResponse.StatusDescription, responseString), ex); - - throw ex; + throw; } catch (Exception ex) { log.DoLogCritical(ex.Message, ex); - } - return jsonObject; + throw; + } } public static Newtonsoft.Json.Linq.JObject GetSimpleJsonObjectFromURL(string url, LogHelper log, bool swallowException) @@ -346,15 +356,15 @@ namespace Core.MarketAnalyzer } public static List GetMarketTrendChanges( - string platform, - string mainMarket, - MarketTrend marketTrend, - List marketList, - Dictionary recentMarkets, - Dictionary trendMarkets, - string sortBy, - bool isGlobal, - PTMagicConfiguration systemConfiguration, + string platform, + string mainMarket, + MarketTrend marketTrend, + List marketList, + Dictionary recentMarkets, + Dictionary trendMarkets, + string sortBy, + bool isGlobal, + PTMagicConfiguration systemConfiguration, LogHelper log) { List result = new List(); diff --git a/Core/MarketAnalyzer/Binance.cs b/Core/MarketAnalyzer/Binance.cs index 1475824..7d75e28 100644 --- a/Core/MarketAnalyzer/Binance.cs +++ b/Core/MarketAnalyzer/Binance.cs @@ -416,7 +416,7 @@ namespace Core.MarketAnalyzer Dictionary tickMarkets = new Dictionary(); foreach (string key in markets.Keys) { - List tickRange = marketTicks[key].FindAll(t => t.Time <= tickTime); + List tickRange = marketTicks[key] != null ? marketTicks[key].FindAll(t => t.Time <= tickTime) : new List(); if (tickRange.Count > 0) { diff --git a/PTMagic/Program.cs b/PTMagic/Program.cs index ffa8652..885fb28 100644 --- a/PTMagic/Program.cs +++ b/PTMagic/Program.cs @@ -7,7 +7,7 @@ using Core.Helper; using Core.Main.DataObjects.PTMagicData; using Microsoft.Extensions.DependencyInjection; -[assembly: AssemblyVersion("2.2.6")] +[assembly: AssemblyVersion("2.2.7")] [assembly: AssemblyProduct("PT Magic")] namespace PTMagic