Esempio n. 1
0
        private static List <MarketOrder> ReadFakeDeals(int accountId)//, DateTime startTime)
        {
            var orders   = new List <MarketOrder>();
            var fileName = ExecutablePath.ExecPath + "\\olddeals.xls";

            if (!File.Exists(fileName))
            {
                return(orders);
            }
            using (var sr = new StreamReaderLog(fileName))
            {
                while (!sr.EndOfStream)
                {
                    var line = sr.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    // Buy	EURUSD	1.5408	14.06.2008 00:00	1.5925	11.07.2008 00:00    20000
                    var parts = line.Split(new[] { (char)9 }, StringSplitOptions.None);
                    if (parts.Length != 7)
                    {
                        continue;
                    }
                    var      side       = parts[0] == "Buy" ? 1 : -1;
                    var      symbol     = parts[1];
                    var      priceEnter = parts[2].ToFloatUniform();
                    DateTime timeEnter;
                    try
                    {
                        timeEnter = parts[3].ToDateTimeUniform();
                    }
                    catch
                    {
                        Logger.ErrorFormat("Error parsing time ({0}) from str {1}", parts[3], line);
                        throw;
                    }
                    var priceExit = parts[4].ToFloatUniformSafe();
                    var timeExit  = parts[5].ToDateTimeUniformSafe();
                    var volume    = parts[6].ToInt();

                    orders.Add(new MarketOrder
                    {
                        AccountID  = accountId,
                        PriceEnter = priceEnter,
                        TimeEnter  = timeEnter,
                        PriceExit  = priceExit,
                        TimeExit   = timeExit,
                        Volume     = volume,
                        Side       = side,
                        Symbol     = symbol
                    });
                }
            }
            return(orders);
        }
Esempio n. 2
0
        private List <BalanceChange> ReadFakePart()
        {
            var changes  = new List <BalanceChange>();
            var fileName = ExecutablePath.ExecPath + "\\deposit_inout.xls";

            if (!File.Exists(fileName))
            {
                return(changes);
            }

            using (var sr = new StreamReaderLog(fileName))
            {
                while (!sr.EndOfStream)
                {
                    var line = sr.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    // 14.06.2008 00:00 -200000 1
                    var parts = line.Split(new[] { (char)9 }, StringSplitOptions.None);
                    if (parts.Length != 3)
                    {
                        return(changes);
                    }
                    var date       = parts[0].ToDateTimeUniformSafe();
                    var amount     = parts[1].ToIntSafe();
                    var changeType = parts[2] == "1"
                                         ? BalanceChangeType.Deposit
                                         : BalanceChangeType.Withdrawal;
                    if (!date.HasValue || !amount.HasValue)
                    {
                        continue;
                    }
                    changes.Add(new BalanceChange {
                        ValueDate          = date.Value,
                        Amount             = amount.Value,
                        CurrencyToDepoRate = 1,
                        ChangeType         = changeType
                    });
                }
            }
            return(changes);
        }
Esempio n. 3
0
        public static void GetFirstAndLastFileDates(string fileName,
                                                    out DateTime?dateFirst, out DateTime?dateLast, out bool endsUpNewLine)
        {
            dateFirst     = null;
            dateLast      = null;
            endsUpNewLine = false;
            if (!File.Exists(fileName))
            {
                return;
            }

            using (var sr = new StreamReaderLog(fileName))
            {
                // получить первую строку
                while (!sr.EndOfStream)
                {
                    var line = sr.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    try
                    {
                        if (!dateFirst.HasValue)
                        {
                            dateFirst = DateTime.ParseExact(line, "ddMMyyyy", CultureProvider.Common);
                        }
                        else
                        {
                            var parts = line.Split(' ');
                            var nH    = int.Parse(parts[0].Substring(0, 2));
                            var nM    = int.Parse(parts[0].Substring(2));
                            dateFirst = dateFirst.Value.AddMinutes(nM + nH * 60);
                            break;
                        }
                    }
                    catch
                    {
                        return;
                    }
                }
                if (sr.EndOfStream)
                {
                    return;
                }

                // получить последнюю строку
                var strLast = ReadEndTokens(sr.BaseStream, 1500, Encoding.ASCII, "\n");
                if (!string.IsNullOrEmpty(strLast))
                {
                    if (strLast[strLast.Length - 1] == '\n')
                    {
                        endsUpNewLine = true;
                    }
                }
                var quoteLines = strLast.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                int?lastHour = null, lastMin = null;
                for (var i = quoteLines.Length - 1; i >= 0; i--)
                {
                    var quoteLineParts = quoteLines[i].Split(' ');
                    if (quoteLineParts.Length == 3 && lastHour.HasValue == false)
                    {
                        lastHour = int.Parse(quoteLineParts[0].Substring(0, 2));
                        lastMin  = int.Parse(quoteLineParts[0].Substring(2));
                        continue;
                    }
                    if (quoteLineParts.Length == 1)
                    {
                        dateLast = DateTime.ParseExact(quoteLines[i], "ddMMyyyy", CultureProvider.Common);
                        if (lastHour.HasValue)
                        {
                            dateLast = dateLast.Value.AddMinutes(lastMin.Value + lastHour.Value * 60);
                        }
                        break;
                    }
                }
            }
        }