예제 #1
0
        private void ConnectorOnScriptingListReceived(object sender, EventArgs <ScriptingReceivedEventArgs> args)
        {
            lock (Indicators)
            {
                Indicators.Clear();

                foreach (var item in args.Value.Indicators.ToList())
                {
                    Indicators.Add(item.Key, item.Value);
                }

                DefaultIndicators.Clear();
                DefaultIndicators.AddRange(args.Value.DefaultIndicators.ToList());
            }

            lock (Signals)
            {
                Signals.Clear();
                foreach (var item in args.Value.Signals)
                {
                    Signals.Add(item);
                }
            }

            ScriptingListUpdated?.Invoke();
        }
예제 #2
0
        public string SendIndicatorToServer(string solutionPath)
        {
            var indicatorName = Path.GetFileNameWithoutExtension(solutionPath);
            var DLLs          = GetCompressedScriptingDlls(Path.GetDirectoryName(solutionPath));

            if (!DLLs.ContainsKey(indicatorName + ".dll"))
            {
                return($"Failed to locate or compress {indicatorName} libraries");
            }

            if (Indicators.ContainsKey(indicatorName))
            {
                Indicators.Remove(indicatorName);
                ScriptingListUpdated?.Invoke();
                IndicatorInstanceRemoved?.Invoke(this, new EventArgs <string>(indicatorName));
            }

            _connector.Send(new SaveScriptingDataRequest
            {
                Files         = DLLs,
                Path          = indicatorName,
                RequestID     = Guid.NewGuid().ToString(),
                ScriptingType = ScriptingType.Indicator
            });

            return(String.Empty);
        }
예제 #3
0
        public void RemoveSignalFromServer(string fullName)  //removes Signal solution and data from server
        {
            Signals.Remove(Signals.FirstOrDefault(i => i.FullName == fullName));
            _connector.Send(new RemoveScriptingInstanceRequest
            {
                Name          = fullName,
                ScriptingType = ScriptingType.Signal,
                RemoveProject = true
            });

            SignalInstanceRemoved?.Invoke(this, new EventArgs <string>(fullName));
            ScriptingListUpdated?.Invoke();
        }
예제 #4
0
        public void RemoveIndicatorFromServer(string name)
        {
            Indicators.Remove(name);
            _connector.Send(new RemoveScriptingInstanceRequest
            {
                Name          = name,
                ScriptingType = ScriptingType.Indicator,
                RemoveProject = true
            });

            ScriptingListUpdated?.Invoke();
            IndicatorInstanceRemoved?.Invoke(this, new EventArgs <string>(name));
        }
예제 #5
0
        private void ConnectorOnScriptingSaved(object sender, EventArgs <ScriptingSavedEventArgs> eventArgs)
        {
            if (eventArgs.Value.ScriptingType == Data.Contracts.ScriptingType.Indicator)
            {
                lock (Indicators)
                {
                    if (Indicators.ContainsKey(eventArgs.Value.Name))
                    {
                        Indicators.Remove(eventArgs.Value.Name);
                    }

                    Indicators.Add(eventArgs.Value.Name, eventArgs.Value.Parameters);
                }
            }
            else if (eventArgs.Value.ScriptingType == Data.Contracts.ScriptingType.Signal)
            {
                lock (Signals)
                {
                    var signal = Signals.FirstOrDefault(i => i.FullName == eventArgs.Value.Name);
                    if (signal != null)
                    {
                        signal.Parameters = new List <ScriptingParameterBase>(eventArgs.Value.Parameters);
                    }
                    else
                    {
                        signal = new Signal
                        {
                            FullName   = eventArgs.Value.Name,
                            Parameters = new List <ScriptingParameterBase>(eventArgs.Value.Parameters)
                        };
                    }

                    if (signal.State == State.New)
                    {
                        signal.State = State.Stopped;
                        signal.SetDefaultParamSpace();
                    }

                    if (Signals.All(i => i.FullName != signal.FullName))
                    {
                        Signals.Add(signal);
                    }
                }
            }

            ScriptingListUpdated?.Invoke();
        }
예제 #6
0
        public string SendSignalToServer(string solutionPath, string settingsPath)  //saves Signal on server (does not start)
        {
            //if (!Directory.Exists(solutionPath))
            //    return "Solution directory does not exist";

            string signalRelativePath;
            var    levels = settingsPath.Split(Path.DirectorySeparatorChar);

            if (levels.Length > 3)
            {
                signalRelativePath = String.Join("\\", levels.Skip(levels.Length - 3));  //portfolio/strategy/signal
            }
            else
            {
                return("Invalid signal settings path");
            }

            CopySignalDllsToSettingsDir(solutionPath, settingsPath);
            var files = GetCompressedSignalDataFiles(settingsPath);

            var name = signalRelativePath.Substring(signalRelativePath.LastIndexOf('\\') + 1);

            if (!files.Any(i => i.Key.EndsWith(name + ".dll")))
            {
                return("Signal DLL does not exist");
            }

            if (!String.IsNullOrEmpty(signalRelativePath) && Signals.Any(i => i.FullName == signalRelativePath))
            {
                Signals.Remove(Signals.First(i => i.FullName == signalRelativePath));
                SignalInstanceRemoved?.Invoke(this, new EventArgs <string>(signalRelativePath));
                ScriptingListUpdated?.Invoke();
            }

            _connector.Send(new SaveScriptingDataRequest
            {
                Files         = files,
                Path          = signalRelativePath,
                RequestID     = Guid.NewGuid().ToString(),
                ScriptingType = ScriptingType.Signal
            });

            return(null);
        }