private void Refresh() { var ids = Invoke(f => f.GetStrategies(_lastCheckTime)).ToArray(); foreach (var tuple in ids.Where(t => t.Item2 < 0)) { var strategy = _strategies.TryGetValue(tuple.Item1); if (strategy != null) { StrategyDeleted?.Invoke(strategy); } } var newIds = new List <long>(); var updatedIds = new List <long>(); foreach (var tuple in ids.Where(t => t.Item2 >= 0)) { var strategy = _strategies.TryGetValue(tuple.Item1); if (strategy != null) { updatedIds.Add(tuple.Item1); } else { newIds.Add(tuple.Item1); } } var newStrategies = Invoke(f => f.GetDescription(newIds.ToArray())); foreach (var newStrategy in newStrategies) { _strategies.Add(newStrategy.Id, newStrategy); StrategyCreated?.Invoke(newStrategy); } var updatedStrategies = Invoke(f => f.GetDescription(updatedIds.ToArray())); foreach (var updatedStrategy in updatedStrategies) { var strategy = _strategies[updatedStrategy.Id]; CopyTo(updatedStrategy, strategy); StrategyUpdated?.Invoke(strategy); } _lastCheckTime = DateTime.Now; }
/// <summary> /// To update the strategy in the store. /// </summary> /// <param name="strategy">The strategy data.</param> public void UpdateStrategy(StrategyData strategy) { ValidateError(Invoke(f => f.UpdateStrategy(SessionId, strategy)), strategy.Id); StrategyUpdated?.Invoke(strategy); }
private void Refresh() { var ids = Invoke(f => f.GetStrategies(_lastCheckTime)).ToArray(); foreach (var tuple in ids.Where(t => t.Item2 < 0)) { var strategy = _strategies.TryGetValue(tuple.Item1); if (strategy != null) { StrategyDeleted?.Invoke(strategy); } } var newIds = new List <long>(); var updatedIds = new List <long>(); foreach (var tuple in ids.Where(t => t.Item2 >= 0)) { var strategy = _strategies.TryGetValue(tuple.Item1); if (strategy != null) { updatedIds.Add(tuple.Item1); } else { newIds.Add(tuple.Item1); } } var newStrategies = Invoke(f => f.GetDescription(newIds.ToArray())); foreach (var newStrategy in newStrategies) { _strategies.Add(newStrategy.Id, newStrategy); StrategyCreated?.Invoke(newStrategy); } var updatedStrategies = Invoke(f => f.GetDescription(updatedIds.ToArray())); foreach (var updatedStrategy in updatedStrategies) { var strategy = _strategies[updatedStrategy.Id]; CopyTo(updatedStrategy, strategy); StrategyUpdated?.Invoke(strategy); } _lastCheckTime = DateTime.Now; foreach (var backtest in _backtests.CachedValues) { if (_backtestResults.ContainsKey(backtest)) { continue; } var resultId = Invoke(f => f.GetBacktestResult(SessionId, backtest.Id)); if (resultId == null) { continue; } _backtestResults.Add(backtest, resultId.Value); BacktestStopped?.Invoke(backtest); _startedBacktests.Remove(backtest); } foreach (var backtest in _startedBacktests.CachedKeys) { var count = Invoke(f => f.GetCompletedIterationCount(SessionId, backtest.Id)); var prevCount = _startedBacktests[backtest]; if (count == prevCount) { continue; } BacktestProgressChanged?.Invoke(backtest, count); if (count == backtest.Iterations.Length) { _startedBacktests.Remove(backtest); } else { _startedBacktests[backtest] = count; } } }