/// <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()); } }
public Dictionary <string, Trade> GetLastTrades(List <string> symbols, bool useCached = true) { List <GMSDK.Tick> gskTicks = new List <GMSDK.Tick>(); if (useCached) { foreach (string symbol in symbols.ToArray()) { GMSDK.Tick gskTick; if (this.tickCache.TryGetValue(symbol, out gskTick)) { gskTicks.Add(gskTick); symbols.Remove(symbol); } } } if (symbols.Count > 0) { gskTicks.AddRange(this.GetLastTicks(symbols)); } Dictionary <string, Trade> tradeDict = new Dictionary <string, Trade>(); foreach (GMSDK.Tick gskTick in gskTicks) { string symbol = gskTick.exchange + "." + gskTick.sec_id; tradeDict.Add(symbol, GSKToGM.ConvertTrade(gskTick)); } return(tradeDict); }
private void setNewBar(GMSDK.Bar gskBar) { string symbol = gskBar.exchange + "." + gskBar.sec_id; Instrument curInstrument = InstrumentManager.Instruments[symbol]; if (curInstrument == null) { this.EmitError(2, "Symbol " + symbol + " was not found in InstrumentManager."); return; } GMBar gmBar = GSKToGM.ConvertBar(gskBar); this.OnNewBar(this, new BarEventArgs(gmBar, curInstrument, this)); }
public List <Bar> GetBars(string symbol, int barSize, string beginTimeString, string endTimeString) { List <GMSDK.Bar> gskBars; lock (this._md) { gskBars = this._md.GetBars(symbol, barSize, beginTimeString, endTimeString); } List <Bar> bars = new List <Bar>(); foreach (GMSDK.Bar gskBar in gskBars) { bars.Add(GSKToGM.ConvertBar(gskBar)); } return(bars); }
public List <Daily> GetDailys(string symbol, string beginDateString, string endDateString) { List <GMSDK.DailyBar> gskDailys; lock (this._md) { gskDailys = this._md.GetDailyBars(symbol, beginDateString, endDateString); } List <Daily> dailys = new List <Daily>(); foreach (GMSDK.DailyBar gskDaily in gskDailys) { dailys.Add(GSKToGM.ConvertDaily(gskDaily)); } return(dailys); }
public List <Trade> GetTrades(string symbol, string beginTimeString, string endTimeString) { List <GMSDK.Tick> gskTicks; lock (this._md) { gskTicks = this._md.GetTicks(symbol, beginTimeString, endTimeString); } List <Trade> trades = new List <Trade>(); foreach (GMSDK.Tick gskTick in gskTicks) { trades.Add(GSKToGM.ConvertTrade(gskTick)); } return(trades); }
public List <Bar> GetLastNBars(string symbol, int barSize, int n, string lastTimeString) { List <GMSDK.Bar> gskBars; lock (this._md) { gskBars = this._md.GetLastNBars(symbol, barSize, n, lastTimeString); } gskBars.Reverse(); List <Bar> bars = new List <Bar>(); foreach (GMSDK.Bar gskBar in gskBars) { bars.Add(GSKToGM.ConvertBar(gskBar)); } return(bars); }
public List <Daily> GetLastNDailys(string symbol, int n, string lastDateString) { List <GMSDK.DailyBar> gskDailys; lock (this._md) { gskDailys = this._md.GetLastNDailyBars(symbol, n, lastDateString); } gskDailys.Reverse(); List <Daily> dailys = new List <Daily>(); foreach (GMSDK.DailyBar gskDaily in gskDailys) { dailys.Add(GSKToGM.ConvertDaily(gskDaily)); } return(dailys); }
public List <Trade> GetLastNTrades(string symbol, string lastTimeString, int n) { List <GMSDK.Tick> gskTicks; lock (this._md) { gskTicks = this._md.GetLastNTicks(symbol, n, lastTimeString); } gskTicks.Reverse(); List <Trade> trades = new List <Trade>(); foreach (GMSDK.Tick gskTick in gskTicks) { trades.Add(GSKToGM.ConvertTrade(gskTick)); } return(trades); }
private void setNewTick(GMSDK.Tick tick, bool isPush = false) { string symbol = tick.exchange + "." + tick.sec_id; if (isPush) { this.symbolsOfPush.Add(symbol); } if (!subscribedSymbols.Contains(symbol)) { return; } Instrument curInstrument = InstrumentManager.Instruments[symbol]; if (curInstrument == null) { this.EmitError(2, "Symbol " + symbol + " was not found in InstrumentManager."); return; } GMSDK.Tick prevTick = null; if (!this.tickCache.TryGetValue(symbol, out prevTick)) { this.EmitNewTrade(GSKToGM.ConvertTrade(tick), curInstrument); this.EmitNewQuote(GSKToGM.ConvertQuote(tick), curInstrument); } else { if (tick.utc_time > prevTick.utc_time) { if (tick.last_volume > 0 || tick.last_price != prevTick.last_price) { this.EmitNewTrade(GSKToGM.ConvertTrade(tick), curInstrument); } this.EmitNewQuote(GSKToGM.ConvertQuote(tick), curInstrument); } } this.tickCache[symbol] = tick; }
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); } }