private void RunTest(TradeParams tradeParams, Configurator configurator, TradesPrinter printer)
        {
            tradeParams.Validate();

            var advisor = new TradeAdvisor(configurator.Repository.Days.First().FiveMins);
            var robot = new RobotContext(tradeParams, configurator.Factory, advisor);
            var results = configurator.GetTradeResults();

            //foreach (var day in repository.Days)
            foreach (var day in configurator.Repository.Days.Skip(1))    //TODO перебирать параметры по абсолютному значению, а затем искать регрессию одних на другие
            {
                foreach (var candle in day.FiveMins)
                {
                    var dealEvent = robot.Process(candle) as DealEvent;
                    if (dealEvent != null)
                    {
                        results.AddDeal(dealEvent.Deal);
                    }
                }
                var ev = robot.StopTrading() as DealEvent;
                if (ev != null)
                {
                    results.AddDeal(ev.Deal);
                }
                //printer.PrintDepoWithParamsName(tradeParams, results);

                Assert.That(results.DealsAreClosed);
                robot.Reset();
            }

            //File.WriteAllLines("out.txt", results.GetDepositSizes().Select(s => (s - 30000).ToString()));
            printer.AddRow(tradeParams, results);
        }
 public IState GetTradeState(RobotContext context, Deal deal)
 {
     switch (TradeStateType)
     {
         case TradeStateTypes.Basic:
             return new BasicTradeState(context, deal);
         case TradeStateTypes.Breakeven:
             return new BreakevenTradeState(context, deal);
         case TradeStateTypes.Trailing:
             return new TrailingTradeState(context, deal);
         default:
             throw new ArgumentException("Not expected trade state type");
     }
 }
        public Configurator(string configsName, MainWindow window)
        {
            var document = XDocument.Load(configsName);

            var eventBus = new EventBus();

            InitLogs(window);
            InitConnector(document.Descendants("Connection").Single());

            var factory = GetFactory(document.Descendants("Types").Single());
            var tradeParams = GetParams(document.Descendants("TradeParams").Single());

            var currentDayCandles = Connector.GetCurrentDayCandles();
            var advisor = new TradeAdvisor(currentDayCandles);	//TODO больше истории

            RobotContext = new RobotContext(tradeParams, factory, advisor, currentDayCandles);
            InitTradeController(document.Descendants("TradeController").Single(), eventBus,
                LogManager.Configuration.Variables["WorkingDirectory"]);
        }
 public IState GetSearchState(RobotContext context)
 {
     return new SearchState(context);
 }
 public IState GetEndState(RobotContext context)
 {
     return new EndState(context);
 }