private void DataForward_OnTick(object sender, IForwardOnTickArgument argument) { double time = argument.Time; //if (time < 20170601.205900) // return; int tradingDay = argument.TickInfo.TickData.TradingDay; if (prevTime == time) { return; } this.prevTime = time; ITickData_Extend tickData = GetTickData(tradingDay); //Console.WriteLine(tickData); RealTimeDataPackageTimeChangeUtils.ChangeTime_TickData(tickData, time); Assert.AreEqual(argument.TickInfo.TickBar.ToString(), tickData.ToString()); IRealTimeDataReader_Code realTimeData = ((IRealTimeDataReader_Code)sender); RealTimeDataPackageTimeChangeUtils.ChangeTime_KLineData(klineData_1Minute, tradingDay, time, tickData); Assert.AreEqual(realTimeData.GetKLineData(KLinePeriod.KLinePeriod_1Minute).ToString(), klineData_1Minute.ToString()); RealTimeDataPackageTimeChangeUtils.ChangeTime_KLineData(klineData_5Minute, tradingDay, time, tickData); Assert.AreEqual(realTimeData.GetKLineData(KLinePeriod.KLinePeriod_5Minute).ToString(), klineData_5Minute.ToString()); RealTimeDataPackageTimeChangeUtils.ChangeTime_KLineData(klineData_15Minute, tradingDay, time, tickData); Assert.AreEqual(realTimeData.GetKLineData(KLinePeriod.KLinePeriod_15Minute).ToString(), klineData_15Minute.ToString()); RealTimeDataPackageTimeChangeUtils.ChangeTime_KLineData(klineData_1Day, tradingDay, time, tickData); Assert.AreEqual(realTimeData.GetKLineData(KLinePeriod.KLinePeriod_1Day).ToString(), klineData_1Day.ToString()); ITimeLineData_RealTime timeLineData = GetTimeLineData(tradingDay); RealTimeDataPackageTimeChangeUtils.ChangeTime_TimeLineData(timeLineData, time, tickData); Assert.AreEqual(realTimeData.GetTimeLineData().ToString(), timeLineData.ToString()); }
private void ForwardToday_KLineData(IKLineData_RealTime klineData, KLinePeriod period) { ITickData_Extend currentTickData = forwardData.CurrentTickData; ITickBar nextTickBar = currentTickData.GetBar(currentTickData.BarPos + 1); //日线,肯定不会跳到下一个bar if (period.Equals(KLinePeriod.KLinePeriod_1Day)) { dic_KLinePeriod_IsEnd[period] = false; klineData.ChangeCurrentBar(GetKLineBar(klineData, nextTickBar)); return; } double nextTickTime = nextTickBar.Time; int nextKLineIndex = FindNextKLineIndex(klineData, nextTickTime); if (nextKLineIndex == klineData.BarPos) { dic_KLinePeriod_IsEnd[period] = false; klineData.ChangeCurrentBar(GetKLineBar(klineData, nextTickBar)); } else { dic_KLinePeriod_IsEnd[period] = true; klineData.ChangeCurrentBar(GetKLineBar(nextTickBar), nextKLineIndex); } }
private void ForwardToday_TimeLineData(ITimeLineData_RealTime timeLineData) { if (timeLineData == null) { return; } ITickData_Extend currentTickData = forwardData.CurrentTickData; ITickBar nextTickBar = currentTickData.GetBar(currentTickData.BarPos + 1); int nextTimeLineBarPos = timeLineData.BarPos + 1; if (nextTimeLineBarPos >= timeLineData.Length) { TimeLineBar timeLineBar = GetTimeLineBar(timeLineData, nextTickBar, timeLineData.YesterdayEnd); timeLineData.ChangeCurrentBar(timeLineBar, timeLineData.BarPos); return; } else { double nextTime = timeLineData.Arr_Time[nextTimeLineBarPos]; TimeLineBar timeLineBar; if (nextTickBar.Time >= nextTime) { timeLineBar = GetTimeLineBar(nextTickBar, timeLineData.YesterdayEnd); timeLineData.ChangeCurrentBar(timeLineBar, nextTimeLineBarPos); } else { timeLineBar = GetTimeLineBar(timeLineData, nextTickBar, timeLineData.YesterdayEnd); timeLineData.ChangeCurrentBar(timeLineBar, timeLineData.BarPos); } } }
private void ForwardToday() { int prevMainBarPos = mainKlineData.BarPos; foreach (KLinePeriod period in forwardData.ReferedKLinePeriods) { IKLineData_RealTime klineData = forwardData.GetKLineData(period); ForwardToday_KLineData(klineData, period); } ForwardToday_TimeLineData(forwardData.CurrentTimeLineData); ITickData_Extend currentTickData = forwardData.CurrentTickData; currentTickData.BarPos++; if (currentTickData.IsTradingTimeEnd(currentTickData.BarPos)) { this.isTradingTimeEnd = true; } else { this.isTradingTimeEnd = false; } if (currentTickData.IsTradingTimeStart(currentTickData.BarPos)) { this.isTradingTimeStart = true; } else { this.isTradingTimeStart = false; } }
private bool ForwardToday_MainKLineData() { ITickData_Extend currentTickData = forwardData.CurrentTickData; ITickBar nextTickBar = currentTickData.GetBar(currentTickData.BarPos + 1); double nextTickTime = nextTickBar.Time; IKLineData_RealTime klineData = forwardData.GetMainKLineData(); if (dic_KLinePeriod_IsEnd[forwardData.MainKLinePeriod]) { dic_KLinePeriod_IsEnd[forwardData.MainKLinePeriod] = false; } else { int nextKLineIndex = FindNextKLineIndex(klineData, nextTickTime); } //if (nextKLineIndex == klineData.BarPos) //{ // dic_KLinePeriod_IsEnd[period] = false; // klineData.ChangeCurrentBar(GetKLineBar(klineData, nextTickBar)); //} //else //{ // dic_KLinePeriod_IsEnd[period] = true; // klineData.ChangeCurrentBar(GetKLineBar(nextTickBar), nextKLineIndex); //} return(false); }
private void InitData() { int currentTradingDay = tradingDays[0]; this.currentTickData = dataPackage.GetTickData(currentTradingDay); foreach (KLinePeriod period in dic_Period_KLineData.Keys) { IKLineData_RealTime klineData = dic_Period_KLineData[period]; klineData.ChangeCurrentBar(GetKLineBar(currentTickData)); if (period == forwardPeriod.KlineForwardPeriod) { mainKlineData = klineData; } } //初始化分时线 //int lastTradingDay = dataReader.TradingDayReader.GetPrevTradingDay(currentTradingDay); //IKLineData lastDayklineData = dataReader.KLineDataReader.GetData(code, lastTradingDay, lastTradingDay, KLinePeriod.KLinePeriod_1Day); //if (lastDayklineData.Length == 0) // lastEndPrice = currentTickData.Arr_Price[0]; //else // lastEndPrice = lastDayklineData.End; this.lastEndPrice = dataPackage.GetLastEndPrice(currentTradingDay); if (useTimeLineData) { ITimeLineData timeLineData = dataPackage.GetTimeLineData(currentTradingDay); if (timeLineData != null) { this.currentTimeLineData = new TimeLineData_RealTime(timeLineData); this.currentTimeLineData.ChangeCurrentBar(GetTimeLineBar(currentTickData, lastEndPrice)); } } }
public ForwardDataIndeier(DataForForward_Code dataForForward) { this.dataForForward = dataForForward; if (this.dataForForward.ReferedKLinePeriods.Count > 1) { List <IKLineData_Extend> indexKLines = new List <IKLineData_Extend>(); for (int i = 0; i < this.dataForForward.ReferedKLinePeriods.Count; i++) { KLinePeriod klinePeriod = this.dataForForward.ReferedKLinePeriods[i]; if (this.dataForForward.MainKLinePeriod == klinePeriod) { continue; } indexKLines.Add(this.dataForForward.GetKLineData(klinePeriod)); } this.klineToKlineIndeier = new KLineToKLineIndeier(dataForForward.MainKLine, indexKLines); } if (this.dataForForward.UseTickData) { int tradingDay = dataForForward.TradingDay; ITickData_Extend tickData = this.dataForForward.CurrentTickData; this.klineToTickIndeier = new KLineToTickIndeier(tickData, dataForForward.MainKLine); } if (this.dataForForward.UseTimeLineData) { int tradingDay = dataForForward.TradingDay; ITimeLineData_Extend timeLineData = this.dataForForward.CurrentTimeLineData; this.timeToKLineIndeier = new TimeLineToKLineIndeier(dataForForward.MainKLine, timeLineData); } }
private int Forward(DataForForward_Code dataForForward, ForwardDataIndeier indeier, int tradingDay, int klineIndex, List <string> list_OnBar) { IKLineData_Extend klineData = dataForForward.GetMainKLineData(); ITickData_Extend tickData = dataForForward.CurrentTickData; int lastMainKLineBarPos; int mainBarPos = 0; KLinePeriod mainPeriod = dataForForward.MainKLinePeriod; for (int i = 0; i < tickData.Length; i++) { tickData.BarPos = i; Console.WriteLine("tick:" + tickData); list_OnBar.Add("tick:" + tickData); mainBarPos = indeier.GetMainKLineBarPosIfFinished(i, out lastMainKLineBarPos); if (mainBarPos < 0) { continue; } PrintData(dataForForward, indeier, klineData, mainBarPos, mainPeriod, list_OnBar); if (lastMainKLineBarPos >= 0 && lastMainKLineBarPos != mainBarPos) { for (int m = mainBarPos + 1; m <= lastMainKLineBarPos; m++) { PrintData(dataForForward, indeier, klineData, m, mainPeriod, list_OnBar); } } } return(mainBarPos); }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { ITickData_Extend currentTickData = forwardData.CurrentTickData; bool canForward = true; if (currentTickData == null) { this.Pause(); return; } int barPos = currentTickData.BarPos; int nextBarPos = barPos + 1; if (nextBarPos >= currentTickData.Length) { canForward = this.Forward(); } else { mileSecondCount++; if (mileSecondCount == 4) { forwardTime = TimeUtils.AddSeconds(forwardTime, 1); mileSecondCount = 0; } if (forwardTime >= currentTickData.Arr_Time[nextBarPos]) { canForward = this.Forward(); } } if (!canForward) { this.Pause(); } }
private ITickData_Extend GetTickData(int date) { if (tickData == null || tickData.TradingDay != date) { tickData = DataCenter.Default.DataReader.TickDataReader.GetTickData_Extend(code, date); } return(tickData); }
/// <summary> /// 得到今日的TICK数据 /// </summary> /// <returns></returns> public ITickData_Extend GetTickData() { if (currentTickData == null || currentTickData.TradingDay != tradingDay) { currentTickData = dataPackage.GetTickData(tradingDay); } DataNavigate_ChangeTime.ChangeTime_TickData(currentTickData, time); return(currentTickData); }
public ITickData_Extend GetTickData() { if (currentTickData == null || currentTickData.TradingDay != tradingDay) { currentTickData = dataPackage_Code.GetTickData(tradingDay); } RealTimeDataPackageTimeChangeUtils.ChangeTime_TickData(currentTickData, time); return(currentTickData); }
public static void ChangeTime_TickData(ITickData_Extend tickData, double time) { if (tickData.Time == time) { return; } int index = TimeIndeierUtils.IndexOfTime_Tick(tickData, time, true); tickData.BarPos = index < 0 ? 0 : index; }
private static int GetStartTickIndex(ITimeLineData_RealTime timeLineData, ITickData_Extend tickData, int timeLineIndex) { double klineTime = timeLineData.BarPos == timeLineIndex?timeLineData.GetCurrentBar_Original().Time : timeLineData.Arr_Time[timeLineIndex]; int startTickIndex; startTickIndex = TimeIndeierUtils.IndexOfTime_Tick(tickData, klineTime, true); if (timeLineData.IsTradingTimeStart(timeLineIndex)) { while (!tickData.IsTradingTimeStart(startTickIndex)) { startTickIndex--; } } return(startTickIndex); }
public void ForwardToday() { ITickData_Extend tickData = this.dataForForward.CurrentTickData; int lastMainKLineBarPos = -1; int mainKLineBarPos = forwardDataIndeier.GetMainKLineBarPosIfFinished(tickData.BarPos, out lastMainKLineBarPos); //小于0,则表示这个K线bar没有结束 if (mainKLineBarPos < 0) { ForwardCurrentBar(); } else { ForwardNextBar(lastMainKLineBarPos); } }
private bool ForwardNextDay() { ITickData_Extend tickData = ForwardTickData(); if (tickData == null) { isEnd = true; return(false); } this.lastEndPrice = currentTickData.Arr_Price[currentTickData.Length - 1]; this.currentTickData = tickData; foreach (KLinePeriod period in dic_Period_KLineData.Keys) { IKLineData_RealTime klineData = dic_Period_KLineData[period]; ForwardNextDay_KLine(klineData, period); } ForwardNextDay_TimeLine(); return(true); }
public void ChangeTime(double time) { if (this.time == time) { return; } this.time = time; int date = this.sessionReader.GetTradingDay(time); if (date < 0) { date = this.sessionReader.GetRecentTradingDay(time); } if (this.date != date) { this.date = date; this.tickData = dataPackage.GetTickData(date); } int index = TimeIndeierUtils.IndexOfTime_Tick(tickData, time, true); tickData.BarPos = index < 0 ? 0 : index; }
private static int GetStartTickIndex(IKLineData_RealTime klineData_RealTime, ITickData_Extend tickData, KLinePeriod klinePeriod, int klineIndex) { int startTickIndex; if (klinePeriod.PeriodType == KLineTimeType.DAY) { startTickIndex = 0; } else { double klineTime = klineData_RealTime.BarPos == klineIndex?klineData_RealTime.GetCurrentBar_Original().Time : klineData_RealTime.Arr_Time[klineIndex]; startTickIndex = TimeIndeierUtils.IndexOfTime_Tick(tickData, klineTime, true); if (klineData_RealTime.IsTradingTimeStart(klineIndex)) { while (!tickData.IsTradingTimeStart(startTickIndex)) { startTickIndex--; } } } return(startTickIndex); }
public ForwardTickInfo(ITickData_Extend tickData, int index) { this.index = index; this.tickData = tickData; }
private static bool IsPeriodEnd(IKLineData_RealTime klineData_RealTime, int klineIndex, ITickData_Extend tickData, int tickIndex) { if (tickIndex == tickData.Length - 1) { return(true); } double tickTime = tickData.Time; double nextTickTime = tickData.Arr_Time[tickIndex + 1]; if (klineIndex >= klineData_RealTime.Length - 1) { return(false); } double klineTime = klineData_RealTime.Arr_Time[klineIndex + 1]; return(tickTime < klineTime && nextTickTime >= klineTime); }
public static void ChangeTime_KLineData(IKLineData_RealTime klineData_RealTime, int date, double time, ITickData_Extend tickData) { KLinePeriod klinePeriod = klineData_RealTime.Period; int klineIndex = IndexOfTime(klineData_RealTime, klinePeriod, time, date); //if(tickData.TradingDay !=date) // tickData = int tickIndex = TimeIndeierUtils.IndexOfTime_Tick(tickData, time, true); if (IsPeriodEnd(klineData_RealTime, klineIndex, tickData, tickIndex)) { klineData_RealTime.BarPos = klineIndex; klineData_RealTime.ResetCurrentBar(); return; } int startTickIndex = GetStartTickIndex(klineData_RealTime, tickData, klinePeriod, klineIndex); KLineBar klineBar = GetKLineBar(tickData, startTickIndex, tickIndex); klineData_RealTime.ChangeCurrentBar(klineBar, klineIndex); }
public static void ChangeTime_TimeLineData(ITimeLineData_RealTime timeLineData, double time, ITickData_Extend tickData) { //if (timeLineData.Time == time) // return; int timeLineIndex = GetTimeLineIndex(timeLineData, time); int tickIndex = TimeIndeierUtils.IndexOfTime_Tick(tickData, time); double klineTime = timeLineData.Arr_Time[timeLineIndex]; int startTickIndex = GetStartTickIndex(timeLineData, tickData, timeLineIndex); TimeLineBar klineBar = GetTimeLineBar(tickData, startTickIndex, tickIndex, timeLineData.YesterdayEnd); timeLineData.ChangeCurrentBar(klineBar, timeLineIndex); }
public ForwardOnTickArgument(ITickData_Extend tickData, int index, IDataForward_Code dataForward_Code) { this.tickInfo = new ForwardTickInfo(tickData, index); this.dataForward_Code = dataForward_Code; }
private void ForwardTickData() { ITickData_Extend tickData = dataForForward_Code.CurrentTickData; tickData.BarPos += 1; }
public TickData_RealTime(ITickData_Extend tickData) { this.tickData = tickData; }
public StrategyOnTickInfo(ITickData_Extend tickData, int index) : base(tickData, index) { }
public StrategyOnTickArgument(ITickData_Extend tickData, int index, IDataForward_Code dataForward_Code) : base(tickData, index, dataForward_Code) { this.onTickInfo = new StrategyOnTickInfo(tickData, index); }