public ActionResult BeginTest(TesterModel model) //!!!В модели использовать Instance { if (ModelState.IsValid) { InstanceModel instance = instanceService.GetById(model.InstanceId, true); //получаем стратегию IStrategy strategy = StrategyHelper.CreateStrategy(instance); //устанавливаем остальные свойства Instrument instr = new Instrument(instance.Ticker, instance.TimeFrame); Portfolio portf = new Portfolio { Balance = instance.Balance, Rent = instance.Rent, Slippage = instance.Slippage }; IManager manager = new TesterManager(strategy, instr, portf); manager.DateFrom = model.DateFrom; manager.DateTo = model.DateTo; //Стартуем стратегию manager.StartStrategy(); //***Положить в сессию AliveResult aliveResult = new AliveResult { AliveId = strategyResultCollection.Count() + 1, StartDate = DateTime.Now, Instance = instance, Strategy = strategy, Manager = manager }; //Извлечь индикаторы из объекта стратегии aliveResult.IndicatorsDict = StrategyHelper.ExtractIndicatorsInStrategy(strategy); strategyResultCollection.Add(aliveResult); //** TempData["message"] = string.Format("Тест успешно запущен. Id={0}",aliveResult.AliveId); return RedirectToAction("Index"); } ViewBag.InstanceList = ModelHelper.GetInstanceList(instanceService); return View(model); }
public ViewResult BeginTest() { ViewBag.InstanceList = ModelHelper.GetInstanceList(instanceService); DateTime dateFrom = DateTime.Now.Date.AddMonths(-1); DateTime dateTo = DateTime.Now.Date; TesterModel model = new TesterModel(); model.DateFrom = dateFrom; model.DateTo = dateTo; return View(model); }
public void BeginTest_HttpPost() { SessionHelper.session = new SessionStateMock(); StrategyInfo strategyInfo = new StrategyInfo { Id = 1, Name = "Mock", TypeName = "RMarket.Examples.Strategies.StrategyMock, RMarket.Examples" }; Ticker ticker = new Ticker { Id = 1, Code = "SBER" }; TimeFrame timeFrame = new TimeFrame { Id = 11, Name = "1 day" }; Instance instance = new Instance { Id = 1, GroupID = new Guid("a76dc9b4-8816-438e-aed3-c123374c2e3e"), StrParams = "[{\"FieldName\":\"withSleep\",\"FieldValue\":true}]", StrategyInfoId = strategyInfo.Id, StrategyInfo = strategyInfo, TickerId=ticker.Id, Ticker = ticker, TimeFrameId=timeFrame.Id, TimeFrame=timeFrame }; Mock<IInstanceRepository> instanceRepoMock = new Mock<IInstanceRepository>(); instanceRepoMock.Setup(m => m.Instances).Returns(new List<Instance> { instance }.AsQueryable()); instanceRepoMock.Setup(m => m.Find(1)).Returns(instance); Mock<ICandleRepository> candleRepoMock = new Mock<ICandleRepository>(); candleRepoMock.Setup(m => m.Candles).Returns(new List<Candle> { new Candle(ticker.Id,timeFrame.Id,new DateTime(2015,1,1),10m,15m,8m,11m,0), new Candle(ticker.Id,timeFrame.Id,new DateTime(2015,1,2),11m,15m,8m,11m,0), new Candle(ticker.Id,timeFrame.Id,new DateTime(2015,1,3),11m,16m,10m,15m,0), }.AsQueryable()); TesterModel model = new TesterModel { InstanceId = 1, DateFrom=new DateTime(2015,1,1), DateTo=new DateTime(2015,2,1) }; TesterController controller = CreateTestManagerController(instanceRepoMock.Object, candleRepoMock.Object); //Действие ActionResult result = controller.BeginTest(model); // Утверждение //1. В сесии есть объект результата List<TestResult> testResultCollection = (List<TestResult>)SessionHelper.session["TestResultCollection"]; Assert.AreNotEqual(null, testResultCollection); //2. Проверка реквизитов сформированной стратегии IStrategy strategy = testResultCollection.FirstOrDefault(t => t.Id == 1).Strategy; Assert.AreEqual(ticker, strategy.Instr.Ticker); Assert.AreEqual(timeFrame, strategy.Instr.TimeFrame); //3. Стратегия стартована Assert.AreEqual(true, strategy.Manager.IsStarted); }
public ActionResult BeginTest(TesterModel model) //!!!В модели использовать Instance { if (ModelState.IsValid) { InstanceModel instance = instanceService.GetById(model.InstanceId, true); DataProviderModel setting = settingService.GetById(model.SettingId); //добавляем живую стратегию AliveStrategy aliveStrategy = new AliveStrategy { GroupID = instance.GroupID, IsActive = true }; aliveStrategyRepository.Save(aliveStrategy); //получаем стратегию IStrategy strategy = StrategyHelper.CreateStrategy(instance); //устанавливаем остальные свойства Instrument instr = new Instrument(instance.Ticker, instance.TimeFrame); Portfolio portf = new Portfolio { Balance = instance.Balance, Rent = instance.Rent, Slippage = instance.Slippage }; IDataProvider connector = new SettingHelper().CreateDataProvider(setting); //IDataProvider connector = (IDataProvider)ReflectionHelper.CreateEntity(setting); IManager manager = new EmulManager(orderRepository, strategy, instr, portf, connector, aliveStrategy); //manager.DateFrom = model.DateFrom; //manager.DateTo = model.DateTo; //Стартуем стратегию manager.StartStrategy(); //***Положить в сессию AliveResult aliveResult = new AliveResult { AliveId = aliveStrategy.Id, StartDate = DateTime.Now, Instance = instance, Strategy = strategy, Manager = manager }; //Извлечь индикаторы из объекта стратегии aliveResult.IndicatorsDict = StrategyHelper.ExtractIndicatorsInStrategy(strategy); strategyResultCollection.Add(aliveResult); //** TempData["message"] = string.Format("Эмуляция успешно запущена. Id={0}", aliveResult.AliveId); return RedirectToAction("Index"); } ViewBag.InstanceList = ModelHelper.GetInstanceList(instanceService); return View(model); }