Beispiel #1
0
 public OpenInterestTickAggregator()
     : base(Resolution.Daily, TickType.OpenInterest)
 {
     Consolidated = new List <BaseData>();
     Consolidator = new OpenInterestConsolidator(Time.OneDay);
     Consolidator.DataConsolidated += (sender, consolidated) =>
     {
         Consolidated.Add(consolidated as OpenInterest);
     };
 }
Beispiel #2
0
        /// <summary>
        /// Add new subscription to current <see cref="IDataAggregator"/> instance
        /// </summary>
        /// <param name="dataConfig">defines the parameters to subscribe to a data feed</param>
        /// <param name="newDataAvailableHandler">handler to be fired on new data available</param>
        /// <returns>The new enumerator for this subscription request</returns>
        public IEnumerator <BaseData> Add(SubscriptionDataConfig dataConfig, EventHandler newDataAvailableHandler)
        {
            IDataConsolidator consolidator;
            var period        = dataConfig.Resolution.ToTimeSpan();
            var isPeriodBased = false;

            switch (dataConfig.Type.Name)
            {
            case nameof(QuoteBar):
                isPeriodBased = dataConfig.Resolution != Resolution.Tick;
                consolidator  = new TickQuoteBarConsolidator(period);
                break;

            case nameof(TradeBar):
                isPeriodBased = dataConfig.Resolution != Resolution.Tick;
                consolidator  = new TickConsolidator(period);
                break;

            case nameof(OpenInterest):
                isPeriodBased = dataConfig.Resolution != Resolution.Tick;
                consolidator  = new OpenInterestConsolidator(period);
                break;

            case nameof(Tick):
                consolidator = FilteredIdentityDataConsolidator.ForTickType(dataConfig.TickType);
                break;

            case nameof(Split):
                consolidator = new IdentityDataConsolidator <Split>();
                break;

            case nameof(Dividend):
                consolidator = new IdentityDataConsolidator <Dividend>();
                break;

            default:
                // streaming custom data subscriptions can pass right through
                consolidator = new FilteredIdentityDataConsolidator <BaseData>(data => data.GetType() == dataConfig.Type);
                break;
            }

            var enumerator = new ScannableEnumerator <BaseData>(consolidator, dataConfig.ExchangeTimeZone, TimeProvider, newDataAvailableHandler, isPeriodBased);

            _enumerators.AddOrUpdate(
                dataConfig.Symbol.ID,
                new List <KeyValuePair <SubscriptionDataConfig, ScannableEnumerator <BaseData> > > {
                new KeyValuePair <SubscriptionDataConfig, ScannableEnumerator <BaseData> >(dataConfig, enumerator)
            },
                (k, v) => { return(v.Concat(new[] { new KeyValuePair <SubscriptionDataConfig, ScannableEnumerator <BaseData> >(dataConfig, enumerator) }).ToList()); });

            return(enumerator);
        }