public double GetValue(RawPrice.Value_e eValue) { if (Exac != null) { return(Exac[eValue]); } if (Prev == null) { if (Next == null) { return(UNKNOWN_CURRENCY_PAIR_VALUE); } return(Next[eValue]); } if (Next == null) { return(Prev[eValue]); } long p = DateTimeToSec.toSec(Prev.DateTime); long e = DateTimeToSec.toSec(this.DateTime); long n = DateTimeToSec.toSec(Next.DateTime); double rate = (double)(e - p) / (n - p); return(Prev[eValue] + (Next[eValue] - Prev[eValue]) * rate); }
private void ExpandSpan(double rate) { long sec1 = DateTimeToSec.ToSec(long.Parse(this.DateTimeSt.Text)); long sec2 = DateTimeToSec.ToSec(long.Parse(this.DateTimeEd.Text)); long span = sec2 - sec1; span = Math.Max(span, 120); // 2 min <= span = DoubleTools.ToLong(span * rate); sec1 = sec2 - span; long st = DateTimeToSec.ToDateTime(sec1); st = Math.Max(st, Ground.I.Period_DateTimeSt); sec1 = DateTimeToSec.ToSec(st); sec2 = sec1 + span; long ed = DateTimeToSec.ToDateTime(sec2); ed = Math.Min(ed, Ground.I.Period_DateTimeEd); this.DateTimeSt.Text = st.ToString(); this.DateTimeEd.Text = ed.ToString(); }
private void MChart_MouseMove(object sender, MouseEventArgs e) { int x = e.X; int y = e.Y; if (this.MCMM_LastX == x && this.MCMM_LastY == y) { return; } this.MCMM_LastX = x; this.MCMM_LastY = y; try { double aX = this.MChart.ChartAreas[0].AxisX.PixelPositionToValue(x); double aY = this.MChart.ChartAreas[0].AxisY.PixelPositionToValue(y); long sec = this.LastStartWeSec + LongTools.toInt(aX * 86400.0); sec = WeSec.WeSecToSec(sec); long dateTime = DateTimeToSec.toDateTime(sec); this.TTip.SetToolTip( this.MChart, Utils.DateTimeToString(dateTime) + "\n" + aY ); } catch { } }
private void MainWin_Shown(object sender, EventArgs e) { // -- 0001 try { Ground.I = new Ground(); Ground.I.LoadDataDir(); this.CurrPair.SelectedIndex = 22; // USDJPY { long ed = Ground.I.Period_DateTimeEd; long st = DateTimeToSec.ToDateTime(DateTimeToSec.ToSec(ed) - 86400 * 5); this.DateTimeSt.Text = st.ToString(); this.DateTimeEd.Text = ed.ToString(); } this.CondChanged(); } catch (Exception ex) { MessageDlgTools.Error(Program.APP_TITLE + " - Error @ Shown", ex); Environment.Exit(1); // unrecoverable error } // ---- this.MTBusy.Leave(); }
private void BtnForward_Click(object sender, EventArgs e) { this.UIEvent_Go(() => { { long sec1 = DateTimeToSec.ToSec(long.Parse(this.DateTimeSt.Text)); long sec2 = DateTimeToSec.ToSec(long.Parse(this.DateTimeEd.Text)); long span = sec2 - sec1; span = Math.Max(span, 0); sec2 += span / 2; long ed = DateTimeToSec.ToDateTime(sec2); ed = Math.Min(ed, Ground.I.Period_DateTimeEd); sec2 = DateTimeToSec.ToSec(ed); sec1 = sec2 - span; long st = DateTimeToSec.ToDateTime(sec1); st = Math.Max(st, Ground.I.Period_DateTimeSt); this.DateTimeSt.Text = st.ToString(); this.DateTimeEd.Text = ed.ToString(); } CondChanged_ByBtn(); }); }
private void Test01() { Console.WriteLine("TTConsts.TTSEC_MIN: " + TTConsts.TTSEC_MIN); Console.WriteLine("TTConsts.TTSEC_MAX: " + TTConsts.TTSEC_MAX); Console.WriteLine("TTConsts.DTSEC_MIN: " + DateTimeToSec.ToSec(CSConsts.DATE_TIME_MIN)); Console.WriteLine("TTConsts.DTSEC_MAX: " + DateTimeToSec.ToSec(CSConsts.DATE_TIME_MAX)); }
private void LoadGraph(CurrencyPair cPair) { //CurrencyPairs.FxCollect(); this.MChart.Series.Clear(); this.MChart.Legends.Clear(); this.MChart.ChartAreas.Clear(); double minMid = double.MaxValue; double maxMid = double.MinValue; long currSec = DateTimeToSec.Now.getSec(); Series srs = new Series(); srs.ChartType = SeriesChartType.Line; srs.Color = Color.OrangeRed; for (long sec = currSec - 86400L * 7L; sec <= currSec; sec += 30L) { double mid = cPair.GetPrice(DateTimeToSec.toDateTime(sec)).Mid; minMid = Math.Min(minMid, mid); maxMid = Math.Max(maxMid, mid); srs.Points.AddXY((sec - currSec) / 86400.0, mid); } this.MChart.Series.Add(srs); ChartArea ca = new ChartArea(); { double METER_SCALE = 1000.0; minMid = (long)(minMid * METER_SCALE) / METER_SCALE; maxMid = ((long)(maxMid * METER_SCALE) + 1) / METER_SCALE; } ca.AxisX.Minimum = -7.0; ca.AxisX.Maximum = 0.0; ca.AxisX.Interval = 1.0; ca.AxisY.Minimum = minMid; ca.AxisY.Maximum = maxMid; //ca.BorderWidth = 0; this.MChart.ChartAreas.Add(ca); //this.MChart.Margin = new Padding(0); //this.MChart.BorderlineDashStyle = ChartDashStyle.NotSet; //this.MChart.BorderlineWidth = 0; this.Text = Program.APP_TITLE + " - " + cPair.Code; }
private void Slim() { long currDateTime = DateTimeToSec.Now.GetDateTime(); long expireDateTime = DateTimeToSec.ToDateTime(DateTimeToSec.ToSec(currDateTime) - Consts.SESSION_TIMEOUT_SEC); ProcMain.WriteLog("SessionBundle.Slim()"); ProcMain.WriteLog("現在日時 ⇒ " + currDateTime); ProcMain.WriteLog("期限切れ ⇒ " + expireDateTime); this.Sessions.RemoveAll(v => v.LastAccessedDateTime < expireDateTime); }
public static void CheckDateTime(long dateTime) { if (dateTime < CSConsts.DATE_TIME_MIN || CSConsts.DATE_TIME_MAX < dateTime) { throw new Exception("Out of range dateTime: " + dateTime); } if (DateTimeToSec.ToDateTime(DateTimeToSec.ToSec(dateTime)) != dateTime) { throw new Exception("Bad dateTime: " + dateTime); } }
private void WeSetDebugWin_Load(object sender, EventArgs e) { List <string> dest = new List <string>(); // ---- long sec = DateTimeToSec.toSec(20170529070000L); // 月曜日の7:00 == 取引開始 dest.Add("" + (sec % (86400L * 7))); // ---- lblOutput.Text = string.Join("\r\n", dest); }
private static void DeleteDeadData() { FileData[] files = Directory.GetFiles(Consts.DATA_DIR).Select(v => new FileData() { File = v, WroteDateTime = DateTimeToSec.ToDateTime(new FileInfo(v).LastWriteTime), }) .ToArray(); Array.Sort(files, (a, b) => { int ret = LongTools.Comp(a.WroteDateTime, b.WroteDateTime); if (ret != 0) { return(ret); } ret = StringTools.CompIgnoreCase(a.File, b.File); return(ret); }); long currDateTime = DateTimeToSec.Now.GetDateTime(); long expireDateTime = DateTimeToSec.ToDateTime(DateTimeToSec.ToSec(currDateTime) - Consts.DATA_LIFESPAN_SEC); for (int index = 0; index < files.Length; index++) { bool deleting = index + Consts.DATA_NUM_MAX < files.Length || files[index].WroteDateTime < expireDateTime; if (deleting == false) { break; } FileTools.Delete(files[index].File); } }
public CSPrice GetPrice(long dateTime) { Validators.CheckDateTime(dateTime); int day = DateToDay.ToDay((int)(dateTime / 1000000)); SortedList <CSPrice> prices = GetDayPrices(day); CSPrice[] matched = prices.GetMatchWithEdge(prices.GetFerret(new CSPrice() { DateTime = dateTime })).ToArray(); if (matched.Length == 3) { return(matched[1]); } if (matched.Length != 2) { throw null; // 2bs -- 同じ日時のデータは無いはず! } if (matched[0] == null) { for (int c = 1; c <= Consts.MARGIN_DAY_MAX; c++) { prices = GetDayPrices(day - c); if (1 <= prices.Count) { matched[0] = prices.Get(prices.Count - 1); break; } } } if (matched[1] == null) { for (int c = 1; c <= Consts.MARGIN_DAY_MAX; c++) { prices = GetDayPrices(day + c); if (1 <= prices.Count) { matched[0] = prices.Get(0); break; } } } matched = matched.Where(v => v != null).ToArray(); if (matched.Length == 0) { return new CSPrice() { DateTime = dateTime } } ; if (matched.Length == 1) { return(matched[0]); } long sec1 = DateTimeToSec.ToSec(matched[0].DateTime); long sec2 = DateTimeToSec.ToSec(dateTime); long sec3 = DateTimeToSec.ToSec(matched[1].DateTime); double rate = (sec2 - sec1) * 1.0 / (sec3 - sec1); return(new CSPrice() { DateTime = dateTime, Hig = matched[0].Hig + rate * (matched[1].Hig - matched[0].Hig), Low = matched[0].Low + rate * (matched[1].Low - matched[0].Low), Ask = matched[0].Ask + rate * (matched[1].Ask - matched[0].Ask), Bid = matched[0].Bid + rate * (matched[1].Bid - matched[0].Bid), }); } }
public void Perform() { Console.WriteLine("Slimdown_Start"); //Console.WriteLine("Slimdown_Start, DY: " + this.DiskYellowFlag); // del @ 2020.4.1 long currDateTime = DateTimeToSec.Now.GetDateTime(); foreach (LiteGroup liteGroup in new GroupBundle().LiteGroups) { Group group = liteGroup.GetGroup(); List <UploadedFile> upFiles = new List <UploadedFile>(); long total = 0L; foreach (string file in group.GetFileBundle().Files) { FileInfo info = new FileInfo(file); UploadedFile upFile = new UploadedFile() { FilePath = file, Size = info.Length, WroteDateTime = DateTimeToSec.ToDateTime(info.LastWriteTime), }; upFiles.Add(upFile); total += upFile.Size; } upFiles.Sort((a, b) => { int ret = VariantTools.Comp(a, b, v => StringTools.EndsWithIgnoreCase(v.FilePath, Consts.TMP_FILE_SUFFIX) && DateTimeToSec.ToSec(v.WroteDateTime) + 3600 <= DateTimeToSec.ToSec(currDateTime) ? 0 : 1); // "1時間以上放置された作業ファイル" を先に if (ret != 0) { return(ret); } ret = LongTools.Comp(a.WroteDateTime, b.WroteDateTime); // 古い順 return(ret); }); while (1 <= upFiles.Count && (Consts.FILE_NUM_MAX < this.UploadedFiles.Count || group.GroupTotalFileSizeMax < total)) { UploadedFile upFile = upFiles[0]; upFiles.RemoveAt(0); upFile.Delete(); total -= upFile.Size; } this.UploadedFiles.AddRange(upFiles); this.TotalSize += total; } this.UploadedFiles.Sort((a, b) => LongTools.Comp(a.WroteDateTime, b.WroteDateTime)); // 古い順 while (1 <= this.UploadedFiles.Count && Consts.TOTAL_FILE_SIZE_MAX < this.TotalSize) { UploadedFile upFile = this.UploadedFiles[0]; this.UploadedFiles.RemoveAt(0); FileTools.Delete(upFile.FilePath); this.TotalSize -= upFile.Size; } #if false // del @ 2020.4.1 if (this.DiskYellowFlag) { int count = this.UploadedFiles.Count; // 10ファイル以上 -> 10% // 1~9ファイル -> 1 // 0ファイル -> 0 // if (10 <= count) { count /= 10; } else { count = Math.Min(1, count); } for (int index = 0; index < count; index++) { UploadedFile upFile = this.UploadedFiles[index]; upFile.Delete(); } } #endif Console.WriteLine("Slimdown_End"); }
public static bool IsFairDateTime(long dt) { return(DateTimeToSec.ToDateTime(DateTimeToSec.ToSec(dt)) == dt); }
private void executeArgs(bool keepAxY = false) { string args = this.Args.Text; try { args = StringTools.tokenize(args, "#")[0]; // ---- args -> vars ---- Queue <string> argq = new Queue <string>(StringTools.tokenize(args, ":")); CurrencyPair cPair = CurrencyPairs.All[CurrencyPairs.IndexOf(argq.Dequeue())]; long dateTime = long.Parse(argq.Dequeue()); if (DateTimeToSec.isFairDateTime(dateTime) == false) { throw new Exception("Bad dateTime"); } long secStart = DateTimeToSec.toSec(dateTime); long secInterval = StringToSec(argq.Dequeue()); long secBound = StringToSec(argq.Dequeue()); string sVisHigLow = argq.Dequeue(); long secMvAvgInterval = -1L; if (1 <= argq.Count) // 省略可能につき { secMvAvgInterval = StringToSec(argq.Dequeue()); } List <long> secMvAvgs = new List <long>(); while (1 <= argq.Count) // 省略可能につき { secMvAvgs.Add(StringToSec(argq.Dequeue())); } argq = null; if (secInterval < 1L) { throw new Exception("interval < 1"); } if (secBound < secInterval) { throw new Exception("bound < interval"); } if (secBound % secInterval != 0) { throw new Exception("期間はインターバルの倍数にしてね!"); } if (Consts.SAMPLING_MAX < secBound / secInterval) { throw new Exception("インターバル刻みすぎ!"); } if (Consts.SEC_BOUND_MAX < secBound) { throw new Exception("期間長過ぎ!"); } bool visHigLow; switch (sVisHigLow) { case "T": visHigLow = true; break; case "F": visHigLow = false; break; default: throw new Exception("Bad sVisHigLow: " + sVisHigLow); } //secBound /= secInterval; //secBound *= secInterval; // secMvAvgInterval ここでチェックしない。MovingAverage ctor に任せる。 // ---- //CurrencyPairs.FxCollect(); this.MChart.Series.Clear(); //this.MChart.Legends.Clear(); this.MChart.ChartAreas.Clear(); // ここから sec -> weSec に切り替えていく。 secStart = WeSec.SecToWeSec(secStart); double minMid = double.MaxValue; double maxMid = double.MinValue; WeSecPrices wsp = new WeSecPrices(cPair); List <MovingAverage> mvAvgs = new List <MovingAverage>(); foreach (long secMvAvg in secMvAvgs) { mvAvgs.Add(new MovingAverage(wsp, secMvAvgInterval, secMvAvg)); } if (visHigLow) { // 高値 { Series srs = new Series(); srs.ChartType = SeriesChartType.Line; srs.Color = Color.LightGray; for (long sec = 0; sec <= secBound; sec += secInterval) { double hig = wsp.GetPrice(secStart - sec).High; minMid = Math.Min(minMid, hig); maxMid = Math.Max(maxMid, hig); srs.Points.AddXY(-sec / 86400.0, hig); } this.MChart.Series.Add(srs); } // 安値 { Series srs = new Series(); srs.ChartType = SeriesChartType.Line; srs.Color = Color.Gray; for (long sec = 0; sec <= secBound; sec += secInterval) { double low = wsp.GetPrice(secStart - sec).Low; minMid = Math.Min(minMid, low); maxMid = Math.Max(maxMid, low); srs.Points.AddXY(-sec / 86400.0, low); } this.MChart.Series.Add(srs); } } // Mid { Series srs = new Series(); srs.ChartType = SeriesChartType.Line; srs.Color = Color.Green; for (long sec = 0; sec <= secBound; sec += secInterval) { double mid = wsp.GetPrice(secStart - sec).Mid; //double mid = cPair.GetPrice(DateTimeToSec.toDateTime(secStart - sec)).Mid; minMid = Math.Min(minMid, mid); maxMid = Math.Max(maxMid, mid); srs.Points.AddXY(-sec / 86400.0, mid); } this.MChart.Series.Add(srs); } Color[] MVAVG_COLORS = new Color[] { Color.Red, Color.Blue, Color.Purple, Color.DarkCyan, Color.DarkOrange, Color.DarkGray, }; for (int index = 0; index < mvAvgs.Count; index++) { MovingAverage mvAvg = mvAvgs[index]; Series srs = new Series(); srs.ChartType = SeriesChartType.Line; srs.Color = MVAVG_COLORS[index % MVAVG_COLORS.Length]; for (long sec = 0; ; sec += secMvAvgInterval) { double mid = mvAvg.GetMid(secStart - sec); //double mid = cPair.GetPrice(DateTimeToSec.toDateTime(secStart - sec)).Mid; minMid = Math.Min(minMid, mid); maxMid = Math.Max(maxMid, mid); srs.Points.AddXY(-sec / 86400.0, mid); if (secBound <= sec) { break; } } this.MChart.Series.Add(srs); } if (keepAxY) { minMid = LastAxYMin; maxMid = LastAxYMax; } else { LastAxYMin = minMid; LastAxYMax = maxMid; } LastStartWeSec = secStart; ChartArea ca = new ChartArea(); { double METER_SCALE = 1000.0; minMid = (long)(minMid * METER_SCALE) / METER_SCALE; maxMid = ((long)(maxMid * METER_SCALE) + 1) / METER_SCALE; } double axInterval; if (secBound < 86400L) { axInterval = 1.0 / 24.0; } else if (secBound < 86400L * 3) { axInterval = 1.0 / 2.0; } else if (secBound < 86400L * 25) { axInterval = 1.0; } else if (secBound < 86400L * 100) { axInterval = 5.0; } else if (secBound < 86400L * 250) { axInterval = 25.0; } else if (secBound < 86400L * 500) { axInterval = 50.0; } else { axInterval = 100.0; } ca.AxisX.Minimum = -secBound / 86400.0; ca.AxisX.Maximum = 0.0; ca.AxisX.Interval = axInterval; ca.AxisY.Minimum = minMid; ca.AxisY.Maximum = maxMid; this.MChart.ChartAreas.Add(ca); // ---- // 成功 this.Args.ForeColor = Color.Black; this.Args.Text = args; this.Args.SelectAll(); } catch (Exception e) { // 失敗 this.TTip.SetToolTip(this.Args, "" + e); this.Args.ForeColor = Color.Red; this.Args.Text = args + "#" + e.Message; this.Args.SelectionStart = 0; this.Args.SelectionLength = args.Length; } GC.Collect(); // 2bs }
public static long DateTimeToWeSec(long dateTime) { return(SecToWeSec(DateTimeToSec.toSec(dateTime))); }
private void DoAltCommand(string command, bool keepAxY = false) { try { string args = this.Args.Text; List <string> tokens = StringTools.tokenize(args, ":"); long dateTime = long.Parse(tokens[1]); long sec = DateTimeToSec.toSec(dateTime); long weSec = WeSec.SecToWeSec(sec); switch (command) { case "戻る": { long secBound = this.StringToSec(tokens[3]); weSec -= secBound / 4; } break; case "進む": { long secBound = this.StringToSec(tokens[3]); weSec += secBound / 4; } break; case "Y-拡大": { expandAxY(1.0 / 1.5); keepAxY = true; } break; case "Y-縮小": { expandAxY(1.5); keepAxY = true; } break; case "拡大": { long secInterval = this.StringToSec(tokens[2]); long secBound = this.StringToSec(tokens[3]); secInterval /= 2; secBound /= 2; // 調整 TODO { if (secBound % secInterval != 0) { secBound /= secInterval; secBound *= secInterval; } } tokens[2] = this.SecToString(secInterval); tokens[3] = this.SecToString(secBound); } break; case "縮小": { long secInterval = this.StringToSec(tokens[2]); long secBound = this.StringToSec(tokens[3]); secInterval *= 2; secBound *= 2; tokens[2] = this.SecToString(secInterval); tokens[3] = this.SecToString(secBound); } break; default: throw null; } sec = WeSec.WeSecToSec(weSec); dateTime = DateTimeToSec.toDateTime(sec); tokens[1] = "" + dateTime; args = string.Join(":", tokens); this.Args.Text = args; executeArgs(keepAxY); } catch { } }
public static long WeSecToDateTime(long weSec) { return(DateTimeToSec.toDateTime(WeSecToSec(weSec))); }
public static long TTSecToDateTime(long ttSec) { return(DateTimeToSec.ToDateTime(TTSecToDTSec(ttSec))); }
public static long DateTimeToTTSec(long dateTime) { return(DTSecToTTSec(DateTimeToSec.ToSec(dateTime))); }