Merge pull request #341 from HojouFotytu/develop

2.8.3
This commit is contained in:
HojouFotytu 2024-02-07 16:02:44 +09:00 committed by GitHub
commit c3cbb4908e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 70 additions and 18 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Data;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Threading;
@ -852,6 +853,8 @@ namespace Core.Main
#region PTMagic Interval Methods
public void PTMagicIntervalTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
// Check if the bot is idle
@ -1297,6 +1300,8 @@ namespace Core.Main
}
}
private void BuildGlobalMarketTrends()
{
this.Log.DoLogInfo("Build global market trends...");
@ -1415,9 +1420,17 @@ namespace Core.Main
// New logic
string triggerConnection = globalSetting.TriggerConnection;
foreach (var triggerResult in triggerResults)
{
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 {globalSetting.SettingName}. Program halted.");
Environment.Exit(1); // Stop the program
}
}
try
{
@ -1815,6 +1828,14 @@ namespace Core.Main
Dictionary<int, double> relevantTriggers = new Dictionary<int, double>();
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
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);
triggerResults.Add(true);
triggerTagsResults[trigger.Tag] = true;
}
else
{
@ -1880,6 +1902,7 @@ namespace Core.Main
relevantTriggers.Add(triggerIndex, marketAge);
triggerResults.Add(true);
triggerTagsResults[trigger.Tag] = true;
}
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")) + "%");
triggerResults.Add(true);
triggerTagsResults[trigger.Tag] = true;
}
else
{
@ -2002,8 +2026,11 @@ namespace Core.Main
triggerIndex++;
} // End loop SMS triggers
// Check if all triggers have to get triggered or just one
bool settingTriggered = false;
if (marketSetting.TriggerConnection.ToLower() == "and" || marketSetting.TriggerConnection.ToLower() == "or")
{
switch (marketSetting.TriggerConnection.ToLower())
{
case "and":
@ -2013,6 +2040,37 @@ namespace Core.Main
settingTriggered = triggerResults.FindAll(tr => tr == true).Count > 0;
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
bool isFreshTrigger = true;

View File

@ -29,20 +29,14 @@
<div class="form-group row">
<label class="col-md-4 col-form-label">Trigger Connection <i class="fa fa-info-circle text-muted" data-toggle="tooltip" data-placement="top" title="Define if triggers will be connected by AND or OR"></i></label>
<div class="col-md-8">
<select name="MarketAnalyzer_SingleMarketSetting_@(Model.SettingName)|TriggerConnection" class="form-control">
<option selected="@(Model.SingleMarketSetting.TriggerConnection.Equals("AND", StringComparison.InvariantCultureIgnoreCase))">AND</option>
<option selected="@(Model.SingleMarketSetting.TriggerConnection.Equals("OR", StringComparison.InvariantCultureIgnoreCase))">OR</option>
</select>
<input type="text" name="MarketAnalyzer_SingleMarketSetting_@(Model.SettingName)|TriggerConnection" class="form-control" value="@Model.SingleMarketSetting.TriggerConnection" />
</div>
</div>
<div class="form-group row">
<label class="col-md-4 col-form-label">Off Trigger Connection <i class="fa fa-info-circle text-muted" data-toggle="tooltip" data-placement="top" title="Define if off triggers will be connected by AND or OR"></i></label>
<div class="col-md-8">
<select name="MarketAnalyzer_SingleMarketSetting_@(Model.SettingName)|OffTriggerConnection" class="form-control">
<option selected="@(Model.SingleMarketSetting.OffTriggerConnection.Equals("AND", StringComparison.InvariantCultureIgnoreCase))">AND</option>
<option selected="@(Model.SingleMarketSetting.OffTriggerConnection.Equals("OR", StringComparison.InvariantCultureIgnoreCase))">OR</option>
</select>
<input type="text" name="MarketAnalyzer_SingleMarketSetting_@(Model.SettingName)|OffTriggerConnection" class="form-control" value="@Model.SingleMarketSetting.OffTriggerConnection" />
</div>
</div>

View File

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