Example #1
0
        private NettoRecord MoveToNettos(DateTime closeTime)
        {
            if (cur == null)
            {
                return(null);
            }
            if (cur.time == closeTime)
            {
                return(cur);
            }
            if (cur.time > closeTime)
            {
                return(null);
            }

            if (next != null)
            {
                if (next.time > closeTime)
                {
                    return(cur);
                }
                if (next.time == closeTime)
                {
                    cur  = next;
                    next = NettoRecord.ReadNext(nettoReader);
                    return(cur);
                }

                while (true)
                {
                    cur  = next;
                    next = NettoRecord.ReadNext(nettoReader);
                    if (next == null)
                    {
                        cur = null;
                        return(null);
                    }
                    if (next.time > closeTime)
                    {
                        return(cur);
                    }
                    if (next.time == closeTime)
                    {
                        cur  = next;
                        next = NettoRecord.ReadNext(nettoReader);
                        return(cur);
                    }
                }
            }

            return(null);
        }
Example #2
0
            public static NettoRecord ReadNext(StreamReader sr)
            {
                if (symbols == null || symbols.Length == 0)
                {
                    return(null);
                }

                while (!sr.EndOfStream)
                {
                    var line = sr.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    // 10.05.2016 22:00 275000 -82000
                    var parts = line.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length < symbols.Length + 2)
                    {
                        continue;
                    }

                    DateTime time;
                    if (!DateTime.TryParseExact(parts[0] + " " + parts[1], "dd.MM.yyyy HH:mm",
                                                CultureInfo.InvariantCulture, DateTimeStyles.None, out time))
                    {
                        continue;
                    }

                    var record = new NettoRecord
                    {
                        time = time
                    };

                    for (var i = 0; i < symbols.Length; i++)
                    {
                        var numStr = parts[i + 2];
                        var num    = numStr.ToDoubleUniformSafe() ?? 0;
                        record.nettoBySymbol.Add(symbols[i], num);
                    }

                    return(record);
                }

                return(null);
            }
Example #3
0
        public override void Initialize(BacktestServerProxy.RobotContext grobotContext,
                                        Contract.Util.BL.CurrentProtectedContext protectedContextx)
        {
            base.Initialize(grobotContext, protectedContextx);
            if (Graphics.Count == 0)
            {
                Logger.DebugFormat("CounterNettoRobot: настройки графиков не заданы");
                return;
            }

            packers = Graphics.ToDictionary(g => g.a, g => new CandlePacker(g.b));

            if (!File.Exists(NettoFilePath))
            {
                Logger.DebugFormat("CounterNettoRobot: файл не найден");
                return;
            }
            nettoReader = new StreamReader(NettoFilePath, Encoding.ASCII);
            NettoRecord.ReadHeader(nettoReader);
            cur  = NettoRecord.ReadNext(nettoReader);
            next = NettoRecord.ReadNext(nettoReader);
        }