public BarSeries this[Instrument instrument] { get { SmartQuant.Instruments.Instrument instrument2 = Map.OQ_SQ_Instrument[instrument] as SmartQuant.Instruments.Instrument; return(new BarSeries(SmartQuant.Instruments.DataManager.Bars[instrument2])); } }
private static void AddInstrument(SmartQuant.Instruments.Instrument sq_instrument) { Instrument instrument = new Instrument(sq_instrument); OpenQuant.instruments.Add(sq_instrument.Symbol, instrument); Map.OQ_SQ_Instrument[instrument] = sq_instrument; Map.SQ_OQ_Instrument[sq_instrument] = instrument; }
private static void RemoveInstrument(SmartQuant.Instruments.Instrument sq_instrument) { OpenQuant.instruments.Remove(sq_instrument.Symbol); Instrument key = Map.SQ_OQ_Instrument[sq_instrument] as Instrument; Map.OQ_SQ_Instrument.Remove(key); Map.SQ_OQ_Instrument.Remove(sq_instrument); }
public BarSeries this[Instrument instrument, BarType barType, long barSize] { get { SmartQuant.Instruments.Instrument instrument2 = Map.OQ_SQ_Instrument[instrument] as SmartQuant.Instruments.Instrument; return(new BarSeries(SmartQuant.Instruments.DataManager.Bars[instrument2, EnumConverter.Convert(barType), barSize])); } }
public static BarSeries GetHistoricalBars(Instrument instrument, DateTime begin, DateTime end, BarType barType, long barSize) { SmartQuant.Instruments.Instrument instrument2 = Map.OQ_SQ_Instrument[instrument] as SmartQuant.Instruments.Instrument; if (barSize == 86400L) { return(new BarSeries(SmartQuant.Instruments.DataManager.GetDailySeries(instrument2, begin, end))); } return(new BarSeries(SmartQuant.Instruments.DataManager.GetBarSeries(instrument2, begin, end, EnumConverter.Convert(barType), barSize))); }
public Instrument(InstrumentType type, string symbol, string secutityExchange, string currency) { if (!SmartQuant.Instruments.InstrumentManager.Instruments.Contains(symbol)) { this.instrument = new SmartQuant.Instruments.Instrument(symbol, EnumConverter.Convert(type)); this.instrument.SecurityExchange = secutityExchange; this.instrument.Currency = currency; this.instrument.Save(); } }
public static void Add(Instrument instrument, Bar bar) { SmartQuant.Instruments.Instrument instrument2 = Map.OQ_SQ_Instrument[instrument] as SmartQuant.Instruments.Instrument; if (bar.bar.BarType == SmartQuant.Data.BarType.Time && bar.bar.Size == 86400L) { Daily daily = new Daily(bar.bar.DateTime, bar.bar.Open, bar.bar.High, bar.bar.Low, bar.bar.Close, bar.bar.Volume, bar.bar.OpenInt); SmartQuant.Instruments.DataManager.Add(instrument2, daily); return; } SmartQuant.Instruments.DataManager.Add(instrument2, bar.bar); }
public void EmitTrade(string instrument, DateTime time, byte providerId, double price, int size) { SmartQuant.Data.Trade trade = new SmartQuant.Data.Trade(time, price, size) { ProviderId = providerId }; SmartQuant.Instruments.Instrument inst = SmartQuant.Instruments.InstrumentManager.Instruments[instrument]; EmitNewTradeEvent(inst, trade); }
public void EmitQuote(string instrument, DateTime time, byte providerId, double bid, int bidSize, double ask, int askSize) { SmartQuant.Data.Quote quote = new SmartQuant.Data.Quote(time, bid, bidSize, ask, askSize) { ProviderId = providerId }; SmartQuant.Instruments.Instrument inst = SmartQuant.Instruments.InstrumentManager.Instruments[instrument]; EmitNewQuoteEvent(inst, quote); }
public void EmitBarOpen(string instrument, DateTime time, byte providerId, double open, double high, double low, double close, long volume, long openInt, long size) { SmartQuant.Data.Bar bar = new SmartQuant.Data.Bar(time, open, high, low, close, volume, size) { ProviderId = providerId, OpenInt = openInt, }; SmartQuant.Instruments.Instrument inst = SmartQuant.Instruments.InstrumentManager.Instruments[instrument]; EmitNewBarOpenEvent(inst, bar); }
public void EmitBar(string instrument, DateTime time, byte providerId, double open, double high, double low, double close, long volume, long openInt, long size) { SmartQuant.Data.Bar bar = new SmartQuant.Data.Bar(SmartQuant.Data.BarType.Time, size, time, time.AddSeconds(size), open, high, low, close, volume, openInt) { ProviderId = providerId, IsComplete = true, }; SmartQuant.Instruments.Instrument inst = SmartQuant.Instruments.InstrumentManager.Instruments[instrument]; EmitNewBarEvent(inst, bar); }
public void SendMarketDataRequest(FIXMarketDataRequest request) { SubscriptionDataType subscriptionDataType = (SubscriptionDataType)0; for (int i = 0; i < request.NoMDEntryTypes; i++) { FIXMDEntryTypesGroup mDEntryTypesGroup = request.GetMDEntryTypesGroup(i); switch (mDEntryTypesGroup.MDEntryType) { case '0': case '1': if (request.MarketDepth == 1) { subscriptionDataType |= SubscriptionDataType.Quotes; } else { subscriptionDataType |= SubscriptionDataType.OrderBook; } break; case '2': subscriptionDataType |= SubscriptionDataType.Trades; break; } } for (int j = 0; j < request.NoRelatedSym; j++) { FIXRelatedSymGroup relatedSymGroup = request.GetRelatedSymGroup(j); SmartQuant.Instruments.Instrument key = SmartQuant.Instruments.InstrumentManager.Instruments[relatedSymGroup.Symbol]; global::OpenQuant.API.Instrument instrument = Map.SQ_OQ_Instrument[key] as global::OpenQuant.API.Instrument; switch (request.SubscriptionRequestType) { case '1': this.provider.CallSubscribe(instrument, subscriptionDataType); break; case '2': this.provider.CallUnsubscribe(instrument, subscriptionDataType); break; default: throw new Exception("Unknown subscription request type " + request.SubscriptionRequestType); } } }
public static BarSeries GetHistoricalBars(Instrument instrument, DateTime begin, DateTime end) { SmartQuant.Instruments.Instrument instrument2 = Map.OQ_SQ_Instrument[instrument] as SmartQuant.Instruments.Instrument; return(new BarSeries(SmartQuant.Instruments.DataManager.GetBarSeries(instrument2, begin, end))); }
public static void Add(Instrument instrument, OrderBookUpdate update) { SmartQuant.Instruments.Instrument instrument2 = Map.OQ_SQ_Instrument[instrument] as SmartQuant.Instruments.Instrument; SmartQuant.Instruments.DataManager.Add(instrument2, update.marketDepth); }
public static void Add(Instrument instrument, Quote quote) { SmartQuant.Instruments.Instrument instrument2 = Map.OQ_SQ_Instrument[instrument] as SmartQuant.Instruments.Instrument; SmartQuant.Instruments.DataManager.Add(instrument2, quote.quote); }
public static void Add(Instrument instrument, Trade trade) { SmartQuant.Instruments.Instrument instrument2 = Map.OQ_SQ_Instrument[instrument] as SmartQuant.Instruments.Instrument; SmartQuant.Instruments.DataManager.Add(instrument2, trade.trade); }
static void Main(string[] args) { // TO DO: Add your code here string dataPath = "e:/QDData"; bool overwrite = false; DateTime beginDate = new System.DateTime(2017, 4, 5); DateTime endDate = new System.DateTime(2017, 4, 7); string username = "******"; string password = "******"; int ret = _md.Init(username, password, MDMode.MD_MODE_NULL, "", "", ""); if (ret != 0) { string msg = _md.StrError(ret); Console.WriteLine(msg); return; } DateTime curDate = beginDate; //获取交易日历,以确定是否开市日 string dateString1 = ""; if (endDate.AddMonths(-1) > beginDate) { dateString1 = beginDate.ToString("yyyy-MM-dd"); } else { dateString1 = endDate.AddMonths(-1).ToString("yyyy-MM-dd"); } string dateString2 = endDate.AddDays(1).ToString("yyyy-MM-dd"); List <DateTime> tradeDates = GetTradeDates("SHSE", dateString1, dateString2); while (curDate < endDate) { Console.WriteLine("日期:" + curDate.ToString("yyyy-MM-dd")); if ((tradeDates.Count <= 0) || (!tradeDates.Contains(curDate))) { Console.WriteLine("今天不是交易日"); curDate = curDate.AddDays(1); continue; } string path = dataPath + "/" + curDate.Year.ToString() + "/" + curDate.Month.ToString(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } DateTime beginTime = curDate.Add(new TimeSpan(9, 0, 0)); DateTime endTime = curDate.Add(new TimeSpan(24, 0, 0)); string beginString = beginTime.ToString("yyyy-MM-dd HH:mm:ss"); string endString = endTime.ToString("yyyy-MM-dd HH:mm:ss"); Console.WriteLine("时间段:" + beginString + "----" + endString); try { DataFile file = DataFile.Open(path); Random ra = new Random(); try { //获取股票代码列表 List <string> symbols = new List <string>(); symbols = GetSymbols("SHSE", 1); symbols.AddRange(GetSymbols("SZSE", 1)); foreach (string symbol in symbols) { //Console.WriteLine("正在检查证券"+symbol+"的Tick数据..."); string name = symbol + ".Trade"; if (!file.Series.Contains(name)) { file.Series.Add(name); } FileSeries series = file.Series[name]; ISeriesObject[] has = series.GetArray(beginTime, endTime); SmartQuant.Instruments.Instrument inst = InstrumentManager.Instruments[symbol]; //获取当天的日线数据 Daily dailyBar = null; if (inst == null) { List <GMSDK.DailyBar> gskDailyBars = _md.GetDailyBars(symbol, curDate.ToString("yyyy-MM-dd"), curDate.ToString("yyyy-MM-dd")); if (gskDailyBars.Count > 0) { List <ISeriesObject> dailys = GSKToGM.ConvertDailys(gskDailyBars); dailyBar = (Daily)dailys[0]; } } else { DailySeries dailySeries = inst.GetDailySeries(curDate, curDate); if (dailySeries.Count > 0) { dailyBar = dailySeries[0]; } } bool needRebuild = false; //检查是否丢失 if (has.Length <= 0) { if (dailyBar != null) { Console.WriteLine("证券:{0},在日期:{1}时丢失Tick数据", symbol, curDate); needRebuild = true; } } else { //检查是否有重复,一般情形下不会重复,所以这里注释掉 /*int r1=ra.Next(0,has.Length-1); * int r2=ra.Next(0,has.Length-1); * * ISeriesObject randTrade1=has[r1]; * ISeriesObject randTrade2=has[r2]; * * ISeriesObject[] repeat1=series.GetArray(randTrade1.DateTime,randTrade1.DateTime); * ISeriesObject[] repeat2=series.GetArray(randTrade2.DateTime,randTrade2.DateTime); * if (repeat1.Length>1&&repeat2.Length>1) { * Console.WriteLine("r1={0},r2={1}",r1,r2); * Console.WriteLine("证券:{0},在日期:{1}时有重复的Tick数据",symbol,curDate); * needRebuild=true; * }*/ //检查是否不完整 GMTrade lastTrade = (GMTrade)has[has.Length - 1]; if ((dailyBar != null) && (lastTrade.TotalSize < dailyBar.Volume)) { Console.WriteLine("证券:{0},在日期:{1}时Tick数据不全", symbol, curDate); needRebuild = true; } } if (needRebuild) { List <GMSDK.Tick> gskTicksCache = _md.GetTicks(symbol, beginString, endString); Console.WriteLine(symbol + "有" + gskTicksCache.Count.ToString() + "笔数据。"); if (gskTicksCache.Count > 0) { //添加trades Console.WriteLine("存储Trade数据..."); List <ISeriesObject> trades = GSKToGM.ConvertTrades(gskTicksCache); string name1 = symbol + ".Trade"; if (!file.Series.Contains(name1)) { file.Series.Add(name1); } FileSeries series1 = file.Series[name1]; ISeriesObject[] hasTrades = series1.GetArray(beginTime, endTime); if (overwrite || hasTrades.Length != trades.Count) { foreach (ISeriesObject aTrade in hasTrades) { series1.Remove(aTrade.DateTime); } foreach (ISeriesObject trade in trades) { series1.Add(trade); } } series1.Reindex(Indexer.Daily); //添加quotes Console.WriteLine("存储Quote数据..."); List <ISeriesObject> quotes = GSKToGM.ConvertQuotes(gskTicksCache); string name2 = symbol + ".Quote"; if (!file.Series.Contains(name2)) { file.Series.Add(name2); } FileSeries series2 = file.Series[name2]; ISeriesObject[] hasQuotes = series2.GetArray(beginTime, endTime); if (overwrite || hasQuotes.Length != quotes.Count) { foreach (ISeriesObject aQuote in hasQuotes) { series2.Remove(aQuote.DateTime); } foreach (ISeriesObject quote in quotes) { series2.Add(quote); } } series2.Reindex(Indexer.Daily); } } } }catch (Exception ex) { throw ex; } finally { file.Close(); } }catch (Exception ex) { Console.WriteLine(ex.Message); } curDate = curDate.AddDays(1); } }
protected override bool doJob() { bool ret = false; List <Plate> topHotPlates = plateMonitor.GetTopNHotPlates(2, 17); List <Stock> stocks = new List <Stock>(); foreach (Plate curPlate in topHotPlates) { Console.WriteLine("版块:{0}", curPlate.Name); foreach (Stock curStock in curPlate.Stocks) { if (curStock.Price <= 0) { continue; //没有价格的除掉 } if (curStock.IncPercent < 1 || curStock.IncPercent >= 5) { continue; //去掉不涨的和已经涨得好高的 } if (!stocks.Contains(curStock)) { stocks.Add(curStock); } } } stocks.Sort(delegate(Stock s1, Stock s2){ return(s2.IncPercent.CompareTo(s1.IncPercent)); }); DateTime lastDate = Clock.Now.Date.AddDays(-1); DateTime beginTime = Clock.Now.Date.Add(new TimeSpan(9, 30, 0)); DateTime endTime = Clock.Now; string lastDateString = lastDate.ToString("yyyy-MM-dd"); string beginTimeString = beginTime.ToString("yyyy-MM-dd HH:mm:ss"); string endTimeString = endTime.ToString("yyyy-MM-dd HH:mm:ss"); foreach (Stock curStock in stocks) { Daily[] gmDailys = this.plateMonitor.GetDailyLine(curStock.Symbol, 20, lastDateString); RecognitionState dailyLineState = this.plateMonitor.GetDailyLineState(gmDailys); Bar[] gmMinBars = this.plateMonitor.GetMinLine(curStock.Symbol, beginTimeString, endTimeString); RecognitionState minLineState = this.plateMonitor.GetMinLineState(gmMinBars); if (!((dailyLineState.Shape == ShapeState.Rise) || (dailyLineState.Shape == ShapeState.RiseAfterFall && dailyLineState.Slope == SlopeState.Steep))) { continue; } if (minLineState.Shape == ShapeState.Fall || minLineState.Shape == ShapeState.RiseAfterFall) { continue; } if (minLineState.Shape == ShapeState.FallAfterRise && minLineState.Speed == SpeedState.Rapid) { continue; } SmartQuant.Instruments.Instrument inst = InstrumentManager.Instruments[curStock.Symbol]; if (inst != null) { this.strategy.AddBehavior(inst, new StockEntry(inst, dailyLineState, minLineState, this.tradeManager, this.strategy)); ret = true; } } return(ret); }
public static TradeSeries GetHistoricalTrades(Instrument instrument, DateTime begin, DateTime end) { SmartQuant.Instruments.Instrument instrument2 = Map.OQ_SQ_Instrument[instrument] as SmartQuant.Instruments.Instrument; return(new TradeSeries(SmartQuant.Instruments.DataManager.GetTradeArray(instrument2, begin, end))); }
internal Instrument(SmartQuant.Instruments.Instrument instrument) { this.instrument = instrument; this.book = new OrderBook(instrument.OrderBook); this.AltIDGroups = new AltIDGroupList(this); }
private void Init(SmartQuant.Instruments.Portfolio sq_Portfolio, SmartQuant.Instruments.Portfolio sq_MetaPortfolio, SmartQuant.Instruments.Instrument sq_Instrument, DataRequests strategyRequests, string strategyName, IStrategyLogManager strategyLogManager) { this.sq_Instrument = sq_Instrument; this.instrument = (Map.SQ_OQ_Instrument[sq_Instrument] as Instrument); this.portfolio = (Map.SQ_OQ_Portfolio[sq_Portfolio] as Portfolio); this.metaPortfolio = (Map.SQ_OQ_Portfolio[sq_MetaPortfolio] as Portfolio); this.performance = new Performance(this.portfolio); this.metaPerformance = new Performance(this.metaPortfolio); this.dataRequests = strategyRequests; this.strategyName = strategyName; this.strategyLogManager = strategyLogManager; }