private string GetDataValues(IBaseData data_) { PropertyInfo[] propertyInfos = data_.GetType().GetProperties(); string type; PropertyInfo propertyInfo; object fieldValue; string valueString = string.Empty; StringBuilder sb = new StringBuilder(); for (int i = 0; i < propertyInfos.Length; i++) { propertyInfo = propertyInfos[i]; if (propertyInfo.GetSetMethod(true) == null) { continue; } fieldValue = propertyInfo.GetValue(data_, null); type = SqLiteHelper.GetColumnType(propertyInfo.PropertyType.Name); valueString = type == SqLiteHelper.TEXT ? string.Format("{0}{1}{2}", "'", fieldValue.ToString(), "'") : fieldValue.ToString(); if (i == 0) { sb.Append(valueString); } else { sb.Append(string.Format(",{0}", valueString)); } } return(sb.ToString()); }
private string GetFieldsNames(IBaseData data_) { List <PropertyInfo> propertyInfos = new List <PropertyInfo>( data_.GetType().GetProperties().Where(prop_ => Attribute.IsDefined(prop_, typeof(DbFieldAttribute))) ); StringBuilder sb = new StringBuilder(); for (int i = 0; i < propertyInfos.Count; i++) { if (propertyInfos[i].GetSetMethod(true) == null) { continue; } if (i == 0) { sb.Append(propertyInfos[i].Name); } else { sb.Append(string.Format(",{0}", propertyInfos[i].Name)); } } return(sb.ToString()); }
/// <summary> /// Updates this consolidator with the specified data /// </summary> /// <param name="data">The new data for the consolidator</param> public void Update(IBaseData data) { if (!(data is TInput)) { throw new ArgumentNullException("data", "Received type of " + data.GetType().Name + " but expected " + typeof(TInput).Name); } Update((TInput)data); }
/// <summary> /// Updates this consolidator with the specified data /// </summary> /// <param name="data">The new data for the consolidator</param> public void Update(IBaseData data) { if (!(data is TInput)) { throw new ArgumentNullException(nameof(data), $"Received type of {data.GetType().Name} but expected {typeof(TInput).Name}" ); } Update((TInput)data); }
/// <summary> /// Initializes an instance of <see cref="PandasData"/> with a sample <see cref="IBaseData"/> object /// </summary> /// <param name="baseData"><see cref="IBaseData"/> object that contains information to be saved in an instance of <see cref="PandasData"/></param> public PandasData(IBaseData baseData) { var columns = "open,high,low,close,volume,askopen,askhigh,asklow,askclose,asksize,bidopen,bidhigh,bidlow,bidclose,bidsize"; var type = baseData.GetType(); if (baseData is DynamicData) { // We get the fields of DynamicData from the storage dictionary // and add the field named 'value' since it is the reference value columns = "value," + string.Join(",", ((DynamicData)baseData).GetStorageDictionary().Keys); } else if (type == typeof(Tick)) { columns = "askprice,asksize,bidprice,bidsize,lastprice,quantity,exchange,suspicious"; } // C# custom data else if (type != typeof(TradeBar) && type != typeof(QuoteBar)) { columns = "Value"; var properties = type.GetProperties(); foreach (var property in properties.GroupBy(x => x.Name)) { if (property.Count() > 1) { throw new ArgumentException($"More than one \'{property.Key}\' member was found in \'{type.Name}\' class."); } if (!_baseDataProperties.Contains(property.Key)) { columns += $",{property.Key}"; } } _customDataType = type; } _series = columns.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToDictionary(k => k, v => new List <object>()); _symbol = baseData.Symbol; _timeIndex = new List <DateTime>(); Levels = 2; if (_symbol.SecurityType == SecurityType.Future) { Levels = 3; } if (_symbol.SecurityType == SecurityType.Option) { Levels = 5; } // Add first data-point to series Add(baseData); }
/// <summary> /// Updates the state of this indicator with the given value and returns true /// if this indicator is ready, false otherwise /// </summary> /// <param name="input">The value to use to update this indicator</param> /// <returns>True if this indicator is ready, false otherwise</returns> public bool Update(IBaseData input) { if (_previousInput != null && input.Time < _previousInput.Time) { // if we receive a time in the past, log and return Log.Error($"This is a forward only indicator: {Name} Input: {input.Time:u} Previous: {_previousInput.Time:u}. It will not be updated with this input."); return(IsReady); } if (!ReferenceEquals(input, _previousInput)) { // compute a new value and update our previous time Samples++; if (!(input is T)) { throw new ArgumentException($"IndicatorBase.Update() 'input' expected to be of type {typeof(T)} but is of type {input.GetType()}"); } _previousInput = (T)input; var nextResult = ValidateAndComputeNextValue((T)input); if (nextResult.Status == IndicatorStatus.Success) { Current = new IndicatorDataPoint(input.Time, nextResult.Value); // let others know we've produced a new data point OnUpdated(Current); } } return(IsReady); }