示例#1
0
 /// <summary>
 /// Enters Bar Into File
 /// </summary>
 private void WriteBarDataToCsvFile(DetailBar newBar)
 {
     try
     {
         using (StreamWriter sw = File.AppendText(CreateDirectoryPathForBarObject(newBar.Security.Symbol, newBar, newBar.MarketDataProvider) + "\\" + newBar.DateTime.ToString("yyyyMMdd") + ".txt"))
         {
             var bar = (Bar)newBar;
             sw.Write(bar.Close);
             sw.Write(",");
             sw.Write(bar.Open);
             sw.Write(",");
             sw.Write(bar.High);
             sw.Write(",");
             sw.Write(bar.Low);
             sw.Write(",");
             sw.Write(bar.Volume);
             sw.Write(",");
             sw.Write(bar.Security.Symbol);
             sw.Write(",");
             sw.Write(bar.DateTime);
             sw.Write(",");
             sw.Write(bar.MarketDataProvider);
             sw.Write(Environment.NewLine);
         }
     }
     catch (Exception exception)
     {
         Logger.Error(exception, _oType.FullName, "WriteBarDataToFile");
     }
 }
 /// <summary>
 /// Initializes the metadata key/value pairs.
 /// </summary>
 protected virtual void InitializeMetadata()
 {
     // This will create elements for all the metadata key/value pairs that is displayed in the DetailsBar.
     this.metadataField.Add(DetailBar.CreateMetadataElement("Date modified:", this, DetailBar.CreateDateTimeMetadataValue("ModifiedTime")));
     this.metadataField.Add(DetailBar.CreateMetadataElement("Date Created:", this, DetailBar.CreateDateTimeMetadataValue("CreatedTime")));
     this.metadataField.Add(DetailBar.CreateMetadataElement("Filled Orders:", this, DetailBar.CreateInt32MetadataValue("FilledOrderCount")));
     this.metadataField.Add(DetailBar.CreateMetadataElement("New Orders:", this, DetailBar.CreateInt32MetadataValue("NewOrderCount")));
     this.metadataField.Add(DetailBar.CreateMetadataElement("Partial Orders:", this, DetailBar.CreateInt32MetadataValue("PartialOrderCount")));
     this.metadataField.Add(DetailBar.CreateMetadataElement("Total Working Orders:", this, DetailBar.CreateInt32MetadataValue("WorkingOrderCount")));
     this.metadataField.Add(DetailBar.CreateMetadataElement("Ordered:", this, DetailBar.CreateProgressMetadataValue("OrderedPercent", 0.0, 1.0)));
     this.metadataField.Add(DetailBar.CreateMetadataElement("Executed:", this, DetailBar.CreateProgressMetadataValue("ExecutedPercent", 0.0, 1.0)));
 }
示例#3
0
 /// <summary>
 /// Writes given data into required files
 /// </summary>
 /// <param name="data">Data to be writen in file</param>
 /// <param name="symbol">Symbol</param>
 /// <param name="newBar">Contains Bar info</param>
 /// <param name="provider">name of market data provider to be used</param>
 public static void WriteData(string data, string symbol, DetailBar newBar, string provider = "Blackwood")
 {
     try
     {
         using (StreamWriter sw = File.AppendText(CreateDirectoryPathForBarObject(symbol, newBar, provider) + "\\" + newBar.DateTime.ToString("yyyyMMdd") + ".txt"))
         {
             sw.Write(data);
             sw.Write(Environment.NewLine);
         }
     }
     catch (Exception exception)
     {
         Logger.Error(exception, _type.FullName, "WriteData");
     }
 }
 /// <summary>
 /// Takes an bar Object and maps it onto DetailBar Object
 /// </summary>
 /// <param name="bar"></param>
 /// <returns></returns>
 public DetailBar ChangeBarToDetailBar(Bar bar)
 {
     try
     {
         DetailBar detailBar = new DetailBar(bar);
         var       request   = BarDataRequests.Single(x => x.Id == detailBar.RequestId);
         detailBar.PipSize      = request.PipSize;
         detailBar.BarFormat    = request.BarFormat;
         detailBar.BarLength    = request.BarLength;
         detailBar.BarPriceType = request.BarPriceType;
         return(detailBar);
     }
     catch (Exception exception)
     {
         Logger.Error(exception, _oType.FullName, "ChangeBarToDetailBar");
         return(null);
     }
 }
示例#5
0
        /// <summary>
        /// Creates Missing Directories and place returns proper
        /// path of file depending on dataType and symbol
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="detailBar"> </param>
        /// <param name="dataProvider"> </param>
        /// <returns></returns>
        private static string CreateDirectoryPathForBarObject(string symbol, DetailBar detailBar, string dataProvider)
        {
            try
            {
                // The folder for the roaming current user
                string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

                // Combine the base folder with your specific folder....
                string specificFolder = Path.Combine(folder, "DataDownloader");

                string[] directories =
                {
                    specificFolder + "\\" + dataProvider,
                    specificFolder + "\\" + dataProvider + "\\" + symbol,
                    specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR",
                    specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR" + "\\" + detailBar.BarFormat,
                    specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR" + "\\" + detailBar.BarFormat + "\\" + detailBar.BarPriceType,
                    specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR" + "\\" + detailBar.BarFormat + "\\" + detailBar.BarPriceType + "\\" + detailBar.BarLength,
                    specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR" + "\\" + detailBar.BarFormat + "\\" + detailBar.BarPriceType + "\\" + detailBar.BarLength + "\\" + DateTime.Now.Year.ToString(CultureInfo.InvariantCulture),
                    specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR" + "\\" + detailBar.BarFormat + "\\" + detailBar.BarPriceType + "\\" + detailBar.BarLength + "\\" + DateTime.Now.Year.ToString(CultureInfo.InvariantCulture) + "\\" + DateTime.Now.Month.ToString(CultureInfo.InvariantCulture)
                };

                foreach (string path in directories)
                {
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                }
                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug(directories[directories.Length - 1] + "\\" + DateTime.Now.ToString("yyyyMMdd"), _type.FullName,
                                 "CreateDirectoryPath");
                }
                return(directories[directories.Length - 1]);
            }
            catch (Exception exception)
            {
                Logger.Error(exception, _type.FullName, "CreateDirectoryPath");
                return(null);
            }
        }
示例#6
0
        /// <summary>
        /// Creates Missing Directories and place returns proper
        /// path of file depending on dataType and symbol
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="detailBar"> </param>
        /// <param name="dataProvider"> </param>
        /// <returns></returns>
        private string CreateDirectoryPathForBarObject(string symbol, DetailBar detailBar, string dataProvider)
        {
            try
            {
                string[] directories =
                {
                    _specificFolder + "\\" + dataProvider,
                    _specificFolder + "\\" + dataProvider + "\\" + symbol,
                    _specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR",
                    _specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR" + "\\" + detailBar.BarFormat,
                    _specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR" + "\\" + detailBar.BarFormat + "\\" + detailBar.BarPriceType,
                    _specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR" + "\\" + detailBar.BarFormat + "\\" + detailBar.BarPriceType + "\\" + detailBar.BarLength,
                    _specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR" + "\\" + detailBar.BarFormat + "\\" + detailBar.BarPriceType + "\\" + detailBar.BarLength + "\\" + DateTime.Now.Year.ToString(CultureInfo.InvariantCulture),
                    _specificFolder + "\\" + dataProvider + "\\" + symbol + "\\BAR" + "\\" + detailBar.BarFormat + "\\" + detailBar.BarPriceType + "\\" + detailBar.BarLength + "\\" + DateTime.Now.Year.ToString(CultureInfo.InvariantCulture) + "\\" + DateTime.Now.Month.ToString(CultureInfo.InvariantCulture)
                };

                foreach (string path in directories)
                {
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                }
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info(directories[directories.Length - 1] + "\\" + DateTime.Now.ToString("yyyyMMdd"), _oType.FullName,
                                "CreateDirectoryPath");
                }
                return(directories[directories.Length - 1] + "\\" + detailBar.DateTime.ToString("yyyyMMdd"));
            }
            catch (Exception exception)
            {
                Logger.Error(exception, _oType.FullName, "CreateDirectoryPath");
                return(null);
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            try
            {
                String docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\eSignal Files";

                if (Directory.Exists(docPath))
                {
                    var directory = new DirectoryInfo(docPath);

                    //foreach (FileInfo file in directory.GetFiles("*.xlsx"))
                    //{
                    //    ConvertExcelToCsv(file);
                    //}

                    foreach (FileInfo file in directory.GetFiles("*.xlsx"))
                    {
                        var dataSet = ReadFromExcelFile(file);
                        if (dataSet == null)
                        {
                            return;
                        }

                        int rowNo = 1;
                        while (rowNo < dataSet.Tables[0].Rows.Count)
                        {
                            string data = string.Empty;

                            for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
                            {
                                data += dataSet.Tables[0].Rows[rowNo][i].ToString() + ",";
                            }

                            string dataConverted = BarConverter.ConvertBars(data, file.Name.Split('.')[0]);

                            DetailBar detailBar = new DetailBar(new Bar(""));
                            detailBar.DateTime = DateTime.ParseExact(dataConverted.Split(',')[6],
                                                                     "M/d/yyyy h:mm:ss tt",
                                                                     CultureInfo.InvariantCulture);
                            detailBar.BarFormat    = BarFormat.TIME;
                            detailBar.BarPriceType = BarPriceType.LAST;
                            detailBar.BarLength    = 60;

                            FileWriter.WriteData(dataConverted, file.Name.Split('.')[0], detailBar);
                            rowNo++;
                        }
                    }

                    //foreach (FileInfo file in directory.GetFiles("*.csv"))
                    //{
                    //    FileStream fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.None);
                    //    StreamReader streamReader = new StreamReader(fileStream);

                    //    string dataRead = streamReader.ReadLine();

                    //    while ((dataRead = streamReader.ReadLine()) != null)
                    //    {
                    //        string dataConverted = BarConverter.CovertBars(dataRead, file.Name);

                    //        DetailBar detailBar= new DetailBar(new Bar(""));

                    //        detailBar.BarFormat = BarFormat.TIME;
                    //        detailBar.BarPriceType = BarPriceType.LAST;
                    //        detailBar.BarLength = 62;

                    //        FileWriter.WriteData(dataConverted, file.Name, detailBar);
                    //    }

                    //    streamReader.Close();
                    //    fileStream.Close();
                    //}
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception, _type.FullName, "Main");
            }
        }
 /// <summary>
 /// Initializes the metadata key/value pairs.
 /// </summary>
 void InitializeMetadata()
 {
     // This will create elements for all the metadata key/value pairs that is displayed in the DetailsBar.
     this.metadata.Add(DetailBar.CreateMetadataElement("Date modified:", this, DetailBar.CreateDateTimeMetadataValue("ModifiedTime")));
 }