diff --git a/Core/Main/PTMagic.cs b/Core/Main/PTMagic.cs index 623e227..d731e8e 100644 --- a/Core/Main/PTMagic.cs +++ b/Core/Main/PTMagic.cs @@ -2095,18 +2095,11 @@ namespace Core.Main // Save current PT properties to API (Valid for PT 2.x and above) this.Log.DoLogInfo("Saving properties using API..."); - // Send Pairs.properties - if (!this.PTMagicConfiguration.GeneralSettings.Application.TestMode) SettingsAPI.SendPropertyLinesToAPI("PAIRS", this.PairsLines, this.PTMagicConfiguration, this.Log); + // Send all Properties + if (!this.PTMagicConfiguration.GeneralSettings.Application.TestMode) SettingsAPI.SendPropertyLinesToAPI(this.PairsLines, this.DCALines, this.IndicatorsLines, this.PTMagicConfiguration, this.Log); - // Send DCA.properties - if (!this.PTMagicConfiguration.GeneralSettings.Application.TestMode) SettingsAPI.SendPropertyLinesToAPI("DCA", this.DCALines, this.PTMagicConfiguration, this.Log); - - // Send Indicators.properties - if (!this.PTMagicConfiguration.GeneralSettings.Application.TestMode) SettingsAPI.SendPropertyLinesToAPI("INDICATORS", this.IndicatorsLines, this.PTMagicConfiguration, this.Log); - - this.Log.DoLogInfo("All properties saved!"); + this.Log.DoLogInfo("Properties saved!"); } - } else { diff --git a/Core/ProfitTrailer/SettingsAPI.cs b/Core/ProfitTrailer/SettingsAPI.cs index f26b428..501f3d6 100644 --- a/Core/ProfitTrailer/SettingsAPI.cs +++ b/Core/ProfitTrailer/SettingsAPI.cs @@ -80,7 +80,7 @@ namespace Core.ProfitTrailer return result; } - public static void SendPropertyLinesToAPI(string ptFileName, List lines, PTMagicConfiguration systemConfiguration, LogHelper log) + public static void SendPropertyLinesToAPI(List pairsLines, List dcaLines, List indicatorsLines, PTMagicConfiguration systemConfiguration, LogHelper log) { int retryCount = 0; int maxRetries = 3; @@ -96,16 +96,18 @@ namespace Core.ProfitTrailer ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(CertificateHelper.AllwaysGoodCertificate); - HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(systemConfiguration.GeneralSettings.Application.ProfitTrailerMonitorURL + "settingsapi/settings/save"); + HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(systemConfiguration.GeneralSettings.Application.ProfitTrailerMonitorURL + "settingsapi/settings/saveAll"); httpWebRequest.ContentType = "application/x-www-form-urlencoded"; httpWebRequest.Method = "POST"; httpWebRequest.Proxy = null; httpWebRequest.Timeout = 30000; // PT is using ordinary POST data, not JSON - string query = "fileName=" + ptFileName + "&configName=" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "&license=" + systemConfiguration.GeneralSettings.Application.ProfitTrailerLicense; - string propertiesString = SystemHelper.ConvertListToTokenString(lines, Environment.NewLine, false); - query += "&saveData=" + WebUtility.UrlEncode(propertiesString); + string query = "configName=" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "&license=" + systemConfiguration.GeneralSettings.Application.ProfitTrailerLicense; + string pairsPropertiesString = SystemHelper.ConvertListToTokenString(pairsLines, Environment.NewLine, false); + string dcaPropertiesString = SystemHelper.ConvertListToTokenString(dcaLines, Environment.NewLine, false); + string indicatorsPropertiesString = SystemHelper.ConvertListToTokenString(indicatorsLines, Environment.NewLine, false); + query += "&pairsData=" + WebUtility.UrlEncode(pairsPropertiesString) + "&dcaData=" + WebUtility.UrlEncode(dcaPropertiesString) + "&indicatorsData=" + WebUtility.UrlEncode(indicatorsPropertiesString); byte[] formData = Encoding.ASCII.GetBytes(query); httpWebRequest.ContentLength = formData.Length; @@ -114,7 +116,7 @@ namespace Core.ProfitTrailer { stream.Write(formData, 0, formData.Length); } - log.DoLogDebug("Built POST request for " + ptFileName + ".properties."); + log.DoLogDebug("Built POST request for Properties"); //using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { // string json = JsonConvert.SerializeObject(new { @@ -127,11 +129,11 @@ namespace Core.ProfitTrailer // streamWriter.Write(json); //} - log.DoLogInfo("Sending " + ptFileName + ".properties..."); + log.DoLogInfo("Sending Properties..."); HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); - log.DoLogInfo(ptFileName + ".properties sent!"); + log.DoLogInfo("Properties sent!"); httpResponse.Close(); - log.DoLogDebug(ptFileName + ".properties response object closed."); + log.DoLogDebug("Properties response object closed."); transferCompleted = true; } @@ -140,7 +142,7 @@ namespace Core.ProfitTrailer // Manual error handling as PT doesn't seem to provide a proper error response... if (ex.Message.IndexOf("401") > -1) { - log.DoLogError("Saving " + ptFileName + ".properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': Unauthorized! The specified Profit Trailer license key '" + systemConfiguration.GetProfitTrailerLicenseKeyMasked() + "' is invalid!"); + log.DoLogError("Saving Properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': Unauthorized! The specified Profit Trailer license key '" + systemConfiguration.GetProfitTrailerLicenseKeyMasked() + "' is invalid!"); transferCanceled = true; } else if (ex.Message.IndexOf("timed out") > -1) @@ -149,17 +151,17 @@ namespace Core.ProfitTrailer retryCount++; if (retryCount <= maxRetries) { - log.DoLogError("Saving " + ptFileName + ".properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': Timeout! Starting retry number " + retryCount + "/" + maxRetries.ToString() + "!"); + log.DoLogError("Saving Properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': Timeout! Starting retry number " + retryCount + "/" + maxRetries.ToString() + "!"); } else { transferCanceled = true; - log.DoLogError("Saving " + ptFileName + ".properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': Timeout! Canceling transfer after " + maxRetries.ToString() + " failed retries."); + log.DoLogError("Saving Properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': Timeout! Canceling transfer after " + maxRetries.ToString() + " failed retries."); } } else { - log.DoLogCritical("Saving " + ptFileName + ".properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': " + ex.Message, ex); + log.DoLogCritical("Saving Properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': " + ex.Message, ex); transferCanceled = true; } @@ -169,17 +171,17 @@ namespace Core.ProfitTrailer retryCount++; if (retryCount <= maxRetries) { - log.DoLogError("Saving " + ptFileName + ".properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': Timeout (" + ex.Message + ")! Starting retry number " + retryCount + "/" + maxRetries.ToString() + "!"); + log.DoLogError("Saving Properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': Timeout (" + ex.Message + ")! Starting retry number " + retryCount + "/" + maxRetries.ToString() + "!"); } else { transferCanceled = true; - log.DoLogError("Saving " + ptFileName + ".properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': Timeout (" + ex.Message + ")! Canceling transfer after " + maxRetries.ToString() + " failed retries."); + log.DoLogError("Saving Properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': Timeout (" + ex.Message + ")! Canceling transfer after " + maxRetries.ToString() + " failed retries."); } } catch (Exception ex) { - log.DoLogCritical("Saving " + ptFileName + ".properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': " + ex.Message, ex); + log.DoLogCritical("Saving Properties failed for setting '" + systemConfiguration.GeneralSettings.Application.ProfitTrailerDefaultSettingName + "': " + ex.Message, ex); transferCanceled = true; } }