예제 #1
0
        public EmulManager(IOrderRepository orderRepository,
            IStrategy strategy, Instrument instr, Portfolio portf, IDataProvider connector, AliveStrategy aliveStrategy)
        {
            this.orderRepository = orderRepository;

            this.Strategy = strategy;
            this.Instr = instr;
            this.Portf = portf;
            this.Connector = connector;
            this.AliveType = AliveType.Emul;
            this.OrderSender = new OrderSender(this);

            Strategy.Instr = Instr;
            Strategy.Manager = this;

            Strategy.Initialize();
            StrategyHelper.SubscriptionToEventAsync(Strategy); //Подписываем на событие формирования свечи асинхронно индикаторы, которые найдем в стратегии.

            this.aliveStrategy = aliveStrategy;

            //!!!проверить на наличие подписки
            Connector.TickPoked += Instr.OnTickPoked;
        }
예제 #2
0
        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);
        }