public void OnSuggestedActionExecuted(SuggestedAction action)
        {
            // We'll need to be on the UI thread for the operations.
            AssertIsForeground();

            // If the user has previously clicked don't show again, then we bail out immediately
            if (_workspace.Options.GetOption(FxCopAnalyzersInstallOptions.NeverShowAgain) ||
                _workspace.Options.GetOption(FxCopAnalyzersInstallOptions.NeverShowAgain_CodeAnalysis2017))
            {
                return;
            }

            // Only show if following conditions are satisfied:
            // 1. Info bar hasn't been shown this session
            // 2. FxCopAnalyzers VSIX is not installed
            // 3. FxCopAnalyzers NuGet is not installed
            // 4. There are no unresolved analyzer references for active project and
            // 5. User is candidate based on light bulb usage.
            if (!_infoBarChecked &&
                !IsVsixInstalled() &&
                !IsNuGetInstalled(out var hasUnresolvedAnalyzerReference) &&
                !hasUnresolvedAnalyzerReference &&
                IsCandidate(action))
            {
                ShowInfoBarIfNecessary();
            }
        }
Ejemplo n.º 2
0
        //static public decimal SavedMoney { get; set; }
        //static public decimal SavedCoins { get; set; }

        public static string CsvRow()
        {
            return(string.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}",

                                 CandleDate.ToString(CultureInfo.InvariantCulture),
                                 Bid.ToString(CultureInfo.InvariantCulture),

                                 Math.Round(EmaDiff, 4).ToString(CultureInfo.InvariantCulture),
                                 Math.Round(Macd, 4).ToString(CultureInfo.InvariantCulture),
                                 Math.Round(MacdStandard, 4).ToString(CultureInfo.InvariantCulture),
                                 Math.Round(Roc, 4).ToString(CultureInfo.InvariantCulture),
                                 Math.Round(RocSpeed, 4).ToString(CultureInfo.InvariantCulture),

                                 CurrentTrend.ToString(),
                                 CurrentLongTermTrend.ToString(),
                                 SuggestedAction.ToString(),
                                 (Action == TradeAction.Unknown || Action == TradeAction.Hold) ? "" : Action.ToString(),
                                 Indicator,
                                 Motivation,
                                 Note,
                                 Math.Round(TotMoney, 4).ToString(CultureInfo.InvariantCulture),
                                 Math.Round(TotCoins, 4).ToString(CultureInfo.InvariantCulture),
                                 Math.Round(TotValue, 4).ToString(CultureInfo.InvariantCulture),
                                 Math.Round(SellAt, 4).ToString(CultureInfo.InvariantCulture),
                                 Math.Round(BuyAt, 4).ToString(CultureInfo.InvariantCulture)

                                 ));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Hides a suggested action
 /// </summary>
 public static Task <Ok> HideSuggestedActionAsync(
     this Client client, SuggestedAction action = default)
 {
     return(client.ExecuteAsync(new HideSuggestedAction
     {
         Action = action
     }));
 }
Ejemplo n.º 4
0
        private SuggestedAction GetFinalSuggestion(List <SuggestedAction> indicatorSuggestions,
                                                   SuggestedAction secondSuggestion)
        {
            var list = new List <SuggestedAction>
            {
                secondSuggestion
            };

            list.AddRange(indicatorSuggestions);
            var actions = new List <SuggestedAction>();

            foreach (var item in indicatorSuggestions)
            {
                switch (item)
                {
                case SuggestedAction.OSCToBuy:
                case SuggestedAction.RSIToBuy:
                    actions.Add(SuggestedAction.Buy);
                    break;

                case SuggestedAction.RSIToWait:
                    actions.Add(SuggestedAction.Wait);
                    break;

                case SuggestedAction.OSCToSell:
                case SuggestedAction.RSIToSell:
                    actions.Add(SuggestedAction.Sell);
                    break;
                }
            }
            if (actions.All(a => a == SuggestedAction.Sell) &&
                secondSuggestion == SuggestedAction.BuyTheDip)
            {
                return(SuggestedAction.BuyTheDip);
            }
            else if (actions.All(a => a == SuggestedAction.Buy) &&
                     (secondSuggestion == SuggestedAction.Buy ||
                      secondSuggestion == SuggestedAction.StrongBuy))
            {
                return(SuggestedAction.StrongBuy);
            }
            else if (actions.Any(a => a == SuggestedAction.Buy) &&
                     actions.Any(a => a != SuggestedAction.Sell))
            {
                return(SuggestedAction.Buy);
            }
            else if (actions.Any(a => a == SuggestedAction.Sell) &&
                     actions.Any(a => a != SuggestedAction.Buy))
            {
                return(SuggestedAction.Sell);
            }
            else
            {
                return(SuggestedAction.Wait);
            }
        }
        private string SuggestionString(decimal lowLimitPrice,
                                        decimal highLimitPrice, SuggestedAction action)
        {
            if (action == SuggestedAction.Sell)
            {
                return($" StrongSell When x < {lowLimitPrice}. Sell When x > {highLimitPrice}.");
            }

            return($"{action} When {lowLimitPrice} < x < {highLimitPrice}.");
        }
        private bool IsCandidate(SuggestedAction action)
        {
            // Candidates fill the following critera:
            //     1: Are a Dotnet user (as evidenced by the fact that this code is being run)
            //     2: Have triggered a lightbulb on 3 separate days or if this is a code quality suggested action.

            // If the user hasn't met candidacy conditions, then we check them. Otherwise, proceed
            // to info bar check
            var options     = _workspace.Options;
            var isCandidate = options.GetOption(FxCopAnalyzersInstallOptions.HasMetCandidacyRequirements);

            if (!isCandidate)
            {
                // We store in UTC to avoid any timezone offset weirdness
                var lastTriggeredTimeBinary = options.GetOption(FxCopAnalyzersInstallOptions.LastDateTimeUsedSuggestionAction);
                FxCopAnalyzersInstallLogger.LogCandidacyRequirementsTracking(lastTriggeredTimeBinary);

                var lastTriggeredTime = DateTime.FromBinary(lastTriggeredTimeBinary);
                var currentTime       = DateTime.UtcNow;
                var span = currentTime - lastTriggeredTime;
                if (span.TotalDays >= 1)
                {
                    options = options.WithChangedOption(FxCopAnalyzersInstallOptions.LastDateTimeUsedSuggestionAction, currentTime.ToBinary());

                    var usageCount = options.GetOption(FxCopAnalyzersInstallOptions.UsedSuggestedActionCount);
                    options = options.WithChangedOption(FxCopAnalyzersInstallOptions.UsedSuggestedActionCount, ++usageCount);

                    // Candidate if user has invoked the light bulb 3 times or if this is a code quality suggested action.
                    if (usageCount >= 3 || action.IsForCodeQualityImprovement)
                    {
                        isCandidate = true;
                        options     = options.WithChangedOption(FxCopAnalyzersInstallOptions.HasMetCandidacyRequirements, true);
                        FxCopAnalyzersInstallLogger.Log(nameof(FxCopAnalyzersInstallOptions.HasMetCandidacyRequirements));
                    }

                    _workspace.Options = options;
                }
            }

            return(isCandidate);
        }
Ejemplo n.º 7
0
        public AlertResult GetAlertResult()
        {
            var result = new AlertResult();

            try
            {
                result = new AlertResult
                {
                    SuggestionMessage      = GetSuggestionForCurrentSticker(),
                    Success                = true,
                    Symbol                 = CurrentSticker,
                    CurrentRSIValue        = Factory.IndicatorSuggestions.GetRSIIndicator(RsiResults),
                    CurrentChaikinOSCValue = Factory.IndicatorSuggestions.GetChaikinOSCValue(ChaikinOscResults),
                    CurrentPrice           = Math.Round(CurrentQuote.Close, 2)
                };
                var secondSuggestion = CheckForSecondAlert();
                result.SuggestedActions.Add(secondSuggestion.ToString());
                var           indicatorSuggestions = CheckForIndicatorSuggestions();
                List <string> suggestions          = GetStringSuggestions(indicatorSuggestions);
                result.SuggestedActions.AddRange(suggestions);
                FinalSuggestion        = GetFinalSuggestion(indicatorSuggestions, secondSuggestion);
                result.FinalSuggestion = FinalSuggestion.ToString();
            }
            catch (Exception ex)
            {
                result = new AlertResult
                {
                    Success      = false,
                    ErrorMessage = "Failed to get Alert and Suggestion." + ex.Message
                };
            }
            finally
            {
                if (result.Success)
                {
                    SuggestionMgr.SaveSuggestion(result);
                }
            }
            return(result);
        }
        public void OnSuggestedActionExecuted(SuggestedAction action)
        {
            // We'll need to be on the UI thread for the operations.
            AssertIsForeground();

            // If the user has previously clicked don't show again, then we bail out immediately
            if (_workspace.Options.GetOption(FxCopAnalyzersInstallOptions.NeverShowAgain) ||
                _workspace.Options.GetOption(FxCopAnalyzersInstallOptions.NeverShowAgain_CodeAnalysis2017))
            {
                return;
            }

            // Only show if the VSIX and NuGet are not installed, the info bar hasn't been shown this session,
            // and the user is candidate based on light bulb usage.
            if (!_infoBarChecked &&
                !IsVsixInstalled() &&
                !IsNuGetInstalled() &&
                IsCandidate(action))
            {
                ShowInfoBarIfNecessary();
            }
        }
        public void OnSuggestedActionExecuted(SuggestedAction action)
        {
            // If the experimentation service hasn't been retrieved, we'll need to be on the UI
            // thread to get it
            AssertIsForeground();

            // If the user has previously clicked don't show again, then we bail out immediately
            if (_workspace.Options.GetOption(AnalyzerABTestOptions.NeverShowAgain))
            {
                return;
            }

            EnsureInitialized();

            // Only show if the VSIX is not installed, the info bar hasn't been shown this session,
            // and the user is an A/B test candidate
            if (!_infoBarChecked &&
                !IsVsixInstalled() &&
                IsCandidate())
            {
                ShowInfoBarIfNecessary();
            }
        }
            private static void AddFix(CodeFix fix, SuggestedAction suggestedAction, IDictionary<DiagnosticData, IList<SuggestedAction>> map, IList<DiagnosticData> order)
            {
                var diag = fix.GetPrimaryDiagnosticData();
                if (!map.ContainsKey(diag))
                {
                    // Remember the order of the keys for the 'map' dictionary.
                    order.Add(diag);
                    map[diag] = ImmutableArray.CreateBuilder<SuggestedAction>();
                }

                map[diag].Add(suggestedAction);
            }
            /// <summary>
            /// Groups fixes by the diagnostic being addressed by each fix.
            /// </summary>
            private void GroupFixes(Workspace workspace, IEnumerable<CodeFixCollection> fixCollections, IDictionary<DiagnosticData, IList<SuggestedAction>> map, IList<DiagnosticData> order, bool hasSuppressionFixes)
            {
                foreach (var fixCollection in fixCollections)
                {
                    var fixes = fixCollection.Fixes;
                    var fixCount = fixes.Length;

                    Func<CodeAction, SuggestedActionSet> getFixAllSuggestedActionSet = codeAction =>
                                CodeFixSuggestedAction.GetFixAllSuggestedActionSet(codeAction, fixCount, fixCollection.FixAllContext,
                                    workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator);

                    foreach (var fix in fixes)
                    {
                        // Suppression fixes are handled below.
                        if (!(fix.Action is SuppressionCodeAction))
                        {
                            SuggestedAction suggestedAction;
                            if (fix.Action.HasCodeActions)
                            {
                                var nestedActions = new List<SuggestedAction>();
                                foreach (var nestedAction in fix.Action.GetCodeActions())
                                {
                                    nestedActions.Add(new CodeFixSuggestedAction(workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator,
                                        fix, nestedAction, fixCollection.Provider, getFixAllSuggestedActionSet(nestedAction)));
                                }

                                var diag = fix.PrimaryDiagnostic;
                                var set = new SuggestedActionSet(nestedActions, SuggestedActionSetPriority.Medium, diag.Location.SourceSpan.ToSpan());

                                suggestedAction = new SuggestedAction(workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator,
                                    fix.Action, fixCollection.Provider, new[] { set });
                            }
                            else
                            {
                                suggestedAction = new CodeFixSuggestedAction(workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator,
                                    fix, fix.Action, fixCollection.Provider, getFixAllSuggestedActionSet(fix.Action));
                            }

                            AddFix(fix, suggestedAction, map, order);
                        }
                    }

                    if (hasSuppressionFixes)
                    {
                        // Add suppression fixes to the end of a given SuggestedActionSet so that they always show up last in a group.
                        foreach (var fix in fixes)
                        {
                            if (fix.Action is SuppressionCodeAction)
                            {
                                SuggestedAction suggestedAction;
                                if (fix.Action.HasCodeActions)
                                {
                                    suggestedAction = new SuppressionSuggestedAction(workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator,
                                        fix, fixCollection.Provider, getFixAllSuggestedActionSet);
                                }
                                else
                                {
                                    suggestedAction = new CodeFixSuggestedAction(workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator,
                                        fix, fix.Action, fixCollection.Provider, getFixAllSuggestedActionSet(fix.Action));
                                }

                                AddFix(fix, suggestedAction, map, order);
                            }
                        }
                    }
                }
            }
            private static void AddFix(
                CodeFix fix, SuggestedAction suggestedAction,
                IDictionary<CodeFixGroupKey, IList<SuggestedAction>> map,
                ArrayBuilder<CodeFixGroupKey> order)
            {
                var diag = fix.GetPrimaryDiagnosticData();

                var groupKey = new CodeFixGroupKey(diag, fix.Action.Priority);
                if (!map.ContainsKey(groupKey))
                {
                    order.Add(groupKey);
                    map[groupKey] = ImmutableArray.CreateBuilder<SuggestedAction>();
                }

                map[groupKey].Add(suggestedAction);
            }
Ejemplo n.º 13
0
 public ClassificationResults(SuggestedAction act, float matchScore)
 {
     Action = act;
     Similarity = matchScore;
 }