From 992ba2a713bfce78e347cc6a8e60b4f256f3eaa3 Mon Sep 17 00:00:00 2001 From: HojouFotytu <36724681+HojouFotytu@users.noreply.github.com> Date: Sat, 8 Aug 2020 02:13:22 +0900 Subject: [PATCH 1/3] removed formula parsing --- Core/ProfitTrailer/StrategyHelper.cs | 36 ++++------------------------ 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/Core/ProfitTrailer/StrategyHelper.cs b/Core/ProfitTrailer/StrategyHelper.cs index 4b7a363..3a7442c 100644 --- a/Core/ProfitTrailer/StrategyHelper.cs +++ b/Core/ProfitTrailer/StrategyHelper.cs @@ -219,7 +219,6 @@ namespace Core.ProfitTrailer string strategyNameOnly = strategyName; // PT allows for "advanced_stats" to be turned on in the application settings, to show details of the trailing logic. - // This code ensures PTM doesn't generate an unnecessary shortcut for this information if (result.Contains("STATS")) { result = ""; @@ -592,7 +591,6 @@ namespace Core.ProfitTrailer isValidStrategy = StrategyHelper.IsValidStrategy(strategy.Name); if (!isValidStrategy) { - if (strategy.Name.Contains("TRIGGERED")) // remove levels already triggered, to show only currently waiting trigger { @@ -609,37 +607,13 @@ namespace Core.ProfitTrailer if (strategy.Name.Contains("LEVEL")) // level X { - string level = strategy.Name.Substring(5, 2); - string expression = strategy.Name.Remove(0, 17); - expression = expression.Replace("", "true").Replace("", "false").Replace("", "").Replace("&&", "and").Replace("||", "or"); - expression = regx.Replace(expression, String.Empty); - var tokens = new Tokenizer(expression).Tokenize(); - var parser = new Parser(tokens); - if (parser.Parse()) - { - strategyText += "L " + level + " "; - } - else - { - strategyText += "L " + level + " "; - } + string level = strategy.Name.Substring(5, 1); + strategyText += "L " + level + " "; } else // standard formula { - string expression = strategy.Name.Remove(0, 10); - expression = expression.Replace("", "true").Replace("", "false").Replace("", "").Replace("&&", "and").Replace("||", "or"); - expression = regx.Replace(expression, String.Empty); - var tokens = new Tokenizer(expression).Tokenize(); - var parser = new Parser(tokens); - if (parser.Parse()) - { - strategyText += "FORM "; - } - else - { - strategyText += "FORM "; - } + strategyText += "FORM "; } } else @@ -663,7 +637,7 @@ namespace Core.ProfitTrailer { if (isTrue) { - strategyText = "" + StrategyHelper.GetStrategyShortcut(strategyText, true) + ""; + strategyText = "" + StrategyHelper.GetStrategyShortcut(strategyText, true) + " "; if (isTrailingBuyActive) { @@ -675,7 +649,7 @@ namespace Core.ProfitTrailer isValidStrategy = StrategyHelper.IsValidStrategy(strategyText); if (isValidStrategy) { - strategyText = "" + StrategyHelper.GetStrategyShortcut(strategyText, true) + ""; + strategyText = "" + StrategyHelper.GetStrategyShortcut(strategyText, true) + " "; } else if (strategyText.Equals("") && isValidStrategy == false) { From e7b4b6ba7da455f981cb8e8ef88fd8b6ea6631f0 Mon Sep 17 00:00:00 2001 From: HojouFotytu <36724681+HojouFotytu@users.noreply.github.com> Date: Sat, 8 Aug 2020 12:08:36 +0900 Subject: [PATCH 2/3] Parser removed --- Core/ProfitTrailer/StrategyHelper.cs | 205 +-------------------------- PTMagic/Program.cs | 2 +- 2 files changed, 3 insertions(+), 204 deletions(-) diff --git a/Core/ProfitTrailer/StrategyHelper.cs b/Core/ProfitTrailer/StrategyHelper.cs index 3a7442c..997c124 100644 --- a/Core/ProfitTrailer/StrategyHelper.cs +++ b/Core/ProfitTrailer/StrategyHelper.cs @@ -9,205 +9,6 @@ using System.Text.RegularExpressions; namespace Core.ProfitTrailer { - public class OperandToken : Token - { - } - public class OrToken : OperandToken - { - } - - public class AndToken : OperandToken - { - } - - public class BooleanValueToken : Token - { - } - - public class FalseToken : BooleanValueToken - { - } - - public class TrueToken : BooleanValueToken - { - } - - public class ParenthesisToken : Token - { - } - - public class ClosedParenthesisToken : ParenthesisToken - { - } - - public class OpenParenthesisToken : ParenthesisToken - { - } - - public class NegationToken : Token - { - } - - public abstract class Token - { - } - - public class Tokenizer - { - private readonly StringReader _reader; - private string _text; - - public Tokenizer(string text) - { - _text = text; - _reader = new StringReader(text); - } - - public IEnumerable Tokenize() - { - var tokens = new List(); - while (_reader.Peek() != -1) - { - while (Char.IsWhiteSpace((char)_reader.Peek())) - { - _reader.Read(); - } - - if (_reader.Peek() == -1) - break; - - var c = (char)_reader.Peek(); - switch (c) - { - case '!': - tokens.Add(new NegationToken()); - _reader.Read(); - break; - case '(': - tokens.Add(new OpenParenthesisToken()); - _reader.Read(); - break; - case ')': - tokens.Add(new ClosedParenthesisToken()); - _reader.Read(); - break; - default: - if (Char.IsLetter(c)) - { - var token = ParseKeyword(); - tokens.Add(token); - } - else - { - var remainingText = _reader.ReadToEnd() ?? string.Empty; - throw new Exception(string.Format("Unknown grammar found at position {0} : '{1}'", _text.Length - remainingText.Length, remainingText)); - } - break; - } - } - return tokens; - } - - private Token ParseKeyword() - { - var text = new StringBuilder(); - while (Char.IsLetter((char)_reader.Peek())) - { - text.Append((char)_reader.Read()); - } - - var potentialKeyword = text.ToString().ToLower(); - - switch (potentialKeyword) - { - case "true": - return new TrueToken(); - case "false": - return new FalseToken(); - case "and": - return new AndToken(); - case "or": - return new OrToken(); - default: - throw new Exception("Expected keyword (True, False, and, or) but found " + potentialKeyword); - } - } - } - public class Parser - { - private readonly IEnumerator _tokens; - - public Parser(IEnumerable tokens) - { - _tokens = tokens.GetEnumerator(); - _tokens.MoveNext(); - } - - public bool Parse() - { - while (_tokens.Current != null) - { - var isNegated = _tokens.Current is NegationToken; - if (isNegated) - _tokens.MoveNext(); - - var boolean = ParseBoolean(); - if (isNegated) - boolean = !boolean; - - while (_tokens.Current is OperandToken) - { - var operand = _tokens.Current; - if (!_tokens.MoveNext()) - { - throw new Exception("Missing expression after operand"); - } - var nextBoolean = ParseBoolean(); - - if (operand is AndToken) - boolean = boolean && nextBoolean; - else - boolean = boolean || nextBoolean; - } - return boolean; - } - throw new Exception("Empty expression"); - } - - private bool ParseBoolean() - { - if (_tokens.Current is BooleanValueToken) - { - var current = _tokens.Current; - _tokens.MoveNext(); - - if (current is TrueToken) - return true; - - return false; - } - if (_tokens.Current is OpenParenthesisToken) - { - _tokens.MoveNext(); - - var expInPars = Parse(); - - if (!(_tokens.Current is ClosedParenthesisToken)) - throw new Exception("Expecting Closing Parenthesis"); - - _tokens.MoveNext(); - - return expInPars; - } - if (_tokens.Current is ClosedParenthesisToken) - throw new Exception("Unexpected Closed Parenthesis"); - - // since its not a BooleanConstant or Expression in parenthesis, it must be a expression again - var val = Parse(); - return val; - } - } - public static class StrategyHelper { public static string GetStrategyShortcut(string strategyName, bool onlyValidStrategies) @@ -597,21 +398,19 @@ namespace Core.ProfitTrailer strategyText += ""; } else if (strategy.Name.Contains("STATS")) - // avoid parsing advanced buy stats + // Avoid displaying advanced buy stats and completed level formulas { strategy.Name = ""; } else if (strategy.Name.Contains("FORMULA")) - // Parse Various PT Formulas + // Avoid displaying formula details { if (strategy.Name.Contains("LEVEL")) - // level X { string level = strategy.Name.Substring(5, 1); strategyText += "L " + level + " "; } else - // standard formula { strategyText += "FORM "; } diff --git a/PTMagic/Program.cs b/PTMagic/Program.cs index 2489c1c..cb5a388 100644 --- a/PTMagic/Program.cs +++ b/PTMagic/Program.cs @@ -6,7 +6,7 @@ using Core.Helper; using Microsoft.Extensions.DependencyInjection; -[assembly: AssemblyVersion("2.4.4")] +[assembly: AssemblyVersion("2.4.5")] [assembly: AssemblyProduct("PT Magic")] namespace PTMagic From 9bbb5389ab8055ff4cf497039578f3582d93da45 Mon Sep 17 00:00:00 2001 From: HojouFotytu <36724681+HojouFotytu@users.noreply.github.com> Date: Sat, 8 Aug 2020 13:12:54 +0900 Subject: [PATCH 3/3] Fix rebuy shortcuts --- Core/ProfitTrailer/StrategyHelper.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Core/ProfitTrailer/StrategyHelper.cs b/Core/ProfitTrailer/StrategyHelper.cs index 997c124..7294cbd 100644 --- a/Core/ProfitTrailer/StrategyHelper.cs +++ b/Core/ProfitTrailer/StrategyHelper.cs @@ -19,15 +19,20 @@ namespace Core.ProfitTrailer string strategyLetter = ""; string strategyNameOnly = strategyName; - // PT allows for "advanced_stats" to be turned on in the application settings, to show details of the trailing logic. + // PT allows for "advanced_stats" to show details of the trailing logic. if (result.Contains("STATS")) { result = ""; } - // strategy labels that are variable value - if (result.Contains("REBUY")) + // strategy labels with variable values + if (result.Contains("BUY TIMEOUT AS")) { - time = strategyName.Remove(0, 14); + time = strategyName.Remove(0, 15); + result = "REBUY " + time; + } + if (result.Contains("BUY TIMEOUT")) + { + time = strategyName.Remove(0, 12); result = "REBUY " + time; } if (result.Contains("CHANGE PERC")) @@ -46,7 +51,6 @@ namespace Core.ProfitTrailer leverage = leverage.Remove(leverage.Length - 1, 1); result = "ISOL " + leverage + "X"; } - // buy/sell strategies beginning with PT 2.3.3 contain the strategy designation letter followed by a colon and space. // remove the letter and colon, change to shortcut, then reapply the letter and colon if (strategyName.Contains(":")) {