void CreateOhlc(int cid, OhlcType ot) { ohlc = new Ohlc(GetPreBoundForTime(ot, DateTime.Now), ohlc == null ? 0 : ohlc.Close, ohlc == null ? 0 : ohlc.Close, ohlc == null ? 0 : ohlc.Close, ohlc == null ? 0 : ohlc.Close, 0); ohlc.OhlcType = ot; ohlc.WhatId = cid; }
/// <summary> /// 获取时间所在区间的上限:比如5分钟线,现在是7分,则返回5分时的时间 /// </summary> /// <param name="ot">ohlc类型,值是区间值,如5分钟线的5分钟</param> /// <param name="dtn"></param> /// <returns></returns> public DateTime GetPreBoundForTime(OhlcType ot, DateTime dtn) { DateTime dtr; var m = (int)dtn.Subtract(dtn.Date).TotalMinutes % (int)ot; var t = dtn.AddMinutes(m * (-1)); dtr = dtn.Date.AddHours(t.Hour).AddMinutes(t.Minute); return(dtr); }
public List <double> GetCurrent(int whatId, OhlcType type) { if (!dic.ContainsKey(whatId)) { return(null); } var d = dic[whatId][type].ohlc; return(d.List); }
public OhlcMaker(int cid, OhlcType ot) { IntervalInMin = (int)ot; CreateOhlc(cid, ot); isTimerFirstExecute = true; t = new Timer(); //首次启动时先找到最近的界限 t.Interval = ohlc.WhenInDt.AddMinutes(IntervalInMin).Subtract(DateTime.Now).TotalMilliseconds; t.Elapsed += t_Elapsed; t.Start(); }
public List <double> GetLatestKline(string code, OhlcType type) { var c = Model.Contracts.Where(a => a.Code == code).FirstOrDefault(); if (c == null) { return(new List <double>()); } var r = ohlcGen.GetCurrent(c.Id, type); return(r); }
public Ohlc GetLastByType(OhlcType ot) { if (!dic.ContainsKey(ot)) { return(null); } var l = dic[ot]; if (l.Count > 0) { return(l[l.Count - 1]); } else { return(null); } }
public Ohlc GetLastByType(OhlcType ot) { return(null); }
public List <double> GetLatestKline(OhlcType type = OhlcType.M5) { var r = ohlcGen.GetCurrent(-2, type); return(r); }