string GetKeyFromSTKHISDATA(ref STKHISDATA pHisData)
 {
     return string.Format("{0}:{1}:{2}", pHisData.Market, pHisData.Code, pHisData.nPeriod);
 }
        private void OnRspHistoryQuot(IntPtr pQuotApi, IntPtr pBuffer, ref STKHISDATA pHisData)
        {
            string key = GetKeyFromSTKHISDATA(ref pHisData);
            string requestId;
            if (historicalDataRecords.TryGetValue(key, out requestId))
            {
                HistoricalDataRequest request;
                if (historicalDataIds.TryGetValue(requestId, out request))
                {
                    IntPtr ptrHead = (IntPtr)(pBuffer + Marshal.SizeOf(typeof(STKHISDATA)));
                    for (int i = 0; i < pHisData.nCount; ++i)
                    {
                        IntPtr ptr = (IntPtr)(ptrHead + Marshal.SizeOf(typeof(HISTORYDATA)) * i);
                        HISTORYDATA hd = (HISTORYDATA)Marshal.PtrToStructure(ptr, typeof(HISTORYDATA));

                        if (request.DataType == HistoricalDataType.Daily)
                        {
                            DateTime datetime = Convert.ToDateTime(hd.time.Substring(0, 10));

                            if (datetime >= request.BeginDate && datetime < request.EndDate)
                            {
                                Daily daily = new Daily(datetime,
                                                                hd.fOpen, hd.fHigh, hd.fLow, hd.fClose, (long)hd.fVolume, (long)hd.fAmount);
                                NewHistoricalBar(this,
                                    new HistoricalBarEventArgs(daily, request.RequestId, request.Instrument, this, -1));
                            }
                        }
                        else
                        {
                            DateTime datetime = Convert.ToDateTime(hd.time);
                            if (datetime >= request.BeginDate && datetime < request.EndDate)
                            {
                                Bar bar = new Bar(BarType.Time, request.BarSize, datetime.AddSeconds(-request.BarSize),
                                    datetime,
                                    hd.fOpen, hd.fHigh, hd.fLow, hd.fClose, (long)hd.fVolume, (long)hd.fAmount);
                                NewHistoricalBar(this,
                                    new HistoricalBarEventArgs(bar, request.RequestId, request.Instrument, this, -1));
                            }
                        }
                    }

                    historicalDataIds.Remove(request.RequestId);
                    EmitHistoricalDataCompleted(request);
                }
                historicalDataRecords.Remove(key);
            }
        }
        private void OnRspHistoryQuot(IntPtr pQuotApi, IntPtr pBuffer, ref STKHISDATA pHisData)
        {
            ehlog.Info("<--OnRspHistoryQuot:{0},{1},{2},{3}条", pHisData.Market, pHisData.Code, (PeriodType)pHisData.nPeriod, pHisData.nCount);
            string key = GetKeyFromSTKHISDATA(ref pHisData);
            DataRecord dr;
            if (historicalDataRecords_key.TryGetValue(key, out dr))
            {
                HistoricalDataRequest request = dr.request;

                IntPtr ptrHead = (IntPtr)(pBuffer + Marshal.SizeOf(typeof(STKHISDATA)));
                for (int i = 0; i < pHisData.nCount; ++i)
                {
                    IntPtr ptr = (IntPtr)(ptrHead + Marshal.SizeOf(typeof(HISTORYDATA)) * i);
                    HISTORYDATA hd = (HISTORYDATA)Marshal.PtrToStructure(ptr, typeof(HISTORYDATA));

                    if (request.DataType == HistoricalDataType.Daily)
                    {
                        DateTime datetime = Convert.ToDateTime(hd.time.Substring(0, 10));

                        if (!EnableDateFilter||(datetime >= request.BeginDate && datetime < request.EndDate))
                        {
                            Daily daily = new Daily(datetime,
                                                            hd.fOpen, hd.fHigh, hd.fLow, hd.fClose, (long)hd.fVolume, (long)hd.fAmount);
                            NewHistoricalBar(this,
                                new HistoricalBarEventArgs(daily, request.RequestId, request.Instrument, this, -1));
                        }
                    }
                    else
                    {
                        DateTime datetime = Convert.ToDateTime(hd.time);
                        if (!EnableDateFilter || (datetime >= request.BeginDate && datetime < request.EndDate))
                        {
                            Bar bar = new Bar(BarType.Time, request.BarSize, datetime.AddSeconds(-request.BarSize), datetime,
                                hd.fOpen, hd.fHigh, hd.fLow, hd.fClose, (long)hd.fVolume, (long)hd.fAmount);
                            NewHistoricalBar(this,
                                new HistoricalBarEventArgs(bar, request.RequestId, request.Instrument, this, -1));
                        }
                    }
                }

                RemoveRequest(key);
            }
        }