Exemple #1
0
        /// <summary>
        /// 获取某个证券的某段时间的历史数据
        /// </summary>
        /// <param name="instrument"></param>
        /// <param name="dataType"></param>
        /// <param name="barSize"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public List <ISeriesObject> GetHistoricalData(Instrument instrument, HistoricalDataType dataType, int barSize, string beginTime, string endTime)
        {
            switch (dataType)
            {
            case HistoricalDataType.Bar:
                List <GMSDK.Bar> gskBars = new List <GMSDK.Bar>();
                gskBars = _md.GetBars(instrument.Symbol, barSize, beginTime, endTime);
                return(GSKToGM.ConvertBars(gskBars));

            case HistoricalDataType.Daily:
                List <GMSDK.DailyBar> gskDailys = new List <GMSDK.DailyBar>();
                gskDailys = _md.GetDailyBars(instrument.Symbol, beginTime, endTime);
                return(GSKToGM.ConvertDailys(gskDailys));

            case HistoricalDataType.Trade:
                this.gskTicksCache = _md.GetTicks(instrument.Symbol, beginTime, endTime);
                return(GSKToGM.ConvertTrades(this.gskTicksCache));

            case HistoricalDataType.Quote:
                this.gskTicksCache = _md.GetTicks(instrument.Symbol, beginTime, endTime);
                return(GSKToGM.ConvertQuotes(this.gskTicksCache));

            default:
                throw new ArgumentException("Unknown data type: " + dataType.ToString());
            }
        }
Exemple #2
0
        private List <GMSDK.Tick> gskTicksCache = new List <GMSDK.Tick>();//trade和quote都由GMSDK.tick产生,为了历史数据提供者在导入trade和quote时不用读取两遍的tick,故而用此变量缓存tick
        public void SendHistoricalDataRequest(HistoricalDataRequest request)
        {
            if (!this.IsConnected)
            {
                this.EmitError(1, "The current historical data provider not connected.");
                return;
            }
            Instrument instrument = (Instrument)request.Instrument;

            this.historicalDataIds.Add(request.RequestId, request);
            string beginTime          = request.BeginDate.ToString("yyyy-MM-dd HH:mm:ss");
            string endTime            = request.EndDate.ToString("yyyy-MM-dd HH:mm:ss");
            List <ISeriesObject> list = this.GetHistoricalData(instrument, request.DataType, (int)request.BarSize, beginTime, endTime);
            bool flag = false;

            if ((list.Count < 1) || (flag = this.historicalPendingCancels.ContainsKey(request.RequestId)))
            {
                if (flag)
                {
                    this.historicalPendingCancels.Remove(request.RequestId);
                    this.EmitHistoricalDataRequestCancelled(request.RequestId, request.Instrument);
                }
                else
                {
                    this.historicalDataIds.Remove(request.RequestId);
                    this.EmitHistoricalDataRequestCompleted(request.RequestId, request.Instrument);
                }
            }
            else
            {
                if (request.DataType == HistoricalDataType.Trade)
                {
                    foreach (ISeriesObject obj1 in list)
                    {
                        this.EmitHistoricalTrade(request.RequestId, request.Instrument, obj1 as Trade);
                        if (this.historicalPendingCancels.ContainsKey(request.RequestId))
                        {
                            this.historicalPendingCancels.Remove(request.RequestId);
                            this.EmitHistoricalDataRequestCancelled(request.RequestId, request.Instrument);
                        }
                    }
                    if (this.tradeAndQuote)//Quote与Trade一起导入
                    {
                        List <ISeriesObject> listOther = GSKToGM.ConvertQuotes(this.gskTicksCache);
                        foreach (ISeriesObject obj2 in listOther)
                        {
                            this.EmitHistoricalQuote(request.RequestId, request.Instrument, obj2 as Quote);
                            if (this.historicalPendingCancels.ContainsKey(request.RequestId))
                            {
                                this.historicalPendingCancels.Remove(request.RequestId);
                                this.EmitHistoricalDataRequestCancelled(request.RequestId, request.Instrument);
                            }
                        }
                    }
                }
                else if (request.DataType == HistoricalDataType.Quote)
                {
                    foreach (ISeriesObject obj2 in list)
                    {
                        this.EmitHistoricalQuote(request.RequestId, request.Instrument, obj2 as Quote);
                        if (this.historicalPendingCancels.ContainsKey(request.RequestId))
                        {
                            this.historicalPendingCancels.Remove(request.RequestId);
                            this.EmitHistoricalDataRequestCancelled(request.RequestId, request.Instrument);
                        }
                    }

                    if (this.tradeAndQuote)//Trade与Quote一起导入
                    {
                        List <ISeriesObject> listOther = GSKToGM.ConvertTrades(this.gskTicksCache);
                        foreach (ISeriesObject obj1 in listOther)
                        {
                            this.EmitHistoricalTrade(request.RequestId, request.Instrument, obj1 as Trade);
                            if (this.historicalPendingCancels.ContainsKey(request.RequestId))
                            {
                                this.historicalPendingCancels.Remove(request.RequestId);
                                this.EmitHistoricalDataRequestCancelled(request.RequestId, request.Instrument);
                            }
                        }
                    }
                }
                else
                {
                    foreach (ISeriesObject obj3 in list)
                    {
                        this.EmitHistoricalBar(request.RequestId, request.Instrument, obj3 as Bar);
                        if (this.historicalPendingCancels.ContainsKey(request.RequestId))
                        {
                            this.historicalPendingCancels.Remove(request.RequestId);
                            this.EmitHistoricalDataRequestCancelled(request.RequestId, request.Instrument);
                        }
                    }
                }
                this.EmitHistoricalDataRequestCompleted(request.RequestId, request.Instrument);
            }
        }