public List <OIDetails> LoadOIData(string _nseUrl, string _expiryDate, string _listofSources) { IOData objData = new IOData(); string[] listsources = _listofSources.Split(','); List <OIDetails> objList = new List <OIDetails>(); List <string> dnames = new List <string>(); foreach (var item in listsources) { try { string[] names = item.Split('#'); string newNseUrl = _nseUrl.Replace("NSECOMPANYNAME", names[0]); newNseUrl = newNseUrl.Replace("INDEXTYPE", names[2]); newNseUrl = newNseUrl.Replace("EXPIRYDATE", _expiryDate); OIDetails data = objData.GenerateOIData(newNseUrl); objList.Add(data); if (data.pchangeinOpenInterest == null || data.pchangeinOpenInterest == "") { dnames.Add(newNseUrl); } } catch (Exception ex) { } } return(objList.Where(x => x.CompanyCode != null).ToList()); }
public List <OIDetails> LoadOptionsData(string _masterDatapathBasic, string _bnExpiryDate, string currentIndexValue, float Size, int count) { OIDetails O = GenerateOIData(currentIndexValue); List <OIDetails> objList = new List <OIDetails>(); List <Types> data = GenerateIndexValues(O.underlyingValue, Size, count); string Name = "BANKNIFTY"; if (Size == 50) { Name = "NIFTY"; } foreach (var item in data[0].requiredValues) { if (item.ToString().Contains('.')) { string _ceurl = _masterDatapathBasic.Replace("EXPIRYCODE", _bnExpiryDate).Replace("TYPECEPE", "CE").Replace("BANKNIFTY", Name).Replace("INDEXVALUE.00", item.ToString() + "0"); objList.Add(GenerateOIData(_ceurl)); string _peurl = _masterDatapathBasic.Replace("EXPIRYCODE", _bnExpiryDate).Replace("TYPECEPE", "PE").Replace("BANKNIFTY", Name).Replace("INDEXVALUE.00", item.ToString() + "0"); objList.Add(GenerateOIData(_peurl)); } else { string _ceurl = _masterDatapathBasic.Replace("EXPIRYCODE", _bnExpiryDate).Replace("TYPECEPE", "CE").Replace("BANKNIFTY", Name).Replace("INDEXVALUE", item.ToString()); objList.Add(GenerateOIData(_ceurl)); string _peurl = _masterDatapathBasic.Replace("EXPIRYCODE", _bnExpiryDate).Replace("TYPECEPE", "PE").Replace("BANKNIFTY", Name).Replace("INDEXVALUE", item.ToString()); objList.Add(GenerateOIData(_peurl)); } } return(objList); }
public List <OIDetails> GenerateToolTip(List <OIDetails> optionsData) { List <OIDetails> objList = new List <OIDetails>(); OIDetails objItem = null; var newData = optionsData.GroupBy(x => x.strikePrice + x.optionType); int count = newData.Count() / 2; int CurrentSeries = 0; foreach (var item in newData) { CurrentSeries++; objItem = new OIDetails(); objItem = item.ToList()[0]; if (CurrentSeries > count && CurrentSeries < count + 4) { objItem.BackColor = "darkgray"; } else { objItem.BackColor = "none"; } var data = item.Select(x => x.changeinOpenInterest).ToList(); objItem.changeinOpenInterest = data[0] + "#" + string.Join(Environment.NewLine, data.ToArray()); // data = item.Select(x => x.strikePrice).ToList(); //objItem.strikePrice = data[0] + "#" + string.Join(Environment.NewLine, data.ToArray()); data = item.Select(x => x.pchangeinOpenInterest).ToList(); objItem.pchangeinOpenInterest = data[0] + "#" + string.Join(Environment.NewLine, data.ToArray()); data = item.Select(x => x.openInterest).ToList(); objItem.openInterest = data[0] + "#" + string.Join(Environment.NewLine, data.ToArray()); data = item.Select(x => x.vwap).ToList(); objItem.vwap = data[0] + "#" + string.Join(Environment.NewLine, data.ToArray()); data = item.Select(x => x.lastPrice).ToList(); objItem.lastPrice = data[0] + "#" + string.Join(Environment.NewLine, data.ToArray()); data = item.Select(x => x.prevClose).ToList(); objItem.prevClose = data[0] + "#" + string.Join(Environment.NewLine, data.ToArray()); data = item.Select(x => x.openPrice).ToList(); objItem.openPrice = data[0] + "#" + string.Join(Environment.NewLine, data.ToArray()); data = item.Select(x => x.highPrice).ToList(); objItem.highPrice = data[0] + "#" + string.Join(Environment.NewLine, data.ToArray()); data = item.Select(x => x.lowPrice).ToList(); objItem.lowPrice = data[0] + "#" + string.Join(Environment.NewLine, data.ToArray()); objList.Add(objItem); } var countData = objList.Sum(x => Convert.ToInt64(x.openInterest.Split('#')[0].Replace(",", ""))); objList[0].TotalCount = countData.ToString(); return(objList); }
private List <OIDetails> BankNiftyMoving(List <OIDetails> queryData) { List <OIDetails> objData = new List <OIDetails>(); OIDetails cmpDetails = null; string stringToReplace = "\"}],\""; var data = queryData.GroupBy(x => x.OISavedTimeStamp.Date).ToList(); decimal previousDayMaxValue = 0.0M; decimal maxValue = 0.0M; decimal fastPercentage = 0.0M; int fastId = 0; int Id = 0; foreach (var item in data) { previousDayMaxValue = maxValue; maxValue = item.Max(x => Convert.ToDecimal(x.NumberOfContractsTraded.Replace(stringToReplace, ""))); Id = 0; fastId = 0; foreach (var collection in item) { cmpDetails = new OIDetails(); cmpDetails.OISavedTimeStamp = collection.OISavedTimeStamp; cmpDetails.PchangeinOpenInterest = collection.PchangeinOpenInterest; cmpDetails.PrevClose = collection.PrevClose; cmpDetails.CompanyCode = collection.CompanyCode; cmpDetails.ExpiryDate = collection.ExpiryDate; cmpDetails.LowPrice = collection.LowPrice; cmpDetails.LastPrice = collection.LastPrice; cmpDetails.totalBuyQuantity = collection.totalBuyQuantity; cmpDetails.totalSellQuantity = collection.totalSellQuantity; cmpDetails.HighPrice = collection.HighPrice; cmpDetails.UnderlyingValue = collection.UnderlyingValue; cmpDetails.PChange = collection.PChange; cmpDetails.NumberOfContractsTraded = collection.NumberOfContractsTraded; cmpDetails.Id = Id; Id++; if (previousDayMaxValue != 0.0M) { cmpDetails.CurrentPrevdayVolumePercentage = Math.Round(((Convert.ToDecimal(cmpDetails.NumberOfContractsTraded) * 100) / previousDayMaxValue), 2).ToString(); if (fastId != 0 && fastPercentage > 0) { cmpDetails.fastPercentage = Math.Round(((Convert.ToDecimal(cmpDetails.CurrentPrevdayVolumePercentage) * 100) / fastPercentage - 100), 2).ToString(); } fastPercentage = Convert.ToDecimal(cmpDetails.CurrentPrevdayVolumePercentage); } fastId++; cmpDetails.CalcDayVolume = String.Format(new CultureInfo("en-IN", false), "{0:n}", maxValue); //{0,n} used for inject the comma's in number objData.Add(cmpDetails); } } if (queryData.Count != objData.Count) { throw new Exception("Error in counting the BN Moving"); } return(objData.OrderByDescending(x => x.OISavedTimeStamp).ToList()); }
public List <OIDetails> CheckPriceWeekIOWeek(string _masterDatapathBasic, string _defaultDate) { ////test to read data OBJtoXML xmltoObj = new OBJtoXML(); BulkEntity datafromXML = new BulkEntity(); datafromXML.OIData = new List <OIDetails>(); var txtFiles = Directory.EnumerateFiles(_masterDatapathBasic, "*.txt").OrderByDescending(d => new FileInfo(d).LastWriteTime).ToArray(); List <string> filesList = FilterDates(txtFiles.ToList(), _defaultDate); foreach (string currentFile in filesList) { datafromXML.OIData.AddRange((List <OIDetails>)xmltoObj.CreateObject(datafromXML.OIData, currentFile, false)); break; } var query7 = datafromXML.OIData.Where(x => x.PchangeinOpenInterest != null && x.PChange != null && x.PchangeinOpenInterest != "-" && x.PChange != "-") .Where(x => Convert.ToDecimal(x.PChange) < 0 && Convert.ToDecimal(x.PchangeinOpenInterest) < 0) .Select(x => new { Code = x.CompanyCode, x.PChange, x.PchangeinOpenInterest, }) .OrderByDescending(x => x.PchangeinOpenInterest) .ToList(); List <OIDetails> newlist = new List <OIDetails>(); OIDetails cmp = null; foreach (var item in query7) { cmp = new OIDetails(); cmp.CompanyCode = item.Code; cmp.PChange = item.PChange.ToString(); cmp.PchangeinOpenInterest = item.PchangeinOpenInterest; newlist.Add(cmp); } return(newlist); }
private OIDetails GenerateOIData(string nseurl) { //string text = System.IO.File.ReadAllText(@"D:\txtData.txt"); OIDetails obj = new OIDetails(); string text = GetHtmlString(nseurl); try { string[] text1 = text.Split(new[] { "content_big" }, StringSplitOptions.None); string[] text2 = text1[0].Split(new[] { "tradedDate" }, StringSplitOptions.None); string data = text2[1].ToString(); string s = @""","""; s = s.Remove(s.Length - 1); string[] text3 = data.Split(new[] { s }, StringSplitOptions.None); foreach (var item in GetOIProperties()) { string result = text3.FirstOrDefault(n => n.Contains(item)); result = result.Split(new[] { "</div>" }, StringSplitOptions.None)[0].Trim(); string text4 = result.Split(new[] { item }, StringSplitOptions.None)[1].Remove(0, 3); obj.OISavedTimeStamp = DateTime.Now; if (item == "underlying") { obj.CompanyCode = text4; } if (item == "highPrice") { obj.HighPrice = text4; } if (item == "pchangeinOpenInterest") { obj.PchangeinOpenInterest = text4; } if (item == "expiryDate") { obj.ExpiryDate = text4; } if (item == "openInterest") { obj.OpenInterest = text4; } if (item == "underlyingValue") { obj.UnderlyingValue = text4; } if (item == "numberOfContractsTraded") { obj.NumberOfContractsTraded = text4; } if (item == "lowPrice") { obj.LowPrice = text4; } if (item == "lastPrice") { obj.LastPrice = text4.Split('}')[0].Remove(text4.Split('}')[0].Length - 1); } if (item == "prevClose") { obj.PrevClose = text4; } if (item == "lastUpdateTime") { obj.LastUpdateTime = text4; } if (item == "pChange") { obj.PChange = text4; } if (item == "totalBuyQuantity") { obj.totalBuyQuantity = text4; } if (item == "totalSellQuantity") { obj.totalSellQuantity = text4; } if (item == "openPrice") { obj.OpenPrice = text4; } if (item == "closePrice") { obj.Closed = text4; } } } catch (Exception ex) { } return(obj); }
private OIDetails GenerateOIData(string nseurl) { //string text = System.IO.File.ReadAllText(@"D:\txtData.txt"); OIDetails obj = new OIDetails(); string text = GetHtmlString(nseurl); try { string[] text1 = text.Split(new[] { "valid" }, StringSplitOptions.None); string[] text2 = text1[1].Split(new[] { "eqLink" }, StringSplitOptions.None); string data = text2[0].ToString(); string s = @""","""; s = s.Remove(s.Length - 1); string[] text3 = data.Split(new[] { s }, StringSplitOptions.None); foreach (var item in GetOIProperties()) { string result = text3.FirstOrDefault(n => n.Contains(item)); string text4 = result.Split(new[] { item }, StringSplitOptions.None)[1].Remove(0, 3); obj.SavedTimeStamp = DateTime.Now; if (item == "lastPrice") { obj.lastPrice = text4; } if (item == "prevClose") { obj.prevClose = text4; } if (item == "openPrice") { obj.openPrice = text4; } if (item == "highPrice") { obj.highPrice = text4.Split('}')[0].Replace("\"", ""); } if (item == "lowPrice") { obj.lowPrice = text4; } if (item == "closePrice") { obj.closePrice = text4; } if (item == "vwap") { obj.vwap = text4; } if (item == "underlyingValue") { obj.underlyingValue = text4; } if (item == "changeinOpenInterest") { obj.changeinOpenInterest = text4; } if (item == "prevClose") { obj.prevClose = text4; } if (item == "openInterest") { obj.openInterest = text4; } if (item == "pchangeinOpenInterest") { obj.pchangeinOpenInterest = text4; } if (item == "instrumentType") { obj.instrumentType = text4; } if (item == "strikePrice") { obj.strikePrice = text4; } if (item == "expiryDate") { obj.expiryDate = text4; } if (item == "optionType") { obj.optionType = text4; } if (item == "underlying") { obj.underlying = text4; } } } catch (Exception ex) { } return(obj); }