예제 #1
0
        /* 对交易时间进行排序,结果为:夜盘->白盘
         * 21:0:0 - 23:0:0
         * 24:0:0 - 2:0:0
         * 09:0:0 - 10:15:0
         * 10:30:0 - 11:30:0
         * 13:30:0 - 15:00:0
         */
        public List <TimeSliceEx> SortInstrumentTradingTime(string instrumentID)
        {
            List <TimeSlice>   slices = GetInstrumentTradingTime(instrumentID);
            List <TimeSliceEx> tse    = TimeSliceEx.CreateSlices(slices, DayTradeBegin, DayTradeEnd);

            tse.Sort(new TimeSliceComparer());
            return(tse);
        }
예제 #2
0
        public static List <TimeSliceEx> CreateSlices(List <TimeSlice> slices)
        {
            List <TimeSliceEx> tse = new List <TimeSliceEx>();

            foreach (TimeSlice s in slices)
            {
                TimeSliceEx se = new TimeSliceEx(s);
                tse.Add(se);
            }

            return(tse);
        }
예제 #3
0
        public static List <TimeSliceEx> CreateSlices(List <TimeSlice> slices, int dayTradeBegin, int dayTradeEnd)
        {
            List <TimeSliceEx> tse = new List <TimeSliceEx>();

            foreach (TimeSlice s in slices)
            {
                TimeSliceEx se = new TimeSliceEx(s);
                se.UpdateTradeType(dayTradeBegin, dayTradeEnd);
                tse.Add(se);
            }

            return(tse);
        }
예제 #4
0
        // 更新当前时间,判断处于哪个交易时间片
        protected void updateTradeSlice()
        {
            _currentTradeSlice = null;

            double currentExchangeTime = CurrentTime.TimeOfDay.TotalSeconds;

            //凌晨时间
            if (CurrentTime.TimeOfDay.Hours < DayTradeBegin)
            {
                currentExchangeTime += UtilsEx.OndayInSeconds;
            }

            double secondsBegin = 0;
            double secondsEnd   = 0;

            foreach (TimeSliceEx slice in _tradeSlices)
            {
                secondsBegin = slice.Slice.BeginTime.TotalSeconds - TimeSliceTolerance;
                secondsEnd   = slice.Slice.EndTime.TotalSeconds + TimeSliceTolerance;
                if (!slice.IsDayTrade)
                {
                    // 夜盘,且跨日期(例如:21:00:00 - 02:00:00)
                    if (slice.Slice.BeginTime.Hours < DayTradeBegin)
                    {
                        secondsBegin += UtilsEx.OndayInSeconds;
                    }
                    if (slice.Slice.EndTime.Hours < DayTradeBegin)
                    {
                        secondsEnd += UtilsEx.OndayInSeconds;
                    }
                }

                if (currentExchangeTime > secondsBegin &&
                    currentExchangeTime < secondsEnd)
                {
                    _currentTradeSlice = slice;
                    break;
                }
            }

            // 是否处于交易休息时间
            _isTradeBreak = _currentTradeSlice == null;
        }