Exemplo n.º 1
0
        public BackTesting(char verify, Models.Strategics game, string key) : base(key)
        {
            if (game.Strategy.Length == 2)
            {
                Charts = new Queue <Models.Charts>(128);
            }

            this.verify  = verify.Equals((char)86);
            this.game    = game;
            Residue      = new Dictionary <uint, int>();
            SellOrder    = new Dictionary <string, uint>();
            BuyOrder     = new Dictionary <string, uint>();
            Judge        = new Dictionary <uint, double>();
            TradingJudge = new Dictionary <uint, double>();
            games        = new Queue <Models.Strategics>();
            Parallel.ForEach(Retrieve.GetCatalog(game), new Action <Catalog.XingAPI.Specify>((param) =>
            {
                if (param.Time > 0)
                {
                    if (param.Strategy.Length > 2)
                    {
                        switch (param.Strategy)
                        {
                        case basic:
                            new Base(this, param);
                            break;

                        case bantam:
                            new Bantam(this, param);
                            break;

                        case feather:
                            new Feather(this, param);
                            break;

                        case fly:
                            new Fly(this, param);
                            break;

                        case sFly:
                            new SuperFly(this, param);
                            break;

                        case heavy:
                            new Heavy(this, param);
                            break;
                        }
                    }
                    else
                    {
                        new Consecutive(this, param);
                    }
                }
            }));
            if (this.verify)
            {
                statement = new Queue <Conclusion>(32);
                new Task(() => new ExceptionMessage(game)).Start();
            }
            if (StartProgress(game.Strategy.Length) > 0)
            {
                using (var sw = new StreamWriter(new Secret().GetPath(game.Strategy, statement.Count), true))
                    try
                    {
                        while (statement.Count > 0)
                        {
                            var sb  = new StringBuilder();
                            var str = statement.Dequeue();

                            if (str.Time.Contains(';'))
                            {
                                var split = str.Time.Split(';');
                                sb.Append(split[0]).Append(',').Append(split[1]).Append(',').Append(str.Division).Append(',').Append(str.Price).Append(',').Append(str.OrderNumber);
                            }
                            else
                            {
                                sb.Append(str.Time).Append(',').Append(str.Division).Append(',').Append(str.Price).Append(',').Append(str.OrderNumber);
                            }

                            sw.WriteLine(sb);
                        }
                    }
                    catch (Exception ex)
                    {
                        new ExceptionMessage(ex.StackTrace);
                    }
            }
        }