Exemple #1
0
 public static int?GetSettingAsInteger(string type, string code, bool enabledOnly = true)
 {
     try {
         MetaSetting setting = MetadataCaller.Instance().GetSetting(type, code, enabledOnly);
         return(Convert.ToInt32(setting.Value));
     }
     catch { return(null); }
 }
Exemple #2
0
 public static string GetSettingAsString(string type, string code, bool enabledOnly = true)
 {
     try
     {
         MetaSetting setting = MetadataCaller.Instance().GetSetting(type, code, enabledOnly);
         return(setting.Value);
     }
     catch { return(null); }
 }
Exemple #3
0
        public virtual async Task <bool> Initialize(int strategyId)
        {
            try
            {
                AddAlgorithmMessage(string.Format("{0} is starting ...", _shortClassName), true, TraceEventType.Start);

                if (strategyId <= 0)
                {
                    throw new ArgumentException("StrategyId may not be less than or equal to 0.");
                }

                if (_logger == null)
                {
                    _logger = ObjectBase.Container.GetExportedValue <IEventLogger>();
                }

                MetadataCaller.Instance().ClearCache();

                Strategy strategy = StrategyCaller.Instance().GetStrategy(strategyId);
                if (strategy == null)
                {
                    throw new ArgumentException(string.Format("Strategy not found for strategyId {0}.", strategyId));
                }

                _strategy       = strategy;
                _shortClassName = _strategy.Name.Split('.').ToList().Last();

                Parameters = new AlgorithmParameters(await StrategyCaller.Instance().GetAlgorithmParametersAsync(_strategy.StrategyID));

                // create and save instance
                _instance = new AlgorithmInstance()
                {
                    StrategyID = strategyId, Status = (short?)AlgorithmStatus.NotRunning
                };
                await UpdateAlgorithmInstance();

                _messages = new ObservableCollection <AlgorithmMessage>();

                // hook up event handlers
                Messages.CollectionChanged += OnAlgorithmMessageChanged;

                _suspended = () => { return(_instance.Status == (short?)AlgorithmStatus.RunningSuspended); };

                AddAlgorithmMessage(string.Format("{0} is initialized.", _shortClassName), true, TraceEventType.Start);
            }
            catch (Exception e)
            {
                Exception ex = new Exception(string.Format("Algorithm for strategyId: {0} failed to initialize.", strategyId), e);
                AddAlgorithmException(ex).Wait();
                return(false);
            }

            return(true);
        }