From cb4f0a01ed3144576962adb997f62bb55f6c991e Mon Sep 17 00:00:00 2001 From: djbadders <34887832+djbadders@users.noreply.github.com> Date: Sun, 17 Feb 2019 23:08:11 +0000 Subject: [PATCH] More fixes - Fixed checking file timestamps to use UTC - Added better debug info on failed calls for market data - Fixed failure to get currency exchange rates --- Core/Helper/FileHelper.cs | 6 +++--- Core/Main/PTMagic.cs | 4 ++-- Core/MarketAnalyzer/BaseAnalyzer.cs | 19 ++++++++++++++++--- PTMagic/_presets/Default/DCA.PROPERTIES | 9 +-------- .../_presets/Default/INDICATORS.PROPERTIES | 2 +- PTMagic/_presets/Default/PAIRS.PROPERTIES | 2 +- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Core/Helper/FileHelper.cs b/Core/Helper/FileHelper.cs index c1b5e31..e262561 100644 --- a/Core/Helper/FileHelper.cs +++ b/Core/Helper/FileHelper.cs @@ -45,7 +45,7 @@ namespace Core.Helper FileInfo file = new FileInfo(filePath); - string backupFilePath = backupFolder + DateTime.UtcNow.ToString("yyyy-MM-dd_HH.mm.ss") + "_" + file.Name; + string backupFilePath = backupFolder + DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss") + "_" + file.Name; if (!backupFileName.Equals("")) { backupFilePath = backupFolder + backupFileName; @@ -66,7 +66,7 @@ namespace Core.Helper { DateTime maxAge = DateTime.UtcNow.AddMinutes(-maxMinutes); - if (file.LastWriteTime < maxAge) + if (file.LastWriteTimeUtc < maxAge) { File.Delete(file.FullName); } @@ -85,7 +85,7 @@ namespace Core.Helper { DateTime maxAge = DateTime.UtcNow.AddHours(-(maxHours + 1)); - if (file.LastWriteTime < maxAge) + if (file.LastWriteTimeUtc < maxAge) { File.Delete(file.FullName); } diff --git a/Core/Main/PTMagic.cs b/Core/Main/PTMagic.cs index 15cd4ef..2521b45 100644 --- a/Core/Main/PTMagic.cs +++ b/Core/Main/PTMagic.cs @@ -893,7 +893,7 @@ namespace Core.Main if (File.Exists(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + Constants.PTMagicPathData + Path.DirectorySeparatorChar + "LastRuntimeSummary.json")) { FileInfo fiLastSummary = new FileInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + Constants.PTMagicPathData + Path.DirectorySeparatorChar + "LastRuntimeSummary.json"); - if (fiLastSummary.LastWriteTime < DateTime.UtcNow.AddMinutes(-(this.PTMagicConfiguration.AnalyzerSettings.MarketAnalyzer.IntervalMinutes * 2))) + if (fiLastSummary.LastWriteTimeUtc < DateTime.UtcNow.AddMinutes(-(this.PTMagicConfiguration.AnalyzerSettings.MarketAnalyzer.IntervalMinutes * 2))) { Log.DoLogWarn("PTMagic seems to have frozen after raid " + this.RunCount.ToString() + ", but don't worry I will sacrifice some Magicbots to get this running again..."); this.State = Constants.PTMagicBotState_Idle; @@ -916,7 +916,7 @@ namespace Core.Main FileInfo generalSettingsFile = new FileInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings.general.json"); FileInfo analyzerSettingsFile = new FileInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings.analyzer.json"); - if (generalSettingsFile.LastWriteTime > this.LastSettingFileCheck || analyzerSettingsFile.LastWriteTime > this.LastSettingFileCheck || EnforceSettingsReapply) + if (generalSettingsFile.LastWriteTimeUtc > this.LastSettingFileCheck || analyzerSettingsFile.LastWriteTimeUtc > this.LastSettingFileCheck || EnforceSettingsReapply) { Log.DoLogInfo("Detected configuration changes. Reloading settings..."); diff --git a/Core/MarketAnalyzer/BaseAnalyzer.cs b/Core/MarketAnalyzer/BaseAnalyzer.cs index b818c44..8a1e478 100644 --- a/Core/MarketAnalyzer/BaseAnalyzer.cs +++ b/Core/MarketAnalyzer/BaseAnalyzer.cs @@ -27,9 +27,11 @@ namespace Core.MarketAnalyzer request.UserAgent = "PTMagic.Import"; request.KeepAlive = true; + HttpWebResponse httpResponse = null; + try { - HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse(); + httpResponse = (HttpWebResponse)request.GetResponse(); StreamReader jsonReader = new StreamReader(httpResponse.GetResponseStream()); string jsonString = jsonReader.ReadToEnd(); @@ -41,7 +43,18 @@ namespace Core.MarketAnalyzer } catch (WebException ex) { - log.DoLogCritical(ex.Message, 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); + + using (var stream = httpResponse.GetResponseStream()) + { + var reader = new StreamReader(stream, encoding); + responseString = reader.ReadToEnd(); + } + + log.DoLogCritical(String.Format("{0} - Response: ({1}) {2} : {3}", ex.Message, httpResponse.StatusCode, httpResponse.StatusDescription, responseString), ex); + throw ex; } catch (Exception ex) @@ -199,7 +212,7 @@ namespace Core.MarketAnalyzer { double result = 1; - string baseUrl = "http://free.currencyconverterapi.com/api/v5/convert?q=USD_" + currency + "&compact=y"; + string baseUrl = "http://free.currencyconverterapi.com/api/v5/convert?q=USD_" + currency + "&compact=y&apiKey=sample-api-key"; log.DoLogDebug("http://free.currencyconverterapi.com - Getting latest exchange rates..."); Newtonsoft.Json.Linq.JObject jsonObject = GetSimpleJsonObjectFromURL(baseUrl, log, false); diff --git a/PTMagic/_presets/Default/DCA.PROPERTIES b/PTMagic/_presets/Default/DCA.PROPERTIES index f92b0a7..41305a7 100644 --- a/PTMagic/_presets/Default/DCA.PROPERTIES +++ b/PTMagic/_presets/Default/DCA.PROPERTIES @@ -1,7 +1,7 @@ # #################################### # ####### PTMagic Current Setting ######## # PTMagic_ActiveSetting = Default -# PTMagic_LastChanged = 7/30/18 10:58 PM +# PTMagic_LastChanged = 17/02/2019 18:11 # #################################### ############################ @@ -72,10 +72,3 @@ DEFAULT_DCA_A_buy_value_limit = 0 DEFAULT_DCA_B_buy_strategy = STOCHRSI DEFAULT_DCA_B_buy_value = 0.2 DEFAULT_DCA_B_buy_value_limit = 0 - -################ -##### Dust ##### -BTC_dust = 0.000999 -ETH_dust = 0.00999 -BNB_dust = 0.0105 -USDT_dust = 9.99 diff --git a/PTMagic/_presets/Default/INDICATORS.PROPERTIES b/PTMagic/_presets/Default/INDICATORS.PROPERTIES index 905dc8e..6054d72 100644 --- a/PTMagic/_presets/Default/INDICATORS.PROPERTIES +++ b/PTMagic/_presets/Default/INDICATORS.PROPERTIES @@ -1,7 +1,7 @@ # #################################### # ####### PTMagic Current Setting ######## # PTMagic_ActiveSetting = Default -# PTMagic_LastChanged = 7/30/18 10:58 PM +# PTMagic_LastChanged = 17/02/2019 18:11 # #################################### OBV_candle_period = 300 diff --git a/PTMagic/_presets/Default/PAIRS.PROPERTIES b/PTMagic/_presets/Default/PAIRS.PROPERTIES index 391b00f..be7f96c 100644 --- a/PTMagic/_presets/Default/PAIRS.PROPERTIES +++ b/PTMagic/_presets/Default/PAIRS.PROPERTIES @@ -1,7 +1,7 @@ # #################################### # ####### PTMagic Current Setting ######## # PTMagic_ActiveSetting = Default -# PTMagic_LastChanged = 7/30/18 10:58 PM +# PTMagic_LastChanged = 17/02/2019 18:11 # #################################### ############################