public void ExecuteNSEEQUITYProcessing(string[] strMTOArr, string[] strNSEArr, string strNSESEC, string strOutputFormat, string strOutputFolder, Action <string> AddMessageToLog) { FileHelperEngine engineMTO = new FileHelperEngine(typeof(NSEMTO)); DelimitedClassBuilder cb = BuildNSECMPFile(); FileHelperEngine engineCMP = new FileHelperEngine(typeof(NSECMP)); FileHelperEngine engineSEC = new FileHelperEngine(typeof(NSESEC)); foreach (string obj in strNSEArr) { //Get NSE Equity Filename day, month, year int index = obj.IndexOf("cm"); string day = obj.Substring(index + 2, 2); string monthname = obj.Substring(index + 4, 3); string year = obj.Substring(index + 7, 4); int month = Convert.ToDateTime("01-" + monthname + "-2011").Month; if (month < 10) { monthname = "0"; } else { monthname = ""; } monthname += month.ToString(); string MTOfilename = "MTO_" + day + monthname + year + ".DAT"; string MTOfilenamewithpath = GetFileNameWithPath(strMTOArr, MTOfilename); if (!File.Exists(MTOfilenamewithpath)) { AddMessageToLog("File " + MTOfilenamewithpath + " does not exist!"); continue; } NSEMTO[] resmto = engineMTO.ReadFile(MTOfilenamewithpath) as NSEMTO[]; if (!File.Exists(obj)) { AddMessageToLog("File " + obj + " does not exist!"); continue; } NSECMP[] rescmp = engineCMP.ReadFile(obj) as NSECMP[]; if (!File.Exists(strNSESEC)) { AddMessageToLog("File " + strNSESEC + " does not exist!"); continue; } NSESEC[] ressec = engineSEC.ReadFile(strNSESEC) as NSESEC[]; int iTotalRows = rescmp.Length; for (int i = 0; i < iTotalRows; i++) { if (rescmp[i].Series == "EQ" || rescmp[i].Series == "BE") { //Copy OI from MTO for (int j = 0; j < resmto.Length; j++) { if ((resmto[j].NameOfSecurity == (string)rescmp[i].Symbol) && (resmto[j].series == (string)rescmp[i].Series)) { rescmp[i].OI = resmto[j].DeliverableQty; break; } } //Copy Security Name from SEC for (int j = 0; j < ressec.Length; j++) { if ((ressec[j].Symbol == (string)rescmp[i].Symbol)) { rescmp[i].SecurityName = ressec[j].SecurityName; break; } } } } //engineCMP.HeaderText = "Symbol,Series,Open,High,Low,Close,Last,PrevClose,Tottrdqty,Tottrdval,Timestamp,Totaltrades,Isin,OI,SecurityName"; //Dump File data engineCMP.HeaderText = "Ticker,Series,Open,High,Low,Close,Last,PrevClose,Volume,Tottrdval,Date,Totaltrades,Isin,OPENINT,NAME"; engineCMP.WriteFile(obj, rescmp); int totrows = 0; int itmp = 0; int cnt = 0; //Calculate number of rows which have series as EQ or BE and are not NULL while (cnt < rescmp.Length) { if (rescmp[cnt].Series == "EQ" || rescmp[cnt].Series == "BE") { totrows++; } cnt++; } NSECMPFINAL[] finalarr = new NSECMPFINAL[totrows]; DateTime myDate; itmp = 0; int icntr = 0; while (icntr < rescmp.Length) { if (rescmp[icntr].Series == "EQ" || rescmp[icntr].Series == "BE") { finalarr[itmp] = new NSECMPFINAL(); finalarr[itmp].Ticker = rescmp[icntr].Symbol; finalarr[itmp].Name = rescmp[icntr].SecurityName; myDate = DateTime.Parse(rescmp[icntr].Timestamp); finalarr[itmp].Date = String.Format("{0:yyyyMMdd}", myDate); finalarr[itmp].Open = rescmp[icntr].Open; finalarr[itmp].High = rescmp[icntr].High; finalarr[itmp].Low = rescmp[icntr].Low; finalarr[itmp].Close = rescmp[icntr].Close; finalarr[itmp].Volume = rescmp[icntr].Tottrdqty; finalarr[itmp].OpenInt = rescmp[icntr].OI; itmp++; } icntr++; } FileHelperEngine engineCMPFINAL = new FileHelperEngine(typeof(NSECMPFINAL)); engineCMPFINAL.HeaderText = "Ticker,Name,Date,Open,High,Low,Close,Volume,Openint"; engineCMPFINAL.WriteFile(obj, finalarr); //FileHelpers.CsvOptions options = new FileHelpers.CsvOptions("ImportRecord", ',', obj); //options.HeaderLines = 1; //FileHelperEngine test = new FileHelpers.CsvEngine(options); ////DataTable header = test.ReadStringAsDT(FileHelpers.CommonEngine.RawReadFirstLines(obj, 1)); ////test.Options.IgnoreFirstLines = 0; //DataTable dttest = test.ReadFileAsDT(obj); string[] words = null; words = strOutputFormat.Split(','); //Get Filename index = obj.IndexOf("cm"); string fname = obj.Substring(index, 19); string folder; foreach (string item in words) { string outputfoldername = Path.Combine(strOutputFolder, item, "NSE", "Equity"); if (item == "StdCSV" || item == "Metastock" || item == "Ninja" || item == "FCharts") { folder = Path.Combine(strOutputFolder, item, "NSE", "Equity", fname); if (!Directory.Exists(outputfoldername)) { AddMessageToLog("Directory " + outputfoldername + " does not exist!"); } else { File.Copy(obj, folder, true); } } else if (item == "Amibroker") { engineCMPFINAL.Options.IgnoreFirstLines = 1; engineCMPFINAL.WriteFile(obj, finalarr); folder = Path.Combine(strOutputFolder, item, "NSE", "Equity", fname); if (!Directory.Exists(outputfoldername)) { AddMessageToLog("Directory " + outputfoldername + " does not exist!"); } else { File.Copy(obj, folder, true); } } } File.Delete(obj); } }
public void ExecuteNSEEQUITYProcessing(string[] strMTOArr, string[] strNSEArr, string strNSESEC, string strOutputFormat, string strOutputFolder, Action<string> AddMessageToLog) { FileHelperEngine engineMTO = new FileHelperEngine(typeof(NSEMTO)); DelimitedClassBuilder cb = BuildNSECMPFile(); FileHelperEngine engineCMP = new FileHelperEngine(typeof(NSECMP)); FileHelperEngine engineSEC = new FileHelperEngine(typeof(NSESEC)); foreach (string obj in strNSEArr) { //Get NSE Equity Filename day, month, year int index = obj.IndexOf("cm"); string day = obj.Substring(index+2, 2); string monthname = obj.Substring(index+4, 3); string year = obj.Substring(index+7,4); int month = Convert.ToDateTime("01-" + monthname + "-2011").Month; if (month < 10) monthname = "0"; else monthname = ""; monthname += month.ToString(); string MTOfilename = "MTO_" + day + monthname + year + ".DAT"; string MTOfilenamewithpath = GetFileNameWithPath(strMTOArr, MTOfilename); if (!File.Exists(MTOfilenamewithpath)) { AddMessageToLog("File " + MTOfilenamewithpath + " does not exist!"); continue; } NSEMTO[] resmto = engineMTO.ReadFile(MTOfilenamewithpath) as NSEMTO[]; if (!File.Exists(obj)) { AddMessageToLog("File " + obj + " does not exist!"); continue; } NSECMP[] rescmp = engineCMP.ReadFile(obj) as NSECMP[]; if (!File.Exists(strNSESEC)) { AddMessageToLog("File " + strNSESEC + " does not exist!"); continue; } NSESEC[] ressec = engineSEC.ReadFile(strNSESEC) as NSESEC[]; int iTotalRows = rescmp.Length; for (int i = 0; i < iTotalRows; i++) { if (rescmp[i].Series == "EQ" || rescmp[i].Series == "BE") { //Copy OI from MTO for (int j = 0; j < resmto.Length; j++) { if ((resmto[j].NameOfSecurity == (string)rescmp[i].Symbol) && (resmto[j].series == (string)rescmp[i].Series)) { rescmp[i].OI = resmto[j].DeliverableQty; break; } } //Copy Security Name from SEC for (int j = 0; j < ressec.Length; j++) { if ((ressec[j].Symbol == (string)rescmp[i].Symbol)) { rescmp[i].SecurityName = ressec[j].SecurityName; break; } } } } //engineCMP.HeaderText = "Symbol,Series,Open,High,Low,Close,Last,PrevClose,Tottrdqty,Tottrdval,Timestamp,Totaltrades,Isin,OI,SecurityName"; //Dump File data engineCMP.HeaderText = "Ticker,Series,Open,High,Low,Close,Last,PrevClose,Volume,Tottrdval,Date,Totaltrades,Isin,OPENINT,NAME"; engineCMP.WriteFile(obj, rescmp); int totrows = 0; int itmp = 0; int cnt = 0; //Calculate number of rows which have series as EQ or BE and are not NULL while(cnt < rescmp.Length) { if (rescmp[cnt].Series == "EQ" || rescmp[cnt].Series == "BE") totrows++; cnt++; } NSECMPFINAL[] finalarr = new NSECMPFINAL[totrows]; DateTime myDate; itmp = 0; int icntr = 0; while (icntr < rescmp.Length) { if (rescmp[icntr].Series == "EQ" || rescmp[icntr].Series == "BE") { finalarr[itmp] = new NSECMPFINAL(); finalarr[itmp].Ticker = rescmp[icntr].Symbol; finalarr[itmp].Name = rescmp[icntr].SecurityName; myDate = DateTime.Parse(rescmp[icntr].Timestamp); finalarr[itmp].Date = String.Format("{0:yyyyMMdd}", myDate); finalarr[itmp].Open = rescmp[icntr].Open; finalarr[itmp].High = rescmp[icntr].High; finalarr[itmp].Low = rescmp[icntr].Low; finalarr[itmp].Close = rescmp[icntr].Close; finalarr[itmp].Volume = rescmp[icntr].Tottrdqty; finalarr[itmp].OpenInt = rescmp[icntr].OI; itmp++; } icntr++; } FileHelperEngine engineCMPFINAL = new FileHelperEngine(typeof(NSECMPFINAL)); engineCMPFINAL.HeaderText = "Ticker,Name,Date,Open,High,Low,Close,Volume,Openint"; engineCMPFINAL.WriteFile(obj, finalarr); //FileHelpers.CsvOptions options = new FileHelpers.CsvOptions("ImportRecord", ',', obj); //options.HeaderLines = 1; //FileHelperEngine test = new FileHelpers.CsvEngine(options); ////DataTable header = test.ReadStringAsDT(FileHelpers.CommonEngine.RawReadFirstLines(obj, 1)); ////test.Options.IgnoreFirstLines = 0; //DataTable dttest = test.ReadFileAsDT(obj); string[] words = null; words = strOutputFormat.Split(','); //Get Filename index = obj.IndexOf("cm"); string fname = obj.Substring(index, 19); string folder; foreach (string item in words) { string outputfoldername = Path.Combine(strOutputFolder, item, "NSE", "Equity"); if (item == "StdCSV" || item == "Metastock" || item == "Ninja" || item == "FCharts") { folder = Path.Combine(strOutputFolder, item, "NSE", "Equity", fname); if (!Directory.Exists(outputfoldername)) AddMessageToLog("Directory " + outputfoldername + " does not exist!"); else File.Copy(obj, folder, true); } else if (item == "Amibroker") { engineCMPFINAL.Options.IgnoreFirstLines = 1; engineCMPFINAL.WriteFile(obj, finalarr); folder = Path.Combine(strOutputFolder, item, "NSE", "Equity", fname); if (!Directory.Exists(outputfoldername)) AddMessageToLog("Directory " + outputfoldername + " does not exist!"); else File.Copy(obj, folder, true); } } File.Delete(obj); } }