예제 #1
0
        /// <summary>
        /// Общая реализация потоковой обработки для всех типов входных аргументов
        /// </summary>
        private void ExecuteStream(ISecurity sec, string symbolKey, IList <double> indicValues)
        {
            //var sw = Stopwatch.StartNew();
            if ((sec == null) || String.IsNullOrWhiteSpace(symbolKey) ||
                (indicValues == null) || (indicValues.Count <= 0))
            {
                return;
            }

            string tradeName = Context.Runtime.TradeName.Replace(Constants.HtmlDot, ".");

            if (String.IsNullOrWhiteSpace(ValuesName))
            {
                string msg = String.Format("[{0}:{1}] ValuesName is null or empty. Please, provide unique series name. ValuesName: '{2}'",
                                           tradeName, GetType().Name, ValuesName ?? "NULL");
                m_context.Log(msg, MessageType.Warning, true);
                return;
            }

            string cashKey = SaveToGlobalCache.GetGlobalCashKey(tradeName, ValuesName, symbolKey);

            if (String.IsNullOrWhiteSpace(cashKey))
            {
                string msg = String.Format("[{0}:{1}] cashKey is null or empty. cashKey: '{2}'",
                                           tradeName, GetType().Name, cashKey ?? "NULL");
                m_context.Log(msg, MessageType.Warning, true);
                return; // Constants.EmptyListDouble;
            }

            // По факту передаю управление в метод CommonExecute
            var updatedValues = CommonStreamExecute(m_variableId + "_" + cashKey, cashKey,
                                                    sec, RepeatLastValue, true, true, new object[] { indicValues }, SaveToStorage, true, MaxValues);

            //if (basePrices.Count > 0)
            //{
            //    double px = basePrices[basePrices.Count - 1];
            //    double displayValue = FixedValue.ConvertToDisplayUnits(m_valueMode, px);
            //    m_displayPrice.Value = displayValue;
            //}

            //return new ReadOnlyCollection<double>(updatedValues);
            //m_context.Log($"SaveCache time: {sw.Elapsed}", MessageType.Info, true);
        }
예제 #2
0
        /// <summary>
        /// Общая реализация побарной обработки для всех типов входных аргументов
        /// </summary>
        private double ExecuteWithBarNumber(ISecurity sec, string symbolKey, int barNum)
        {
            if ((sec == null) || String.IsNullOrWhiteSpace(symbolKey))
            {
                return(Double.NaN); // В данном случае намеренно возвращаю Double.NaN
            }
            int len = m_context.BarsCount;

            if (len <= 0)
            {
                return(Double.NaN); // В данном случае намеренно возвращаю Double.NaN
            }
            if (len <= barNum)
            {
                string msg = String.Format("[{0}:{1}] (BarsCount <= barNum)! BarsCount:{2}; barNum:{3}",
                                           m_context.Runtime.TradeName, GetType().Name, m_context.BarsCount, barNum);
                m_context.Log(msg, MessageType.Warning, true);
                barNum = len - 1;
            }

            // Здесь используется имя агента-источника-данных из свойства AgentName.
            // Это _НЕ_ имя агента, внутри которого мы сейчас находимся!
            string tradeName = AgentName.Replace(Constants.HtmlDot, ".");

            if (String.IsNullOrWhiteSpace(ValuesName))
            {
                string msg = String.Format("[{0}:{1}] ValuesName is null or empty. Please, provide unique series name. ValuesName: '{2}'",
                                           tradeName, GetType().Name, ValuesName ?? "NULL");
                m_context.Log(msg, MessageType.Warning, true);
                return(Double.NaN); // В данном случае намеренно возвращаю Double.NaN
            }

            string symbol  = String.IsNullOrWhiteSpace(OverrideSymbol) ? symbolKey : OverrideSymbol;
            string cashKey = SaveToGlobalCache.GetGlobalCashKey(tradeName, ValuesName, symbol);

            if (String.IsNullOrWhiteSpace(cashKey))
            {
                string msg = String.Format("[{0}:{1}] cashKey is null or empty. cashKey: '{2}'",
                                           tradeName, GetType().Name, cashKey ?? "NULL");
                m_context.Log(msg, MessageType.Warning, true);
                return(Double.NaN); // В данном случае намеренно возвращаю Double.NaN
            }

            DateTime now = sec.Bars[barNum].Date;
            double   updatedIndicValue = CommonExecute(cashKey, now, RepeatLastValue, true, true, barNum, EmptyArrays.Object);

            //// [2017-06-27] Отключаю вывод отладочных сообщений в лог агента.
            //if (barNum >= 0.9 * len)
            //{
            //    string msg = String.Format("[{0}:{1}] barNum:{2}; updatedIndicValue:{3}; now:{4}",
            //        tradeName, GetType().Name, barNum, updatedIndicValue, now.ToString("dd-MM-yyyy HH:mm:ss.fff"));
            //    m_context.Log(msg, MessageType.Info, false);
            //}

            //// Просто заполнение свойства для отображения на UI
            //int barsCount = ContextBarsCount;
            //if (barNum >= barsCount - 1)
            //{
            //    double displayValue = FixedValue.ConvertToDisplayUnits(m_valueMode, risk);
            //    m_displayRisk.Value = displayValue;
            //}

            return(updatedIndicValue);
        }
예제 #3
0
        /// <summary>
        /// Общая реализация потоковой обработки для всех типов входных аргументов
        /// </summary>
        private IList <double> ExecuteStream(ISecurity sec, string symbolKey)
        {
            if ((sec == null) || String.IsNullOrWhiteSpace(symbolKey))
            {
                return(Constants.EmptyListDouble);
            }

            // Здесь используется имя агента-источника-данных из свойства AgentName.
            // Это _НЕ_ имя агента, внутри которого мы сейчас находимся!
            string tradeName = AgentName.Replace(Constants.HtmlDot, ".");

            if (String.IsNullOrWhiteSpace(ValuesName))
            {
                string msg = String.Format("[{0}:{1}] ValuesName is null or empty. Please, provide unique series name. ValuesName: '{2}'",
                                           tradeName, GetType().Name, ValuesName ?? "NULL");
                m_context.Log(msg, MessageType.Warning, true);
                return(Constants.EmptyListDouble);
            }

            string symbol  = String.IsNullOrWhiteSpace(OverrideSymbol) ? symbolKey : OverrideSymbol;
            string cashKey = SaveToGlobalCache.GetGlobalCashKey(tradeName, ValuesName, symbol);

            if (String.IsNullOrWhiteSpace(cashKey))
            {
                string msg = String.Format("[{0}:{1}] cashKey is null or empty. cashKey: '{2}'",
                                           tradeName, GetType().Name, cashKey ?? "NULL");
                m_context.Log(msg, MessageType.Warning, true);
                return(Constants.EmptyListDouble);
            }

            // Проверяю наличие в Глобальном Кеше объекта с указанным именем
            object testObj  = m_context.LoadGlobalObject(cashKey);
            var    testDict = testObj as Dictionary <DateTime, double>;

            if (testDict == null)
            {
                var container = testObj as NotClearableContainer;
                if ((container != null) && (container.Content != null))
                {
                    testDict = container.Content as Dictionary <DateTime, double>;
                }
            }
            if ((testObj == null) || (testDict == null))
            {
                // Данного ключа в глобальном кеше нет? Тогда выход.
                // [{0}] There is no value in global cache. Probably, you have to start agent '{1}' for security '{2}' to collect values '{3}'.
                string msg = RM.GetStringFormat("OptHandlerMsg.LoadFromGlobalCache.CacheNotFound", GetType().Name, tradeName, symbol, ValuesName);
                if (m_context.Runtime.IsAgentMode)
                {
                    throw new ScriptException(msg); // PROD-4624 - Андрей велит кидать исключение.
                }
                // А если в режиме лаборатории, тогда только жалуемся и продолжаем.
                m_context.Log(msg, MessageType.Warning, true);
                return(Constants.EmptyListDouble);
            }

            // По факту передаю управление в метод CommonExecute
            IList <double> updatedValues = CommonStreamExecute(m_variableId + "_" + cashKey, cashKey,
                                                               sec, RepeatLastValue, true, true, EmptyArrays.Object);

            //if (basePrices.Count > 0)
            //{
            //    double px = basePrices[basePrices.Count - 1];
            //    double displayValue = FixedValue.ConvertToDisplayUnits(m_valueMode, px);
            //    m_displayPrice.Value = displayValue;
            //}

            return(new ReadOnlyCollection <double>(updatedValues));
        }
예제 #4
0
        /// <summary>
        /// Общая реализация побарной обработки для всех типов входных аргументов
        /// </summary>
        private void ExecuteWithBarNumber(ISecurity sec, string symbolKey, double indicValue, int barNum)
        {
            if ((sec == null) || String.IsNullOrWhiteSpace(symbolKey) ||
                Double.IsNaN(indicValue) || Double.IsInfinity(indicValue))
            {
                return;
            }

            int len = m_context.BarsCount;

            if (len <= 0)
            {
                return;
            }

            // В режиме Лаборатории даже не стоит продолжать -- это может сломать ГК
            if (!Context.Runtime.IsAgentMode)
            {
                return;
            }

            if (len <= barNum)
            {
                string msg = String.Format("[{0}:{1}] (BarsCount <= barNum)! BarsCount:{2}; barNum:{3}",
                                           m_context.Runtime.TradeName, GetType().Name, m_context.BarsCount, barNum);
                m_context.Log(msg, MessageType.Warning, true);
                barNum = len - 1;
            }

            string tradeName = Context.Runtime.TradeName.Replace(Constants.HtmlDot, ".");

            if (String.IsNullOrWhiteSpace(ValuesName))
            {
                string msg = String.Format("[{0}:{1}] ValuesName is null or empty. Please, provide unique series name. ValuesName: '{2}'",
                                           tradeName, GetType().Name, ValuesName ?? "NULL");
                m_context.Log(msg, MessageType.Warning, true);
                return;
            }

            string cashKey = SaveToGlobalCache.GetGlobalCashKey(tradeName, ValuesName, symbolKey);

            if (String.IsNullOrWhiteSpace(cashKey))
            {
                string msg = String.Format("[{0}:{1}] cashKey is null or empty. cashKey: '{2}'",
                                           tradeName, GetType().Name, cashKey ?? "NULL");
                m_context.Log(msg, MessageType.Warning, true);
                return;
            }

            DateTime now = sec.Bars[barNum].Date;
            double   updatedIndicValue = CommonExecute(cashKey, now, RepeatLastValue, true, true, barNum, new object[] { indicValue });

            //// [2017-06-28] Отключаю вывод отладочных сообщений в лог агента.
            //if (barNum >= 0.9 * len)
            //{
            //    string msg = String.Format("[{0}:{1}] barNum:{2}; updatedIndicValue:{3}; now:{4}",
            //        tradeName, GetType().Name, barNum, updatedIndicValue, now.ToString("dd-MM-yyyy HH:mm:ss.fff"));
            //    m_context.Log(msg, MessageType.Info, false);
            //}

            //// Просто заполнение свойства для отображения на UI
            //int barsCount = ContextBarsCount;
            //if (barNum >= barsCount - 1)
            //{
            //    double displayValue = FixedValue.ConvertToDisplayUnits(m_valueMode, risk);
            //    m_displayRisk.Value = displayValue;
            //}

            //return updatedIndicValue;
        }