Esempio n. 1
0
        protected override void OnSubscribe(InstrumentList instruments)
        {
            // Get size of bar.
            barSize = (long)Global[barSizeCode];

            // Get roll info.
            rollInfo = (List <RollInfo>)Global[rollInfoCode];

            // Get root instrument.
            rootInstrument = instruments.GetByIndex(0);

            // Get current futures contract.
            currentFuturesContract = rootInstrument.Legs[legIndex].Instrument;

            // Add current futures contract to bar factory.
            BarFactory.Add(currentFuturesContract, BarType.Time, barSize);

            // Add current futures contract to strategy.
            AddInstrument(currentFuturesContract);

            // Add reminder to maturity date and roll time.
            AddReminder(rollInfo[legIndex].Maturity.Date + TimeOfRoll);

            AddGroups();
        }
Esempio n. 2
0
 public void Subscribe(IDataProvider provider, InstrumentList instruments)
 {
     if (provider.Status != ProviderStatus.Connected)
     {
         provider.Connect();
     }
     InstrumentList instrumentList = new InstrumentList();
     for (int i = 0; i < instruments.Count; i++)
     {
         Instrument byIndex = instruments.GetByIndex(i);
         if (!this.subscriptions.ContainsKey((int)provider.Id))
         {
             this.subscriptions[(int)provider.Id] = new Dictionary<Instrument, int>();
         }
         if (!this.subscriptions[(int)provider.Id].ContainsKey(byIndex) || this.subscriptions[(int)provider.Id][byIndex] == 0)
         {
             this.subscriptions[(int)provider.Id][byIndex] = 0;
             instrumentList.Add(byIndex);
         }
         Dictionary<Instrument, int> dictionary;
         Instrument key;
         (dictionary = this.subscriptions[(int)provider.Id])[key = byIndex] = dictionary[key] + 1;
     }
     if (instrumentList.Count > 0)
     {
         provider.Subscribe(instrumentList);
     }
 }
Esempio n. 3
0
 public void Unsubscribe(IDataProvider provider, InstrumentList instruments)
 {
     InstrumentList instrumentList = new InstrumentList();
     for (int i = 0; i < instruments.Count; i++)
     {
         Instrument byIndex = instruments.GetByIndex(i);
         Dictionary<Instrument, int> dictionary;
         Instrument key;
         (dictionary = this.subscriptions[(int)provider.Id])[key = byIndex] = dictionary[key] - 1;
         if (this.subscriptions[(int)provider.Id][byIndex] == 0)
         {
             instrumentList.Add(byIndex);
         }
     }
     provider.Unsubscribe(instrumentList);
 }
Esempio n. 4
0
        protected override void OnSubscribe(InstrumentList instruments)
        {
            // Get size of bar.
            barSize = (long)Global[barSizeCode];

            // Get roll info.
            rollInfo = (List<RollInfo>)Global[rollInfoCode];

            // Get root instrument.
            rootInstrument = instruments.GetByIndex(0);

            // Get current futures contract.
            currentFuturesContract = rootInstrument.Legs[legIndex].Instrument;

            // Add current futures contract to bar factory.
            BarFactory.Add(currentFuturesContract, BarType.Time, barSize);

            // Add current futures contract to strategy.
            AddInstrument(currentFuturesContract);

            // Add reminder to maturity date and roll time.
            AddReminder(rollInfo[legIndex].Maturity.Date + TimeOfRoll);

            AddGroups();
        }