internal SeriesSymbolData(InstrumentDataRequest dataRequest, InstrumentSettings settings = null) { this.Id = 0x40000000 | System.Threading.Interlocked.Increment(ref __iLastSeriesId); this.Indexer = new SeriesIndexer(); __cDataRequest = dataRequest; __cSettings = ((settings == null) ? new InstrumentSettings(ref __cDataRequest) : settings.Create(ref __cDataRequest)); __cUpdateTime = DateTime.UtcNow.AddHours(__cSettings.TimeZone); SessionObject cSession = __cSettings.GetSessionFromToday(); __iRealtimeCount = (cSession == null) ? 1 : (int) ((cSession.GetCloseTimeForDaylight() - cSession.GetStartTimeForDaylight()).TotalSeconds / dataRequest.Resolution.TotalSeconds + 1); Indexer.HistoryIndex = 0; Indexer.RealtimeIndex = -1; __cOpens = new Series<double>(__iRealtimeCount); __cOpens.onRequest += Series_onRequest; __cHighs = new Series<double>(__iRealtimeCount); __cHighs.onRequest += Series_onRequest; __cLows = new Series<double>(__iRealtimeCount); __cLows.onRequest += Series_onRequest; __cCloses = new Series<double>(__iRealtimeCount); __cCloses.onRequest += Series_onRequest; __cTimes = new Series<DateTime>(__iRealtimeCount); __cTimes.onRequest += Series_onRequest; __cVolumes = new Series<double>(__iRealtimeCount); __cVolumes.onRequest += Series_onRequest; __cDataRequest.Range.Count = 0; //將資料筆數設定為0(因為一開始沒有請求任何資訊) }
/// <summary> /// 根據設定資訊調整 InstrumentDataRequest 設定並回傳目前的設定類別 /// </summary> /// <param name="request">InstrumentDataRequest類別</param> /// <returns>回傳值: 目前的 InstrumentSettings類別</returns> public InstrumentSettings Create(ref InstrumentDataRequest request) { SessionObject cSession = GetSessionFromToday(); DataRequestType cRequestType = request.Range.RequestType; request.Resolution.CalculateRate(cSession.GetStartTimeForDaylight(), cSession.GetCloseTimeForDaylight(), __cProperty.Sessions.Count); if (cRequestType == DataRequestType.DaysBack || cRequestType == DataRequestType.FromTo) { request.Range.Count = request.Resolution.ConvertDaysToBars(request.Range.Count); } return this; }
private Queue<DateTime> CreateRealtimePeriods() { DateTime cToday = DateTime.UtcNow.AddHours(__cSettings.TimeZone); string sDataSource = __cDataRequest.DataFeed; AbstractQuoteService cService = QuoteManager.Manager.GetQuoteService(sDataSource); if (cService != null) { cToday = cService.TradeDate; } //從新計算今日的起始時間與結束時間的周期(有些商品不是每天的開收盤都一樣) SessionObject cSession = __cSettings.GetSessionFromToday(); __cDataRequest.Resolution.CalculateRate(cSession.GetStartTimeForDaylight(), cSession.GetCloseTimeForDaylight(), __cSettings.Sessions.Count); //從新計算結算日期 __cSettings.SetExpirationFromTime(cToday); __cTimeQueue = __cDataRequest.Resolution.CalculateRealtimePeriods((this.LastBarTime == DateTime.MinValue) ? cToday : this.LastBarTime, cToday, __cSettings.Expiration); return __cTimeQueue; }