public override void Init(GenericDataDictionary template, GenericDataObject parentModel) { template.GetValue("label", out string label); _label.Text = label; template.GetValue("keyPrefix", out _keyPrefix); _prefixLabel.Text = _keyPrefix; template.GetValue("slotType", out _linkType); parentModel.TryGetValue(_label.Text, out GenericDataObject <string> model); if (model != null) { _model = model; _field.Text = _model.value.Substring(_keyPrefix.Length, _model.value.Length - _keyPrefix.Length); OnChanged(_field.Text); } else { template.GetValue("key", out string defaultKey); _field.Text = defaultKey; _model = parentModel.TryAddValue(_label.Text, string.Empty) as GenericDataObject <string>; OnChanged(_field.Text); } }
/// <summary> /// Gets the data of the specified symbol and type. /// </summary> /// <remarks>Supports both C# and Python use cases</remarks> protected static dynamic GetImpl(Type type, Slice instance) { Lazy <object> dictionary; if (!instance._dataByType.TryGetValue(type, out dictionary)) { if (type == typeof(Tick)) { dictionary = new Lazy <object>(() => { var dataDictionaryCache = GenericDataDictionary.Get(type); var dic = Activator.CreateInstance(dataDictionaryCache.GenericType); foreach (var data in instance._data.Value.Values.SelectMany <dynamic, dynamic>(x => x.GetData()).Where(o => o != null && (Type)o.GetType() == type)) { dataDictionaryCache.MethodInfo.Invoke(dic, new[] { data.Symbol, data }); } return(dic); } ); } else if (type == typeof(TradeBar)) { dictionary = new Lazy <object>(() => new DataDictionary <TradeBar>( instance._data.Value.Values.Where(x => x.TradeBar != null).Select(x => x.TradeBar), x => x.Symbol)); } else if (type == typeof(QuoteBar)) { dictionary = new Lazy <object>(() => new DataDictionary <QuoteBar>( instance._data.Value.Values.Where(x => x.QuoteBar != null).Select(x => x.QuoteBar), x => x.Symbol)); } else { dictionary = new Lazy <object>(() => { var dataDictionaryCache = GenericDataDictionary.Get(type); var dic = Activator.CreateInstance(dataDictionaryCache.GenericType); foreach (var data in instance._data.Value.Values.Select(x => x.GetData()).Where(o => o != null && (Type)o.GetType() == type)) { dataDictionaryCache.MethodInfo.Invoke(dic, new[] { data.Symbol, data }); } return(dic); } ); } instance._dataByType[type] = dictionary; } return(dictionary.Value); }
/// <summary> /// Provides a <see cref="GenericDataDictionary"/> instance for a given <see cref="Type"/> /// </summary> /// <param name="type"></param> /// <returns>A new instance or retrieved from the cache</returns> public static GenericDataDictionary Get(Type type) { GenericDataDictionary dataDictionaryCache; if (!_genericCache.TryGetValue(type, out dataDictionaryCache)) { var generic = typeof(DataDictionary <>).MakeGenericType(type); var method = generic.GetMethod("Add", new[] { typeof(Symbol), type }); _genericCache[type] = dataDictionaryCache = new GenericDataDictionary(generic, method); } return(dataDictionaryCache); }
/// <summary> /// Provides a <see cref="GenericDataDictionary"/> instance for a given <see cref="Type"/> /// </summary> /// <param name="type">The requested data type</param> /// <param name="isPythonData">True if data is of <see cref="PythonData"/> type</param> /// <returns>A new instance or retrieved from the cache</returns> public static GenericDataDictionary Get(Type type, bool isPythonData) { GenericDataDictionary dataDictionaryCache; if (!_genericCache.TryGetValue(type, out dataDictionaryCache)) { var dictionaryType = type; if (isPythonData) { // let's create a python data dictionary because the data itself will be a PythonData type in C# dictionaryType = typeof(PythonData); } var generic = typeof(DataDictionary <>).MakeGenericType(dictionaryType); var method = generic.GetMethod("Add", new[] { typeof(Symbol), dictionaryType }); _genericCache[type] = dataDictionaryCache = new GenericDataDictionary(generic, method); } return(dataDictionaryCache); }
public override void Init(GenericDataDictionary template, GenericDataObject parentModel) { template.GetValue("label", out string label); _label.Text = label; template.GetValue("keyPrefix", out _keyPrefix); template.GetValue("keySize", out _keySize); template.GetValue("slotType", out _linkType); parentModel.TryGetValue(_label.Text, out GenericDataObject <string> model); if (model != null) { _model = model; SetKey(_model.value); _model.value = GetKey; } else { SetKey(); _model = parentModel.TryAddValue(_label.Text, GetKey) as GenericDataObject <string>; } }
/// <summary> /// Gets the data of the specified type. /// </summary> /// <remarks>Supports both C# and Python use cases</remarks> protected static dynamic GetImpl(Type type, Slice instance) { if (instance._dataByType == null) { // for performance we only really create this collection if someone used it instance._dataByType = new Dictionary <Type, object>(1); } object dictionary; if (!instance._dataByType.TryGetValue(type, out dictionary)) { var requestedOpenInterest = type == typeof(OpenInterest); if (type == typeof(Tick) || requestedOpenInterest) { var dataDictionaryCache = GenericDataDictionary.Get(type); dictionary = Activator.CreateInstance(dataDictionaryCache.GenericType); foreach (var data in instance.Ticks) { var symbol = data.Key; // preserving existing behavior we will return the last data point, users expect a 'DataDictionary<Tick> : IDictionary<Symbol, Tick>'. // openInterest is stored with the Ticks collection var lastDataPoint = data.Value.LastOrDefault(tick => requestedOpenInterest && tick.TickType == TickType.OpenInterest || !requestedOpenInterest && tick.TickType != TickType.OpenInterest); if (lastDataPoint == null) { continue; } dataDictionaryCache.MethodInfo.Invoke(dictionary, new object[] { symbol, lastDataPoint }); } } else if (type == typeof(TradeBar)) { dictionary = instance.Bars; } else if (type == typeof(QuoteBar)) { dictionary = instance.QuoteBars; } else if (type == typeof(Delisting)) { dictionary = instance.Delistings; } else if (type == typeof(Split)) { dictionary = instance.Splits; } else if (type == typeof(OptionChain)) { dictionary = instance.OptionChains; } else if (type == typeof(FuturesChain)) { dictionary = instance.FuturesChains; } else if (type == typeof(Dividend)) { dictionary = instance.Dividends; } else if (type == typeof(SymbolChangedEvent)) { dictionary = instance.SymbolChangedEvents; } else { var dataDictionaryCache = GenericDataDictionary.Get(type); dictionary = Activator.CreateInstance(dataDictionaryCache.GenericType); foreach (var data in instance._data.Value.Values.Select(x => x.Custom).Where(o => o != null && o.GetType() == type)) { dataDictionaryCache.MethodInfo.Invoke(dictionary, new object[] { data.Symbol, data }); } } instance._dataByType[type] = dictionary; } return(dictionary); }
/// <summary> /// Gets the data of the specified type. /// </summary> /// <remarks>Supports both C# and Python use cases</remarks> protected static dynamic GetImpl(Type type, Slice instance) { object dictionary; if (!instance._dataByType.TryGetValue(type, out dictionary)) { if (type == typeof(Tick)) { var dataDictionaryCache = GenericDataDictionary.Get(type); dictionary = Activator.CreateInstance(dataDictionaryCache.GenericType); foreach (var data in instance.Ticks) { var symbol = data.Key; var listOfTicks = data.Value; // preserving existing behavior we will return the last data point, users expect a 'DataDictionary<Tick> : IDictionary<Symbol, Tick>' var lastDataPoint = listOfTicks[listOfTicks.Count - 1]; dataDictionaryCache.MethodInfo.Invoke(dictionary, new object[] { symbol, lastDataPoint }); } } else if (type == typeof(TradeBar)) { dictionary = instance.Bars; } else if (type == typeof(QuoteBar)) { dictionary = instance.QuoteBars; } else if (type == typeof(Delisting)) { dictionary = instance.Delistings; } else if (type == typeof(Split)) { dictionary = instance.Splits; } else if (type == typeof(OptionChain)) { dictionary = instance.OptionChains; } else if (type == typeof(FuturesChain)) { dictionary = instance.FuturesChains; } else if (type == typeof(Dividend)) { dictionary = instance.Dividends; } else if (type == typeof(SymbolChangedEvent)) { dictionary = instance.SymbolChangedEvents; } else { var dataDictionaryCache = GenericDataDictionary.Get(type); dictionary = Activator.CreateInstance(dataDictionaryCache.GenericType); foreach (var data in instance._data.Value.Values.Select(x => x.Custom).Where(o => o != null && o.GetType() == type)) { dataDictionaryCache.MethodInfo.Invoke(dictionary, new object[] { data.Symbol, data }); } } instance._dataByType[type] = dictionary; } return(dictionary); }