public static int OutputFileLastDeven(InstrumentInfo instrument, int indexOfDate, bool isShamsiDate) { int num = 0; try { Settings settings = new Settings(); string str1 = settings.StorageLocation; if (settings.AdjustPricesCondition == 1 || settings.AdjustPricesCondition == 2) { str1 = settings.AdjustedStorageLocation; } string str2 = FileService.GetFileName(instrument, settings.FileName, settings.AdjustPricesCondition); string str3 = str2.Replace('\\', ' ').Replace('/', ' ').Replace('*', ' ').Replace(':', ' ').Replace('>', ' ').Replace('<', ' ').Replace('?', ' ').Replace('|', ' ').Replace('^', ' ').Replace('"', ' '); if (!File.Exists(str1 + "\\" + str3 + "." + settings.FileExtension)) { return(0); } using (StreamReader streamReader = new StreamReader((Stream)File.OpenRead(str1 + "\\" + str3 + "." + settings.FileExtension))) { string str4 = ""; while (!streamReader.EndOfStream) { str4 = streamReader.ReadLine(); } string[] strArray = str4.Split(','); num = isShamsiDate ? Utility.ConvertJalaliStringToGregorianInt(strArray[indexOfDate].ToString()) : Convert.ToInt32(strArray[indexOfDate].ToString()); } } catch (Exception ex) { throw ex; } return(num); }
public static string GetFileName(InstrumentInfo instrument, string filenameType, int AdjustPricesCondition) { string YMarNSC = instrument.YMarNSC; string filename = ""; switch (Convert.ToInt32(filenameType)) { case 0: filename = instrument.CIsin + FileService.GetSuffix(YMarNSC, AdjustPricesCondition); break; case 1: filename = instrument.LatinName + FileService.GetSuffix(YMarNSC, AdjustPricesCondition); break; case 2: filename = instrument.LatinSymbol + FileService.GetSuffix(YMarNSC, AdjustPricesCondition); break; case 3: filename = instrument.Name + FileService.GetSuffix(YMarNSC, AdjustPricesCondition, true); break; case 4: filename = instrument.Symbol + FileService.GetSuffix(YMarNSC, AdjustPricesCondition, true); break; default: filename = instrument.CIsin + FileService.GetSuffix(YMarNSC, AdjustPricesCondition); break; } return(filename); }
public static bool UpdateClosingPrices() { Settings settings = new Settings(); try { /*if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tدریافت اطلاعات ... "); this.progressBar.Value = 0; this.lblProgress.Text = "0%"; }*/ string str1 = ""; try { //str1 = ServerMethods.LastPossibleDeven(); str1 = "20190220;20190525"; } catch (Exception ex) { //ServerMethods.LogError("lastPossibleDEvens", ex); } if (str1.Equals("*")) { /*if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tبروز رسانی اطلاعات در حد فاصل ساعت هشت صبح تا یک بعد از ظهر روزهای شنبه تا چهارشنبه امکان پذیر نمی باشد."); this.rtbOperationLog.AppendText("\n\tجهت ساخت فایلها با اطلاعات فعلی از دکمه تعبیه شده در پایین صفحه استفاده کنید."); }*/ return false; } string[] strArray1 = str1.Split(';'); int int32_1 = Convert.ToInt32(strArray1[0]); int int32_2 = Convert.ToInt32(strArray1[1]); long[][] numArray1 = new long[StaticData.SelectedInstruments.Count][]; int index1 = 0; using (List<string>.Enumerator enumerator = StaticData.SelectedInstruments.GetEnumerator()) { while (enumerator.MoveNext()) { string item = enumerator.Current; int num = FileService.LastDeven(item); InstrumentInfo instrumentInfo = StaticData.Instruments.Find((Predicate<InstrumentInfo>)(p => p.InsCode == Convert.ToInt64(item))); if ((!(instrumentInfo.YMarNSC == "NO") || num != int32_1) && (!(instrumentInfo.YMarNSC == "ID") || num != int32_2)) { numArray1[index1] = new long[3]; numArray1[index1][0] = Convert.ToInt64(item); numArray1[index1][1] = Convert.ToInt64(num); numArray1[index1][2] = instrumentInfo.YMarNSC == "NO" ? 0L : 1L; ++index1; } } } int num1 = index1 % 20 != 0 ? index1 / 20 + 1 : index1 / 20; for (int index2 = 0; index2 < num1; ++index2) { int length = index2 < num1 - 1 ? 20 : index1 % 20; /*if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tدریافت بخش " + (index2 + 1).ToString() + " از " + (object)num1 + " اطلاعات ... "); if (length == 0) { this.lblProgress.Text = "100%"; continue; } }*/ long[][] numArray2 = new long[length][]; for (int index3 = 0; index3 < length; ++index3) { numArray2[index3] = new long[3]; numArray2[index3][0] = numArray1[index2 * 20 + index3][0]; numArray2[index3][1] = numArray1[index2 * 20 + index3][1]; numArray2[index3][2] = numArray1[index2 * 20 + index3][2]; } string str2 = ""; foreach (long[] numArray3 in numArray2) str2 = str2 + (object)numArray3[0] + "," + (object)numArray3[1] + "," + (object)numArray3[2] + ";"; //string insturmentClosingPrice = ServerMethods.GetInsturmentClosingPrice(str2.Substring(0, str2.Length - 1)); string insturmentClosingPrice = UCStepUpdate.dumb; if (insturmentClosingPrice.Equals("*")) { /*if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tبروز رسانی اطلاعات در حد فاصل ساعت هشت صبح تا یک بعد از ظهر روزهای شنبه تا چهارشنبه امکان پذیر نمی باشد."); this.rtbOperationLog.AppendText("\n\tجهت ساخت فایلها با اطلاعات فعلی از دکمه تعبیه شده در پایین صفحه استفاده کنید."); }*/ return false; } string str3 = insturmentClosingPrice; char[] chArray = new char[1] { '@' }; foreach (string str4 in str3.Split(chArray)) { if (!string.IsNullOrEmpty(str4)) { List<ClosingPriceInfo> cpList = new List<ClosingPriceInfo>(); string[] strArray2 = str4.Split(';'); for (int index3 = 0; index3 < strArray2.Length; ++index3) { ClosingPriceInfo closingPriceInfo = new ClosingPriceInfo(); try { string[] strArray3 = strArray2[index3].Split(','); closingPriceInfo.InsCode = Convert.ToInt64(strArray3[0].ToString()); closingPriceInfo.DEven = Convert.ToInt32(strArray3[1].ToString()); closingPriceInfo.PClosing = Convert.ToDecimal(strArray3[2].ToString()); closingPriceInfo.PDrCotVal = Convert.ToDecimal(strArray3[3].ToString()); closingPriceInfo.ZTotTran = Convert.ToDecimal(strArray3[4].ToString()); closingPriceInfo.QTotTran5J = Convert.ToDecimal(strArray3[5].ToString()); closingPriceInfo.QTotCap = Convert.ToDecimal(strArray3[6].ToString()); closingPriceInfo.PriceMin = Convert.ToDecimal(strArray3[7].ToString()); closingPriceInfo.PriceMax = Convert.ToDecimal(strArray3[8].ToString()); closingPriceInfo.PriceYesterday = Convert.ToDecimal(strArray3[9].ToString()); closingPriceInfo.PriceFirst = Convert.ToDecimal(strArray3[10].ToString()); cpList.Add(closingPriceInfo); } catch (Exception ex) { //ServerMethods.LogError("UpdateClosingPrices[Row:" + strArray2[index3] + "]", ex); throw ex; } } FileService.WriteClosingPrices(cpList); /*if (this.isVisual && cpList.Count > 0) { InstrumentInfo instrumentInfo = StaticData.Instruments.Find((Predicate<InstrumentInfo>)(p => p.InsCode == cpList[0].InsCode)); this.rtbOperationLog.AppendText("\n\t\tبروز رسانی اطلاعات " + instrumentInfo.Symbol + " (" + instrumentInfo.Name + ")"); }*/ } } /*if (this.isVisual) { this.lblProgress.Text = Convert.ToInt32((double)(index2 + 1) / (double)num1 * 100.0).ToString() + "%"; }*/ } /*if (this.isVisual) { if (num1 == 0) { this.lblProgress.Text = "100%"; } this.rtbOperationLog.AppendText("\n\tبروز رسانی اطلاعات نمادها با موفقیت انجام گردید\t "); this.rtbOperationLog.AppendText("\n\tجهت ایجاد خروجی جدید بر اساس اطلاعات بروز شده از دکمه تولید خروجی استفاده کنید "); }*/ return true; } catch (Exception ex) { if (ex.Message.Contains("The magic number in GZip header is not correct") && settings.EnableDecompression) { settings.EnableDecompression = false; settings.Save(); //this.owner.TabSwitcher(Tabs.Update); return false; } /*if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tبروز رسانی اطلاعات نمادها ناموفق بود. "); this.rtbOperationLog.AppendText(ServerMethods.LogError(nameof(UpdateClosingPrices), ex)); }*/ try { bool cond = false; //bool cond = FileService.LogErrorFile("[ UpdateClosingPrices (" + StaticData.Version + ") ] " + ex.Message + "(" + (ex.InnerException != null ? ex.InnerException.Message ?? "" : "") + ")") == -1; if (cond) { /*if (this.isVisual) { int num = (int)MessageBox.Show("مقدار فیلد محل ذخیره فایل ها صحیح نمی باشد "); }*/ } } catch { //this.rtbOperationLog.AppendText("\n\tثبت خطا در فایل ناموفق بود"); } return false; } }
public static bool GnerateFiles() { try { Settings settings = new Settings(); settings.AdjustPricesCondition = 2; // me //string path = settings.AdjustPricesCondition != 0 ? settings.AdjustedStorageLocation : settings.StorageLocation; string path = "./"; // me if ((string.IsNullOrEmpty(path) || !Directory.Exists(path))) // && this.isVisual { Console.WriteLine("\n\tمقدار فیلد محل ذخیره فایل ها صحیح نمی باشد "); return(false); } int cond = settings.AdjustPricesCondition; //settings.StartDate = settings.StartDate.Replace("/", "").ToString(); // unnecessary DateTime dateTime = Utility.ConvertJalaliStringToDateTime(settings.StartDate); int startDeven = dateTime.Year * 10000 + dateTime.Month * 100 + dateTime.Day; using (List <string> .Enumerator enumerator = StaticData.SelectedInstruments.GetEnumerator()) { // for each selected instrument while (enumerator.MoveNext()) { string currentItemInscode = enumerator.Current; List <ClosingPriceInfo> cp = FileService.ClosingPrices(Convert.ToInt64(currentItemInscode)); // all closing prices of a selected instrument cp = cp.FindAll((Predicate <ClosingPriceInfo>)(p => p.DEven >= startDeven)); if ((cond == 1 || cond == 2) && cp.Count > 1) // for both adjust conds { List <ClosingPriceInfo> closingPriceInfoList = new List <ClosingPriceInfo>(); Decimal num2 = new Decimal(1); closingPriceInfoList.Add(cp[cp.Count - 1]); double gaps = 0.0; // number of price gaps happened in whole history (capital-increase, dividends, intrument open-closes, etc) if (cond == 1) // cond 1 { for (int i = cp.Count - 2; i >= 0; --i) // for each cp (2ndlast to first) { if (cp[i].PClosing != cp[i + 1].PriceYesterday) { ++gaps; } } // above for loop detects capital increases, dividends or any kind of price gaps // formula: if closing price of previous day is not equal to today's yesterday-price // (if closing price of a day is not equal to yesterday-price of the next day) } // (gaps / cp.Count) = I don't understand this yet. // maybe if (gaps / cp.count) is < 0.08, then it's an indication of capital-increase & dividends if ((cond == 1 && gaps / cp.Count < 0.08) || cond == 2) // cond 2 (kinda) { for (int i = cp.Count - 2; i >= 0; --i) // for each cp (2ndlast to first) { Predicate <TseShareInfo> aShareThatsDifferent = p => { if (p.InsCode.ToString().Equals(currentItemInscode)) { return(p.DEven == cp[i + 1].DEven); } return(false); }; bool pricesDontMatch = cp[i].PClosing != cp[i + 1].PriceYesterday; if (cond == 1 && pricesDontMatch) // if found gap { num2 = num2 * cp[i + 1].PriceYesterday / cp[i].PClosing; // tomorrow's PriceYesterday / today's PClosing } else if (cond == 2 && pricesDontMatch && StaticData.TseShares.Exists(aShareThatsDifferent)) { var something = StaticData.TseShares.Find(aShareThatsDifferent); decimal oldShares = something.NumberOfShareOld; decimal newShares = something.NumberOfShareNew; num2 = (num2 * oldShares) / newShares; } closingPriceInfoList.Add(new ClosingPriceInfo() { InsCode = cp[i].InsCode, DEven = cp[i].DEven, PClosing = Math.Round(num2 * cp[i].PClosing, 2), PDrCotVal = Math.Round(num2 * cp[i].PDrCotVal, 2), ZTotTran = cp[i].ZTotTran, QTotTran5J = cp[i].QTotTran5J, QTotCap = cp[i].QTotCap, PriceMin = Math.Round(num2 * cp[i].PriceMin), PriceMax = Math.Round(num2 * cp[i].PriceMax), PriceYesterday = Math.Round(num2 * cp[i].PriceYesterday), PriceFirst = Math.Round(num2 * cp[i].PriceFirst, 2) }); } cp.Clear(); for (int index = closingPriceInfoList.Count - 1; index >= 0; --index) { cp.Add(closingPriceInfoList[index]); } } } // end of adjusting scenarios InstrumentInfo instrument = StaticData.Instruments.Find((Predicate <InstrumentInfo>)(p => p.InsCode.ToString().Equals(currentItemInscode))); if (!settings.ExcelOutput) { //FileService.WriteOutputFile(instrument, cp, !Program.chkRemoveOldFiles.Checked); FileService.WriteOutputFile(instrument, cp, false); } else { FileService.WriteOutputExcel(instrument, cp); } } } // end of for each selected instrument return(true); } catch (Exception ex) { var x = ex; return(false); } }
public static void WriteOutputExcel(InstrumentInfo instrument, List <ClosingPriceInfo> cp) { return; }
public static void WriteOutputFile(InstrumentInfo instrument, List <ClosingPriceInfo> cp, bool appendExistingFile) { Settings settings = new Settings(); string storageLocation = settings.StorageLocation; if (settings.AdjustPricesCondition == 1 || settings.AdjustPricesCondition == 2) { storageLocation = settings.AdjustedStorageLocation; } string delimiter = settings.Delimeter.ToString(); string filename = FileService.GetFileName(instrument, settings.FileName, settings.AdjustPricesCondition); // replace(char, with) // replaces invalid chars for windows file names in the settings.filename (set by user in settings panel) filename = filename.Replace('\\', ' ').Replace('/', ' ').Replace('*', ' ').Replace(':', ' ').Replace('>', ' ').Replace('<', ' ').Replace('?', ' ').Replace('|', ' ').Replace('^', ' ').Replace('"', ' '); int outputFileLastDeven = 0; if (appendExistingFile) { if (!File.Exists(storageLocation + "\\" + filename + "." + settings.FileExtension)) { appendExistingFile = false; } else { int indexOfDate = 0; bool isShamsiDate = false; foreach (ColumnInfo columnInfo in StaticData.ColumnsInfo) { if (columnInfo.Type == ColumnType.Date && columnInfo.Visible) { indexOfDate = columnInfo.Index - 1; isShamsiDate = false; break; } if (columnInfo.Type == ColumnType.ShamsiDate && columnInfo.Visible) { indexOfDate = columnInfo.Index; isShamsiDate = true; } } outputFileLastDeven = FileService.OutputFileLastDeven(instrument, indexOfDate, isShamsiDate); } } List <ColumnInfo> columnInfoList = FileService.ColumnsInfo(); //Encoding utF8 = Encoding.UTF8; // unnecessary Encoding encoding; switch (Convert.ToInt32(settings.Encoding)) { case 0: encoding = Encoding.Unicode; break; case 1: encoding = Encoding.UTF8; break; case 2: encoding = Encoding.GetEncoding(1256); break; default: encoding = Encoding.UTF8; break; } TextWriter textWriter = (TextWriter) new StreamWriter(storageLocation + "\\" + filename + "." + settings.FileExtension, appendExistingFile, encoding); columnInfoList.Sort((Comparison <ColumnInfo>)((s1, s2) => s1.Index.CompareTo(s2.Index))); // sort by index I think string headerRow = ""; if (settings.ShowHeaders && outputFileLastDeven == 0) { foreach (ColumnInfo columnInfo in columnInfoList) { if (columnInfo.Visible) { headerRow += columnInfo.Header; headerRow += delimiter; } } headerRow = headerRow.Substring(0, headerRow.Length - 1); textWriter.WriteLine(headerRow); } // this is where file is generated string YMarNSC = instrument.YMarNSC; int AdjustPricesCondition = settings.AdjustPricesCondition; foreach (ClosingPriceInfo closingPriceInfo in cp) { if ((!appendExistingFile || closingPriceInfo.DEven > outputFileLastDeven) && (settings.ExportDaysWithoutTrade || !(closingPriceInfo.ZTotTran == new Decimal(0)))) { string str6 = ""; foreach (ColumnInfo columnInfo in columnInfoList) { if (columnInfo.Visible) { switch (columnInfo.Type) { case ColumnType.CompanyCode: str6 += instrument.CompanyCode.ToString(); break; case ColumnType.LatinName: str6 += instrument.LatinName.ToString() + FileService.GetSuffix(YMarNSC, AdjustPricesCondition); break; case ColumnType.Symbol: str6 += instrument.Symbol.Replace(" ", "_").ToString() + FileService.GetSuffix(YMarNSC, AdjustPricesCondition, true); break; case ColumnType.Name: str6 += instrument.Name.Replace(" ", "_").ToString() + FileService.GetSuffix(YMarNSC, AdjustPricesCondition, true); break; case ColumnType.Date: str6 += closingPriceInfo.DEven.ToString(); break; case ColumnType.ShamsiDate: str6 += Utility.ConvertGregorianIntToJalaliInt(closingPriceInfo.DEven).ToString(); break; case ColumnType.PriceFirst: str6 += closingPriceInfo.PriceFirst.ToString(); break; case ColumnType.PriceMax: str6 += closingPriceInfo.PriceMax.ToString(); break; case ColumnType.PriceMin: str6 += closingPriceInfo.PriceMin.ToString(); break; case ColumnType.LastPrice: str6 += closingPriceInfo.PDrCotVal.ToString(); break; case ColumnType.ClosingPrice: str6 += closingPriceInfo.PClosing.ToString(); break; case ColumnType.Price: str6 += closingPriceInfo.QTotCap.ToString(); break; case ColumnType.Volume: str6 += closingPriceInfo.QTotTran5J.ToString(); break; case ColumnType.Count: str6 += closingPriceInfo.ZTotTran.ToString(); break; case ColumnType.PriceYesterday: str6 += closingPriceInfo.PriceYesterday.ToString(); break; } str6 += delimiter; } } string str7 = str6.Substring(0, str6.Length - 1); textWriter.WriteLine(str7); } } textWriter.Flush(); textWriter.Dispose(); }
public static string UpdateClosingPrices() { string result = "start"; string str1 = "20190811;20190811"; // string str1 = ServerMethods.LastPossibleDeven(); string[] strArray1 = str1.Split(';'); int int32_1 = Convert.ToInt32(strArray1[0]); int int32_2 = Convert.ToInt32(strArray1[1]); // long[][] numArray1 = new long[StaticData.SelectedInstruments.Count][]; long[][] numArray1 = new long[2][]; int index1 = 0; List <string> stringList = new List <string> { "44891482026867833" }; // stringList.Add(); // using (List<string>.Enumerator enumerator = StaticData.SelectedInstruments.GetEnumerator()) using (List <string> .Enumerator enumerator = stringList.GetEnumerator()) { while (enumerator.MoveNext()) { string item = enumerator.Current; int num = 20190810; // FileService.LastDeven(item); // InstrumentInfo instrumentInfo = StaticData.Instruments.Find((Predicate<InstrumentInfo>)(p => p.InsCode == Convert.ToInt64(item))); // List<InstrumentInfo> instrumentInfoList = new List<InstrumentInfo>(); // 44891482026867833,IRO1SIPA0001,SIPA1,Saipa,SIPA,خساپا,سايپا,IRO1SIPA0001,20190810,1,سايپا,A,N1,NO,3,34 ,3410,300 InstrumentInfo instrumentInfo = new InstrumentInfo() { InsCode = Convert.ToInt64("44891482026867833"), InstrumentID = "IRO1SIPA0001", LatinSymbol = "SIPA1", LatinName = "Saipa", CompanyCode = "SIPA", Symbol = "خساپا", Name = "سايپا", CIsin = "IRO1SIPA0001", DEven = Convert.ToInt32("20190810"), Flow = Convert.ToByte("1"), LSoc30 = "سايپا", CGdSVal = "A", CGrValCot = "N1", YMarNSC = "NO", CComVal = "3", CSecVal = "34", CSoSecVal = "3410", YVal = "300" }; if ((instrumentInfo.YMarNSC != "NO" || num != int32_1) && (instrumentInfo.YMarNSC != "ID" || num != int32_2)) { numArray1[index1] = new long[3]; numArray1[index1][0] = Convert.ToInt64(item); numArray1[index1][1] = Convert.ToInt64(num); numArray1[index1][2] = instrumentInfo.YMarNSC == "NO" ? 0L : 1L; ++index1; } } } int num1 = index1 % 20 != 0 ? index1 / 20 + 1 : index1 / 20; for (int index2 = 0; index2 < num1; ++index2) { int length = index2 < num1 - 1 ? 20 : index1 % 20; long[][] numArray2 = new long[length][]; for (int index3 = 0; index3 < length; ++index3) { numArray2[index3] = new long[3]; numArray2[index3][0] = numArray1[index2 * 20 + index3][0]; numArray2[index3][1] = numArray1[index2 * 20 + index3][1]; numArray2[index3][2] = numArray1[index2 * 20 + index3][2]; } string str2 = ""; foreach (long[] numArray3 in numArray2) { str2 = str2 + (object)numArray3[0] + "," + (object)numArray3[1] + "," + (object)numArray3[2] + ";"; } /* * long[] numArr = { 22645269567765904, 20190807, 1 }; * string str2 = ""; * str2 += (object)numArr[0]; * Console.WriteLine(str); */ result = str2.Substring(0, str2.Length - 1); return(result); // string insturmentClosingPrice = ServerMethods.GetInsturmentClosingPrice(str2.Substring(0, str2.Length - 1)); } return(result); }