private void Init(MarketDataProvider provider, string NewBarOpen, string NewBar, string NewMarketBar) { _NewBar = NewBar; _NewBarOpen = NewBarOpen; _NewMarketBar = NewMarketBar; //得到OpenQuant.API.MarketDataProvider内的SmartQuant.Providers.IMarketDataProvider接口 marketDataProvider = (IMarketDataProvider)provider.GetType().GetField("provider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(provider); factory = marketDataProvider.BarFactory; // 遍历,得到对应的事件 foreach (var e in marketDataProvider.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic)) { switch (e.FieldType.ToString()) { case "SmartQuant.Providers.QuoteEventHandler": NewQuoteField = e; // 很遗憾,不能提前在保存下来 //(MulticastDelegate)NewQuoteField.GetValue(marketDataProvider); break; case "SmartQuant.Providers.TradeEventHandler": NewTradeField = e; break; case "SmartQuant.Providers.BarEventHandler": // 有三个这样的事件,怎么识别呢? // 由于混淆了代码,没法识别,只能人工先判断 // 判断的方法,1.断点, // 2.模拟下的 v8UpctWIWM(SeriesObjectEventArgs args1) if (e.Name == _NewBarOpen) { NewBarOpenField = e; } else if (e.Name == _NewBar) { NewBarField = e; } else if (e.Name == _NewMarketBar) { NewMarketBarField = e; } else { Console.WriteLine("{0} 没有识别出来,需人工处理!", e.Name); } break; } } }
public ExtMarketDataFilter(MarketDataProvider provider) { //得到OpenQuant.API.MarketDataProvider内的SmartQuant.Providers.IMarketDataProvider接口 marketDataProvider = (IMarketDataProvider)provider.GetType().GetField("provider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(provider); factory = marketDataProvider.BarFactory; // 遍历,得到对应的两个事件 foreach (var e in marketDataProvider.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic)) { //Console.WriteLine(e); switch (e.FieldType.ToString()) { case "SmartQuant.Providers.QuoteEventHandler": NewQuoteField = e; // 很遗憾,不能提前在保存下来 //(MulticastDelegate)NewQuoteField.GetValue(marketDataProvider); break; case "SmartQuant.Providers.TradeEventHandler": NewTradeField = e; break; } } }