SMS new logic

This commit is contained in:
HojouFotytu 2024-02-05 19:16:57 +09:00
parent 39b00b6750
commit c2fd70dfea
2 changed files with 68 additions and 10 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Data;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Threading; using System.Threading;
@ -852,6 +853,8 @@ namespace Core.Main
#region PTMagic Interval Methods #region PTMagic Interval Methods
public void PTMagicIntervalTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) public void PTMagicIntervalTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
// Check if the bot is idle // Check if the bot is idle
@ -1297,6 +1300,8 @@ namespace Core.Main
} }
} }
private void BuildGlobalMarketTrends() private void BuildGlobalMarketTrends()
{ {
this.Log.DoLogInfo("Build global market trends..."); this.Log.DoLogInfo("Build global market trends...");
@ -1415,9 +1420,17 @@ namespace Core.Main
// New logic // New logic
string triggerConnection = globalSetting.TriggerConnection; string triggerConnection = globalSetting.TriggerConnection;
foreach (var triggerResult in triggerResults) foreach (var triggerResult in triggerResults)
{
if (!string.IsNullOrEmpty(triggerResult.Key))
{ {
triggerConnection = triggerConnection.Replace(triggerResult.Key, triggerResult.Value.ToString().ToLower()); triggerConnection = triggerConnection.Replace(triggerResult.Key, triggerResult.Value.ToString().ToLower());
} }
else
{
this.Log.DoLogError($"ERROR: A required trigger Tag is missing for global setting {globalSetting.SettingName}. Program halted.");
Environment.Exit(1); // Stop the program
}
}
try try
{ {
@ -1815,6 +1828,14 @@ namespace Core.Main
Dictionary<int, double> relevantTriggers = new Dictionary<int, double>(); Dictionary<int, double> relevantTriggers = new Dictionary<int, double>();
int triggerIndex = 0; int triggerIndex = 0;
// Create a dictionary to store the tag and its corresponding result
Dictionary<string, bool> triggerTagsResults = new Dictionary<string, bool>();
// Initialize all tags with a value of false
foreach (Trigger trigger in marketSetting.Triggers)
{
triggerTagsResults[trigger.Tag] = false;
}
// Loop through SMS triggers // Loop through SMS triggers
foreach (Trigger trigger in marketSetting.Triggers) foreach (Trigger trigger in marketSetting.Triggers)
{ {
@ -1850,6 +1871,7 @@ namespace Core.Main
matchedSingleMarketTriggers.Add(marketSetting.SettingName + ": " + triggerContent + " - 24h volume = " + mtc.Volume24h.ToString(new System.Globalization.CultureInfo("en-US")) + " " + this.LastRuntimeSummary.MainMarket); matchedSingleMarketTriggers.Add(marketSetting.SettingName + ": " + triggerContent + " - 24h volume = " + mtc.Volume24h.ToString(new System.Globalization.CultureInfo("en-US")) + " " + this.LastRuntimeSummary.MainMarket);
triggerResults.Add(true); triggerResults.Add(true);
triggerTagsResults[trigger.Tag] = true;
} }
else else
{ {
@ -1880,6 +1902,7 @@ namespace Core.Main
relevantTriggers.Add(triggerIndex, marketAge); relevantTriggers.Add(triggerIndex, marketAge);
triggerResults.Add(true); triggerResults.Add(true);
triggerTagsResults[trigger.Tag] = true;
} }
else else
{ {
@ -1961,6 +1984,7 @@ namespace Core.Main
matchedSingleMarketTriggers.Add(marketSetting.SettingName + ": " + triggerContent + " - TrendChange (" + trigger.MarketTrendRelation + ") = " + trendChange.ToString("#,#0.00", new System.Globalization.CultureInfo("en-US")) + "%"); matchedSingleMarketTriggers.Add(marketSetting.SettingName + ": " + triggerContent + " - TrendChange (" + trigger.MarketTrendRelation + ") = " + trendChange.ToString("#,#0.00", new System.Globalization.CultureInfo("en-US")) + "%");
triggerResults.Add(true); triggerResults.Add(true);
triggerTagsResults[trigger.Tag] = true;
} }
else else
{ {
@ -2002,8 +2026,11 @@ namespace Core.Main
triggerIndex++; triggerIndex++;
} // End loop SMS triggers } // End loop SMS triggers
// Check if all triggers have to get triggered or just one // Check if all triggers have to get triggered or just one
bool settingTriggered = false; bool settingTriggered = false;
if (marketSetting.TriggerConnection.ToLower() == "and" || marketSetting.TriggerConnection.ToLower() == "or")
{
switch (marketSetting.TriggerConnection.ToLower()) switch (marketSetting.TriggerConnection.ToLower())
{ {
case "and": case "and":
@ -2013,6 +2040,37 @@ namespace Core.Main
settingTriggered = triggerResults.FindAll(tr => tr == true).Count > 0; settingTriggered = triggerResults.FindAll(tr => tr == true).Count > 0;
break; break;
} }
}
else
{
// Parse the TriggerConnection string into a logical expression
string triggerConnection = marketSetting.TriggerConnection;
foreach (var triggerResult in triggerTagsResults)
{
// Replace the tag in the expression with its corresponding value from triggerTagsResults
if (!string.IsNullOrEmpty(triggerResult.Key))
{
triggerConnection = triggerConnection.Replace(triggerResult.Key, triggerResult.Value.ToString().ToLower());
}
else
{
this.Log.DoLogError($"ERROR: A required trigger Tag is missing for global setting {marketSetting.SettingName}. Program halted.");
Environment.Exit(1); // Stop the program
}
}
try
{
// Evaluate the expression using ParseLambda
settingTriggered = (bool)DynamicExpressionParser.ParseLambda(ParsingConfig.Default, new ParameterExpression[0], typeof(bool), triggerConnection).Compile().DynamicInvoke();
}
catch (Exception ex)
{
this.Log.DoLogError($"ERROR: Trigger Connection for global setting {marketSetting.SettingName} is invalid or missing. Program halted.");
Environment.Exit(1); // Stop the program
}
}
#endregion #endregion
bool isFreshTrigger = true; bool isFreshTrigger = true;

View File

@ -6,7 +6,7 @@ using Core.Helper;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
[assembly: AssemblyVersion("2.8.2")] [assembly: AssemblyVersion("2.8.3")]
[assembly: AssemblyProduct("PT Magic")] [assembly: AssemblyProduct("PT Magic")]
namespace PTMagic namespace PTMagic