Пример #1
0
 public static void AddFileToPriceList(List <Price> price_list, string file)
 {
     string[,] table = ToolsIOCSV.ReadCSVFile(file);
     for (int index_0 = 0; index_0 < table.GetLength(0); index_0++)
     {
         //TODO duplicate date_times can exist both on the server and on the client
         DateTimeUTC date_time = ToolsTime.UnixTimeStampToDateTimeUTC(int.Parse(table[index_0, 1]));
         double      bid       = double.Parse(table[index_0, 2], CultureInfo.InvariantCulture);
         double      ask       = double.Parse(table[index_0, 3], CultureInfo.InvariantCulture);
         price_list.Add(new Price(date_time, bid, ask));
     }
 }
Пример #2
0
        private PriceSet ImportSecondData(string file_path)
        {
            string        symbol         = Path.GetFileName(file_path).Substring(0, 6);
            TradingSymbol trading_symbol = new TradingSymbol("TradersWay", "MT4.VAR.DEMO", symbol, "The one we mine on the VM");
            List <Price>  price_list     = new List <Price>();

            string[,] table = ToolsIOCSV.ReadCSVFile(file_path);
            for (int index_0 = 0; index_0 < table.GetLength(0); index_0++)
            {
                //TODO duplicate date_times can exist both on the server and on the client
                DateTimeUTC date_time = ToolsTime.UnixTimeStampToDateTimeUTC(int.Parse(table[index_0, 0]));
                double      bid       = double.Parse(table[index_0, 2], CultureInfo.InvariantCulture);
                double      ask       = double.Parse(table[index_0, 3], CultureInfo.InvariantCulture);
                price_list.Add(new Price(date_time, bid, ask));
            }

            return(new PriceSet(trading_symbol, price_list));
        }
Пример #3
0
        private static List <PriceCandle> ReadHST400(BinaryReader reader, long file_size, TimeScale time_scale, double spread)
        {
            // bars array(single-byte justification) . . . total 44 bytes
            long line_count         = (file_size - 148) / 44;
            List <PriceCandle> data = new List <PriceCandle>();

            for (int i = 0; i < line_count; i++)
            {
                reader.ReadBytes(4);
                DateTimeUTC open_date_time = ToolsTime.UnixTimeStampToDateTimeUTC(reader.ReadInt32());
                double      open           = reader.ReadDouble(); // open price	8 bytes
                double      low            = reader.ReadDouble(); // lowest price	8 bytes
                double      high           = reader.ReadDouble(); // highest price	8 bytes
                double      close          = reader.ReadDouble(); // close price	8 bytes
                double      volume         = reader.ReadDouble(); // tick count	8 bytes
                data.Add(new PriceCandle(open_date_time, time_scale, open, high, low, close, volume, spread));
            }
            return(data);
        }
Пример #4
0
        private static List <PriceCandle> ReadHST401(BinaryReader reader, long file_size, TimeScale time_scale)
        {
            //then the bars array(single-byte justification) . . . total 60 bytes
            long line_count         = (file_size - 148) / 60;
            List <PriceCandle> data = new List <PriceCandle>();

            for (int i = 0; i < line_count; i++)
            {
                DateTimeUTC open_date_time = ToolsTime.UnixTimeStampToDateTimeUTC(reader.ReadInt64()); // bar start time	8 bytes
                double      open           = reader.ReadDouble();                                      // open price	8 bytes
                double      high           = reader.ReadDouble();                                      // highest price	8 bytes
                double      low            = reader.ReadDouble();                                      // lowest price	8 bytes
                double      close          = reader.ReadDouble();                                      // close price	8 bytes
                long        volume         = reader.ReadInt64();                                       // tick count	8 bytes
                int         spread         = reader.ReadInt32();;                                      // spread	4 bytes
                long        real_volume    = reader.ReadInt64();                                       // real volume	8 bytes
                data.Add(new PriceCandle(open_date_time, time_scale, open, high, low, close, volume, spread, real_volume));
            }

            return(data);
        }
Пример #5
0
        private static void CreateEventCSV()
        {
            // read CSV
            string[,] source = ToolsIOCSV.ReadCSVFile(ToolsTradingDataSet.GetPath() + "events.csv", Delimiter.SemiColon);

            //Allocate new array
            List <string[]> result_list = new List <string[]>();

            string[] exclusion = new string[] { "day", "Day", "Data" };
            //For each other column
            for (int index_0 = 0; index_0 < source.GetLength(0); index_0++)
            {
                if (!ExtensionsString.ContainsAny(source[index_0, 2], exclusion))
                {
                    string[] result = new string[3]; // Date symbol impact


                    //Find dat
                    DateTime week_start = DateTime.Parse(source[index_0, 0]);
                    int      year       = week_start.Year;
                    int      month      = ToolsForexFactory.MonthToInt(source[index_0, 1].Split(' ')[0]);
                    int      day        = int.Parse(source[index_0, 1].Split(' ')[1]);

                    if ((week_start.Month == 12) && (month == 1))
                    {
                        year++;
                    }

                    int hour   = int.Parse(source[index_0, 2].Split(':')[0]);
                    int minute = int.Parse(source[index_0, 2].Split(':')[1].Substring(0, 2));

                    if (source[index_0, 2].Contains("pm"))
                    {
                        hour = hour + 12;
                    }
                    if (hour == 24)
                    {
                        hour = 0;
                        DateTime date_time = new DateTime(year, month, day, hour, minute, 0);
                        date_time = date_time.AddDays(1);
                        result[0] = ToolsTime.DateTimeToUnixTimestampInt32(date_time).ToString();
                    }
                    else
                    {
                        DateTime date_time = new DateTime(year, month, day, hour, minute, 0);
                        result[0] = ToolsTime.DateTimeToUnixTimestampInt32(date_time).ToString();
                    }

                    result[1] = source[index_0, 3];
                    switch (source[index_0, 4])
                    {
                    case "Non-Economic":
                        result[2] = "0";     // Impacs
                        break;

                    case "Low Impact Expected":
                        result[2] = "1";     // Impacs
                        break;

                    case "Medium Impact Expected":
                        result[2] = "2";     // Impacs
                        break;

                    case "High Impact Expected":
                        result[2] = "3";     // Impacs
                        break;

                    default:
                        throw new Exception("Unknown impact");
                    }
                    result_list.Add(result);
                }
            }
            ToolsIOCSV.WriteCSVFile(ToolsTradingDataSet.GetPath() + "events_small.csv", ToolsCollection.ConvertToArray2D(result_list));
        }