IEnumerable <Queue <Charts> > FindTheOldestDueDate(string code) { var temporary = new Temporary(code.Length); if (code.Length == 8 && Temporary.CodeStorage != null && Temporary.CodeStorage.Any(o => o.Code.StartsWith(code.Substring(0, 3)) && o.Code.EndsWith(code.Substring(5)))) { var stack = new Stack <Codes>(); var days = temporary.CallUpTheChartAsync(code); foreach (var arg in Temporary.CodeStorage.Where(o => o.Code.StartsWith(code.Substring(0, 3)) && o.Code.EndsWith(code.Substring(5))).OrderByDescending(o => o.MaturityMarketCap.Length == 8 ? o.MaturityMarketCap.Substring(2) : o.MaturityMarketCap)) { stack.Push(arg); } Days = days.Result; while (stack.Count > 0) { yield return(temporary.CallUpTheChartAsync(stack.Pop()).Result); } } else if (code.Length == 6 && Temporary.CodeStorage != null && Temporary.CodeStorage.Any(o => o.Code.Equals(code))) { Market = Temporary.CodeStorage.First(o => o.Code.Equals(code)).MarginRate == 1; string sDate = temporary.FindTheChartStartsAsync(code).Result, date = string.IsNullOrEmpty(sDate) ? DateTime.Now.AddDays(-5).ToString(format) : sDate.Substring(0, 6); Days = new Queue <Charts>(); foreach (var day in temporary.CallUpTheChartAsync(code).Result) { if (string.Compare(day.Date.Substring(2), date) < 0) { Days.Enqueue(day); } } if (int.TryParse(date, out int start)) { var end = string.Empty; var count = 0; while (string.IsNullOrEmpty(end) || string.Compare(end, DateTime.Now.ToString(format)) <= 0) { if (end.CompareTo(excluding) > 0 && end.CompareTo(theDate) < 0) { for (int i = 0; i < 0x1C; i++) { count++; } } yield return(temporary.CallUpTheChartAsync(new Catalog.Request.Charts { Code = code, Start = (start - 1 + 0x12C * count++).ToString(nFormat), End = end = (start - 1 + 0x12C * count).ToString(nFormat) }).Result); } } } }
protected internal long StartProgress(string code) { if (string.IsNullOrEmpty(code) == false) { var revise = new Temporary(code.Length).CallUpTheRevisedStockPrice(code).Result; var modify = revise != null && revise.Count > 0 ? new Catalog.Request.ConfirmRevisedStockPrice[revise.Count] : null; var index = 0; foreach (var queue in FindTheOldestDueDate(code)) { if (queue != null && queue.Count > 0) { var enumerable = queue.OrderBy(o => o.Date); var before = enumerable.First().Date.Substring(0, 6); while (revise != null && revise.Count > 0) { var param = revise.Dequeue(); if (param.Date.CompareTo(Days.Count > 0 ? Days.Max(o => o.Date).Substring(2) : before) > 0) { if (revise.Count == 0) { modify[index] = param; break; } var peek = revise.Peek(); if (param.Rate != peek.Rate) { modify[index++] = param; } } } if (Days.Count > 0) { foreach (var day in Days.OrderBy(o => o.Date)) { if (string.Compare(day.Date.Substring(2), before) < 0) { SendConsecutive convey; if (modify != null && int.TryParse(day.Price, out int price)) { var rate = 1D; foreach (var param in Array.FindAll(modify, o => string.IsNullOrEmpty(o.Date) == false && o.Date.CompareTo(day.Date.Substring(2)) > 0)) { rate *= param.Rate; } convey = new SendConsecutive(day.Date, GetStartingPrice((int)((1 + rate * 1e-2) * price), Market), day.Volume); } else { convey = new SendConsecutive(day); } Send?.Invoke(this, convey); } } Days.Clear(); } foreach (var consecutive in enumerable) { SendConsecutive convey; if (modify != null && int.TryParse(consecutive.Price, out int price)) { var rate = 1D; foreach (var param in Array.FindAll(modify, o => string.IsNullOrEmpty(o.Date) == false && o.Date.CompareTo(consecutive.Date.Substring(0, 6)) > 0)) { rate *= param.Rate; } convey = new SendConsecutive(consecutive.Date, GetStartingPrice((int)((1 + rate * 1e-2) * price), Market), consecutive.Volume); } else { convey = new SendConsecutive(consecutive); } Send?.Invoke(this, convey); } } } } return(GC.GetTotalMemory(true)); }
IEnumerable <Queue <Charts> > FindTheOldestDueDate(string code) { if (code.Length == 8 && Temporary.CodeStorage != null && Temporary.CodeStorage.Any(o => o.Code.Length == 8 && o.Code.StartsWith(code.Substring(0, 3)) && o.Code.EndsWith(code.Substring(5)))) { var stack = new Stack <Codes>(); if (code[0].Equals('1')) { MarginRate = Temporary.CodeStorage.First(o => o.Code.Equals(code)).MarginRate; TransactionMultiplier = GetTransactionMultiplier(code); } foreach (var arg in Temporary.CodeStorage.Where(o => o.Code.StartsWith(code.Substring(0, 3)) && o.Code.EndsWith(code.Substring(5))) .OrderByDescending(o => o.MaturityMarketCap.Length == 8 ? o.MaturityMarketCap.Substring(2) : o.MaturityMarketCap)) { stack.Push(arg); Days = new Queue <Charts>(); if (uint.TryParse(arg.MaturityMarketCap.Length == 8 ? arg.MaturityMarketCap.Substring(2) : arg.MaturityMarketCap, out uint remain) && Temporary.RemainingDay.Add(remain - 1)) { Console.WriteLine(code + "_" + Temporary.RemainingDay.Count + "_" + (remain - 1)); } } foreach (var day in Temporary.CallUpTheChartAsync(code).Result) { Days.Enqueue(day); } while (stack.Count > 0) { var codes = stack.Pop(); if (codes.Code.Equals("105QA000")) { foreach (var arg in Temporary.CallUpTheChartAsync(Temporary.CodeStorage.First(o => o.Code.Equals("101QC000"))).Result) { if (arg.Date.Substring(6, 4).Equals("1545")) { Days.Enqueue(new Charts { Date = string.Concat("20", arg.Date.Substring(0, 6)), Price = arg.Price }); } } continue; } yield return(Temporary.CallUpTheChartAsync(codes).Result); } } else if (code.Length == 6 && Temporary.CodeStorage != null && Temporary.CodeStorage.Any(o => o.Code.Equals(code))) { Market = Temporary.CodeStorage.First(o => o.Code.Equals(code)).MarginRate == 1; string sDate = Temporary.FindTheChartStartsAsync(code).Result, date = string.IsNullOrEmpty(sDate) ? DateTime.Now.AddDays(-5).ToString(format) : sDate.Substring(0, 6); Days = new Queue <Charts>(); foreach (var day in Temporary.CallUpTheChartAsync(code).Result) { if (string.Compare(day.Date.Substring(2), date) < 0) { Days.Enqueue(day); } } if (DateTime.TryParseExact(date, format, CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime start)) { var end = string.Empty; var count = 0; while (string.IsNullOrEmpty(end) || string.Compare(end, DateTime.Now.ToString(format)) <= 0) { yield return(Temporary.CallUpTheChartAsync(new Catalog.Request.Charts { Code = code, Start = start.AddDays(-1).AddDays(0x4B * count++).ToString(format), End = end = start.AddDays(-1).AddDays(0x4B * count).ToString(format) }).Result); } } } }