/// <summary> /// Converts instance execution status to SolidColorBrush for indication of status /// </summary> /// <param name="value">StrategyStatus</param> /// <param name="targetType">not used</param> /// <param name="parameter">not used</param> /// <param name="culture">not used</param> /// <returns>System.Windows.Media.SolidColorBrush</returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null && value != DependencyProperty.UnsetValue) { StrategyStatus status = (StrategyStatus)value; // Return certain brush depending on StrategyStatus if (status.Equals(StrategyStatus.Executed)) { return(Application.Current.Resources["BlueBrush"]); } else if (status.Equals(StrategyStatus.Executing)) { return(Application.Current.Resources["GreenBrush"]); } else if (status.Equals(StrategyStatus.Stopped)) { return(Application.Current.Resources["RedBrush"]); } else if (status.Equals(StrategyStatus.Initializing)) { return(Application.Current.Resources["OrangeBrush"]); } else if (status.Equals(StrategyStatus.None)) { return(Application.Current.Resources["GrayBrush"]); } } // Initial state is None, so the color is Gray return(Application.Current.Resources["GrayBrush"]); }
public IStrategy[] Tick() { var tickerResult = ticker.Tick(); Status = tickerResult.Status; return(tickerResult.Strategies); }
private void StopStrategy() { Console.WriteLine(DateTime.Now + " StrategyManager::StopStrategy " + this.strategy.Name); if (!this.framework.IsExternalDataQueue) { foreach (KeyValuePair <IDataProvider, InstrumentList> current in new Dictionary <IDataProvider, InstrumentList>(this.requests)) { if (this.framework.SubscriptionManager != null) { this.framework.SubscriptionManager.Unsubscribe(current.Key, current.Value); } } } if (this.strategy.status == StrategyStatus.Stopped) { Console.WriteLine("StrategyManager::Stop Error: Can not stop stopped strategy ( " + this.strategy.Name + ")"); return; } this.strategy.OnStrategyStop_(); if (this.framework.Mode == FrameworkMode.Simulation) { this.framework.providerManager.dataSimulator.Disconnect(); this.framework.providerManager.executionSimulator.Disconnect(); } if (this.strategy.DataProvider != null) { this.strategy.DataProvider.Disconnect(); } if (this.strategy.ExecutionProvider != null) { this.strategy.ExecutionProvider.Disconnect(); } this.status = StrategyStatus.Stopped; }
/// <summary> /// Converts instance execution status to bool. Used for enabling/disabling of 'Edit' and 'Delete' instance buttons from DataGrid. /// </summary> /// <param name="value">StrategyStatus</param> /// <param name="targetType">not used</param> /// <param name="parameter">not used</param> /// <param name="culture">not used</param> /// <returns>bool</returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null) { // If parameter is Invert, then use inverted logic for button visibility if (parameter != null && ((string)parameter).Equals("Invert")) { StrategyStatus status = (StrategyStatus)value; // Return 'False' only if status is 'None' or 'Initializing' indicating it's not yet executed. if (status.Equals(StrategyStatus.None) || status.Equals(StrategyStatus.Initializing)) { return(false); } else { return(true); } } else if (value != DependencyProperty.UnsetValue) { StrategyStatus status = (StrategyStatus)value; // Return true only if status is Stopped or None if (status.Equals(StrategyStatus.Stopped) || status.Equals(StrategyStatus.None)) { return(true); } } } return(false); }
public void Stop() { if (this.status != StrategyStatus.Stopped) { this.status = StrategyStatus.Stopped; this.StopStrategy(); } this.Clear(); }
internal virtual void OnStrategyStop_() { this.status = StrategyStatus.Stopped; if (this.raiseEvents) { this.OnStrategyStop(); } for (LinkedListNode <Strategy> linkedListNode = this.strategies.First; linkedListNode != null; linkedListNode = linkedListNode.Next) { linkedListNode.Data.OnStrategyStop_(); } }
/// <summary> /// On strategy status changed /// </summary> /// <param name="instanceKey"></param> /// <param name="strategyStatus"></param> private void OnStrategyStatusChanged(string instanceKey, StrategyStatus strategyStatus) { // Create object to indicate status change to be used for Publishing StrategyInstanceStatus strategyInstanceStatus = new StrategyInstanceStatus(); strategyInstanceStatus.StrategyKey = instanceKey.Split('-')[0]; strategyInstanceStatus.InstanceKey = instanceKey; strategyInstanceStatus.StrategyStatus = strategyStatus; // Publish event to notify listeners EventSystem.Publish <StrategyInstanceStatus>(strategyInstanceStatus); }
/// <summary> /// Called when there is a change in strategy status /// </summary> /// <param name="key">Unique Key to identify the Strategy</param> /// <param name="status">indicates whether the strategy is running or stopped</param> private void OnStrategyExecutorStatusChanged(string key, StrategyStatus status) { try { if (_asyncClassLogger.IsInfoEnabled) { _asyncClassLogger.Info("Strategy: " + key + " is running: " + status, _type.FullName, "OnStrategyExecutorStatusChanged"); } // Get Statistics if the strategy is completed if (status == StrategyStatus.Executed) { StrategyExecutor strategyExecutor; if (_strategiesCollection.TryRemove(key, out strategyExecutor)) { StringBuilder parametersInfo = new StringBuilder(); foreach (object ctorArgument in strategyExecutor.CtorArguments) { parametersInfo.Append(ctorArgument.ToString()); parametersInfo.Append(" | "); } // Unhook Event strategyExecutor.StatusChanged -= OnStrategyExecutorStatusChanged; // Stop Strategy strategyExecutor.StopStrategy(); //// Close all connections //strategyExecutor.Close(); // Dispose strategyExecutor.Dispose(); // Update Iterations information _optimizationParameters.CompletedIterations += 1; _optimizationParameters.RemainingIterations = _optimizationParameters.TotalIterations - _optimizationParameters.CompletedIterations; // Execute next iteration StartStrategyExecution(); } } } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "OnStrategyExecutorStatusChanged"); } }
internal virtual void OnStrategyStart_() { this.status = StrategyStatus.Running; foreach (Instrument current in this.instruments) { this.RegisterInstrument(current); } if (this.raiseEvents) { this.OnStrategyStart(); } for (LinkedListNode <Strategy> linkedListNode = this.strategies.First; linkedListNode != null; linkedListNode = linkedListNode.Next) { this.RegisterStrategy(linkedListNode.Data, linkedListNode.Data.instruments, (int)linkedListNode.Data.id); linkedListNode.Data.OnStrategyStart_(); } }
public bool bAskPriceChanged;//用于通知ShortSell重新挂单 //public long TotalVolume; //public long Volume; //public long BuyVolume; //主动买量 //public long SellVolume; //主动卖量 //为未来加入lvl2数据留空间 public SingleStockData(string _ticker) { BidPrices = new double[10]; AskPrices = new double[10]; BidVol = new uint[10]; AskVol = new uint[10]; StatusCBFishing = StrategyStatus.None; StatusStockFishing = StrategyStatus.None; StatusTrending = StrategyStatus.None; bAskPriceChanged = false; zbDataList = new List <ZBTickData>(); ZBFirstIndex = -1; ZBLastIndex = -1; }
/// <summary> /// Converts instance execution status to visibility of buttons Start and Stop /// </summary> /// <param name="value">StrategyStatus</param> /// <param name="targetType">not used</param> /// <param name="parameter">String as inversion indicator</param> /// <param name="culture">not used</param> /// <returns>System.Windows.Visibility</returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null) { StrategyStatus status = (StrategyStatus)value; // If parameter is Invert, then use inverted logic for button visibility if (parameter != null && ((string)parameter).Equals("Invert")) { // If inverted logic and if strategy status is Executing or Executed, Start button is visible, Stop button is collapsed if (status.Equals(StrategyStatus.Executing) || status.Equals(StrategyStatus.Executed)) { return(System.Windows.Visibility.Visible); } else if (status.Equals(StrategyStatus.None) || status.Equals(StrategyStatus.Stopped)) { return(System.Windows.Visibility.Collapsed); } else if (status.Equals(StrategyStatus.Initializing)) { return(System.Windows.Visibility.Visible); } } else { // If not inverted logic and if strategy status is Executing or Executed, Start button is collapsed, Stop button is visible if (status.Equals(StrategyStatus.Executing) || status.Equals(StrategyStatus.Executed)) { return(System.Windows.Visibility.Collapsed); } else if (status.Equals(StrategyStatus.None) || status.Equals(StrategyStatus.Stopped)) { return(System.Windows.Visibility.Visible); } } } // Default visibility for Start button is visible return(System.Windows.Visibility.Visible); }
public Strategy(Framework framework, string name) { this.framework = framework; this.Name = name; this.strategiesByInstrument = new IdArray<LinkedList<Strategy>>(1000); this.strategyByOrderId = new IdArray<Strategy>(1000); this.strategies = new LinkedList<Strategy>(); this.status = StrategyStatus.Stopped; this.instruments = new InstrumentList(); this.instrumentCountTable = new IdArray<int>(1000); if (framework != null) { this.portfolio = new Portfolio(framework, this.Name); framework.PortfolioManager.Add(this.portfolio); } this.bars = new BarSeries("", ""); this.equity = new TimeSeries(); this.bids = new TickSeries(""); this.asks = new TickSeries(""); this.stops = new List<Stop>(); this.stopsByInstrument = new IdArray<List<Stop>>(1000); }
public Strategy(Framework framework, string name) { this.framework = framework; this.Name = name; this.strategiesByInstrument = new IdArray <LinkedList <Strategy> >(1000); this.strategyByOrderId = new IdArray <Strategy>(1000); this.strategies = new LinkedList <Strategy>(); this.status = StrategyStatus.Stopped; this.instruments = new InstrumentList(); this.instrumentCountTable = new IdArray <int>(1000); if (framework != null) { this.portfolio = new Portfolio(framework, this.Name); framework.PortfolioManager.Add(this.portfolio); } this.bars = new BarSeries("", ""); this.equity = new TimeSeries(); this.bids = new TickSeries(""); this.asks = new TickSeries(""); this.stops = new List <Stop>(); this.stopsByInstrument = new IdArray <List <Stop> >(1000); }
internal virtual void OnStrategyStop_() { this.status = StrategyStatus.Stopped; if (this.raiseEvents) { this.OnStrategyStop(); } for (LinkedListNode<Strategy> linkedListNode = this.strategies.First; linkedListNode != null; linkedListNode = linkedListNode.Next) { linkedListNode.Data.OnStrategyStop_(); } }
public void StartStrategy(Strategy strategy, StrategyMode mode) { this.strategy = strategy; if (mode == StrategyMode.Backtest) { this.framework.Mode = FrameworkMode.Simulation; } else { this.framework.Mode = FrameworkMode.Realtime; } if (this.framework.eventManager.status != EventManagerStatus.Running) { this.framework.eventManager.Start(); } StrategyStatusInfo strategyStatusInfo = new StrategyStatusInfo(this.framework.clock.DateTime, StrategyStatusType.Started); strategyStatusInfo.Solution = ((strategy.Name == null) ? "Solution" : strategy.Name); strategyStatusInfo.Mode = mode.ToString(); this.framework.eventServer.OnLog(new GroupEvent(strategyStatusInfo, null)); strategy.OnStrategyStart_(); if (!this.framework.IsExternalDataQueue) { Dictionary <IDataProvider, InstrumentList> dictionary = new Dictionary <IDataProvider, InstrumentList>(); while (this.requests.Count != 0) { Dictionary <IDataProvider, InstrumentList> dictionary2 = new Dictionary <IDataProvider, InstrumentList>(this.requests); this.requests.Clear(); foreach (KeyValuePair <IDataProvider, InstrumentList> current in new Dictionary <IDataProvider, InstrumentList>(dictionary2)) { InstrumentList instrumentList = null; if (!dictionary.TryGetValue(current.Key, out instrumentList)) { instrumentList = new InstrumentList(); dictionary[current.Key] = instrumentList; } InstrumentList instrumentList2 = new InstrumentList(); foreach (Instrument current2 in current.Value) { if (!instrumentList.Contains(current2)) { instrumentList.Add(current2); instrumentList2.Add(current2); } } if (current.Key is SellSideStrategy && this.framework.SubscriptionManager != null) { this.framework.SubscriptionManager.Subscribe(current.Key, instrumentList2); } } } this.status = StrategyStatus.Running; this.requests = dictionary; if (this.requests.Count == 0) { Console.WriteLine(string.Concat(new object[] { DateTime.Now, " StrategyManager::StartStrategy ", strategy.Name, " has no data requests, stopping..." })); this.StopStrategy(); return; } foreach (KeyValuePair <IDataProvider, InstrumentList> current3 in this.requests) { if (!(current3.Key is SellSideStrategy) && this.framework.SubscriptionManager != null) { this.framework.SubscriptionManager.Subscribe(current3.Key, current3.Value); } } } }
public void StartStrategy(Strategy strategy, StrategyMode mode) { this.strategy = strategy; if (mode == StrategyMode.Backtest) { this.framework.Mode = FrameworkMode.Simulation; } else { this.framework.Mode = FrameworkMode.Realtime; } if (this.framework.eventManager.status != EventManagerStatus.Running) { this.framework.eventManager.Start(); } StrategyStatusInfo strategyStatusInfo = new StrategyStatusInfo(this.framework.clock.DateTime, StrategyStatusType.Started); strategyStatusInfo.Solution = ((strategy.Name == null) ? "Solution" : strategy.Name); strategyStatusInfo.Mode = mode.ToString(); this.framework.eventServer.OnLog(new GroupEvent(strategyStatusInfo, null)); strategy.OnStrategyStart_(); if (!this.framework.IsExternalDataQueue) { Dictionary<IDataProvider, InstrumentList> dictionary = new Dictionary<IDataProvider, InstrumentList>(); while (this.requests.Count != 0) { Dictionary<IDataProvider, InstrumentList> dictionary2 = new Dictionary<IDataProvider, InstrumentList>(this.requests); this.requests.Clear(); foreach (KeyValuePair<IDataProvider, InstrumentList> current in new Dictionary<IDataProvider, InstrumentList>(dictionary2)) { InstrumentList instrumentList = null; if (!dictionary.TryGetValue(current.Key, out instrumentList)) { instrumentList = new InstrumentList(); dictionary[current.Key] = instrumentList; } InstrumentList instrumentList2 = new InstrumentList(); foreach (Instrument current2 in current.Value) { if (!instrumentList.Contains(current2)) { instrumentList.Add(current2); instrumentList2.Add(current2); } } if (current.Key is SellSideStrategy && this.framework.SubscriptionManager != null) { this.framework.SubscriptionManager.Subscribe(current.Key, instrumentList2); } } } this.status = StrategyStatus.Running; this.requests = dictionary; if (this.requests.Count == 0) { Console.WriteLine(string.Concat(new object[] { DateTime.Now, " StrategyManager::StartStrategy ", strategy.Name, " has no data requests, stopping..." })); this.StopStrategy(); return; } foreach (KeyValuePair<IDataProvider, InstrumentList> current3 in this.requests) { if (!(current3.Key is SellSideStrategy) && this.framework.SubscriptionManager != null) { this.framework.SubscriptionManager.Subscribe(current3.Key, current3.Value); } } } }
public void Stop() { if (this.status != StrategyStatus.Stopped) { this.status = StrategyStatus.Stopped; this.StopStrategy(); } this.Clear(); }
public StrategyResult(StrategyStatus status, IStrategy[] strategies) { Status = status; Strategies = strategies; }
/// <summary> /// Argument Constructor /// </summary> /// <param name="instanceKey"></param> /// <param name="strategyStatus"></param> public StrategyStatusRepresentation(string instanceKey, StrategyStatus strategyStatus) { InstanceKey = instanceKey; StrategyStatus = strategyStatus; }
private void StopStrategy() { Console.WriteLine(DateTime.Now + " StrategyManager::StopStrategy " + this.strategy.Name); if (!this.framework.IsExternalDataQueue) { foreach (KeyValuePair<IDataProvider, InstrumentList> current in new Dictionary<IDataProvider, InstrumentList>(this.requests)) { if (this.framework.SubscriptionManager != null) { this.framework.SubscriptionManager.Unsubscribe(current.Key, current.Value); } } } if (this.strategy.status == StrategyStatus.Stopped) { Console.WriteLine("StrategyManager::Stop Error: Can not stop stopped strategy ( " + this.strategy.Name + ")"); return; } this.strategy.OnStrategyStop_(); if (this.framework.Mode == FrameworkMode.Simulation) { this.framework.providerManager.dataSimulator.Disconnect(); this.framework.providerManager.executionSimulator.Disconnect(); } if (this.strategy.DataProvider != null) { this.strategy.DataProvider.Disconnect(); } if (this.strategy.ExecutionProvider != null) { this.strategy.ExecutionProvider.Disconnect(); } this.status = StrategyStatus.Stopped; }
internal virtual void OnStrategyStart_() { this.status = StrategyStatus.Running; foreach (Instrument current in this.instruments) { this.RegisterInstrument(current); } if (this.raiseEvents) { this.OnStrategyStart(); } for (LinkedListNode<Strategy> linkedListNode = this.strategies.First; linkedListNode != null; linkedListNode = linkedListNode.Next) { this.RegisterStrategy(linkedListNode.Data, linkedListNode.Data.instruments, (int)linkedListNode.Data.id); linkedListNode.Data.OnStrategyStart_(); } }