public override void Subscribe(InstrumentList instruments)
 {
     foreach (Instrument current in instruments)
     {
         this.Subscribe(current);
     }
 }
Exemple #2
0
 public void Add(InstrumentList instruments, BarType barType, long barSize)
 {
     foreach (Instrument current in instruments)
     {
         this.Add(current, barType, barSize);
     }
 }
Exemple #3
0
 public virtual void Unsubscribe(InstrumentList instruments)
 {
     foreach (Instrument current in instruments)
     {
         this.Unsubscribe(current);
     }
 }
Exemple #4
0
 public void AddInstruments(InstrumentList instruments)
 {
     foreach (Instrument current in instruments)
     {
         this.AddInstrument(current);
     }
 }
        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);
            }
        }
Exemple #6
0
 internal void UnregisterMarketDataRequest(IDataProvider dataProvider, InstrumentList instrumentList)
 {
     if (this.status == StrategyStatus.Running && instrumentList.Count > 0 && this.framework.SubscriptionManager != null)
     {
         this.framework.SubscriptionManager.Unsubscribe(dataProvider, instrumentList);
     }
 }
 public override void Unsubscribe(InstrumentList instruments)
 {
     foreach (Instrument current in instruments)
     {
         SellSideInstrumentStrategy sellSideInstrumentStrategy = this.strategyBySynthInstrument[current.Id];
         sellSideInstrumentStrategy.OnUnsubscribe(current);
     }
 }
Exemple #8
0
        public void RemoveInstrument(Instrument instrument)
        {
            this.instruments.Remove(instrument);
            InstrumentList instrumentList = new InstrumentList();

            instrumentList.Add(instrument);
            this.framework.strategyManager.UnregisterMarketDataRequest(this.GetDataProvider(this, instrument), instrumentList);
            if (this.parent != null)
            {
                this.parent.UnregisterStrategy(this, instrumentList, (int)this.id);
            }
        }
Exemple #9
0
        internal void RegisterStrategy(Strategy strategy, InstrumentList instruments, int orderRouteId)
        {
            strategy.portfolio.Parent = this.portfolio;
            foreach (Instrument current in instruments)
            {
                LinkedList <Strategy> linkedList;
                if (this.strategiesByInstrument[current.Id] == null)
                {
                    linkedList = new LinkedList <Strategy>();
                    this.strategiesByInstrument[current.Id] = linkedList;
                }
                else
                {
                    linkedList = this.strategiesByInstrument[current.Id];
                }
                linkedList.Add(strategy);
                IdArray <int> idArray;
                int           num;
                (idArray = this.instrumentCountTable)[num = current.id] = idArray[num] + 1;
            }
            Dictionary <IDataProvider, InstrumentList> dictionary = new Dictionary <IDataProvider, InstrumentList>();

            foreach (Instrument current2 in instruments)
            {
                InstrumentList     instrumentList    = null;
                IDataProvider      dataProvider      = this.GetDataProvider(strategy, current2);
                IExecutionProvider executionProvider = strategy.GetExecutionProvider(current2);
                if (dataProvider.Status == ProviderStatus.Disconnected)
                {
                    dataProvider.Connect();
                }
                if (executionProvider.Status == ProviderStatus.Disconnected)
                {
                    executionProvider.Connect();
                }
                if (!dictionary.TryGetValue(dataProvider, out instrumentList))
                {
                    instrumentList           = new InstrumentList();
                    dictionary[dataProvider] = instrumentList;
                }
                instrumentList.Add(current2);
            }
            foreach (KeyValuePair <IDataProvider, InstrumentList> current3 in dictionary)
            {
                this.framework.strategyManager.RegisterMarketDataRequest(current3.Key, current3.Value);
            }
            this.strategyByOrderId[orderRouteId] = strategy;
            if (this.parent != null)
            {
                this.parent.RegisterStrategy(this, instruments, orderRouteId);
            }
        }
Exemple #10
0
 public override void Subscribe(InstrumentList instruments)
 {
     if (!this.isRunning)
     {
         foreach (Instrument current in instruments)
         {
             this.Subscribe_(current, this.dateTime1, this.dateTime2);
         }
         this.Run();
         return;
     }
     foreach (Instrument current2 in instruments)
     {
         this.Subscribe_(current2, this.framework.Clock.DateTime, this.dateTime2);
     }
 }
        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);
        }
 public InstrumentManager(Framework framework, InstrumentServer server)
 {
     this.framework = framework;
     this.server    = server;
     this.server.Open();
     this.next_id     = -1;
     this.instruments = server.Load();
     for (int i = 0; i < this.instruments.Count; i++)
     {
         this.instruments.GetByIndex(i).isPersistent = true;
         int id = this.instruments.GetByIndex(i).Id;
         if (id > this.next_id)
         {
             this.next_id = id;
         }
     }
     this.next_id++;
 }
Exemple #13
0
        internal void UnregisterStrategy(Strategy strategy, InstrumentList instruments, int orderRouteId)
        {
            strategy.portfolio.Parent = this.portfolio;
            foreach (Instrument current in instruments)
            {
                LinkedList <Strategy> linkedList = this.strategiesByInstrument[current.Id];
                if (linkedList != null)
                {
                    linkedList.Remove(strategy);
                }
                linkedList.Add(strategy);
                IdArray <int> idArray;
                int           num;
                (idArray = this.instrumentCountTable)[num = current.id] = idArray[num] - 1;
                if (this.instrumentCountTable[current.id] == 0)
                {
                    this.Instruments.Remove(current);
                }
            }
            Dictionary <IDataProvider, InstrumentList> dictionary = new Dictionary <IDataProvider, InstrumentList>();

            foreach (Instrument current2 in instruments)
            {
                InstrumentList instrumentList = null;
                IDataProvider  key            = this.GetDataProvider(strategy, current2);
                if (!dictionary.TryGetValue(key, out instrumentList))
                {
                    instrumentList  = new InstrumentList();
                    dictionary[key] = instrumentList;
                }
                instrumentList.Add(current2);
            }
            foreach (KeyValuePair <IDataProvider, InstrumentList> current3 in dictionary)
            {
                this.framework.strategyManager.UnregisterMarketDataRequest(current3.Key, current3.Value);
            }
            this.strategyByOrderId[orderRouteId] = null;
            if (this.parent != null)
            {
                this.parent.UnregisterStrategy(this, instruments, orderRouteId);
            }
        }
Exemple #14
0
        private void RegisterInstrument(Instrument instrument)
        {
            InstrumentList instrumentList = new InstrumentList();

            instrumentList.Add(instrument);
            IDataProvider      dataProvider      = this.GetDataProvider(this, instrument);
            IExecutionProvider executionProvider = this.GetExecutionProvider(instrument);

            if (dataProvider.Status == ProviderStatus.Disconnected)
            {
                dataProvider.Connect();
            }
            if (executionProvider.Status == ProviderStatus.Disconnected)
            {
                executionProvider.Connect();
            }
            this.framework.strategyManager.RegisterMarketDataRequest(dataProvider, instrumentList);
            if (this.parent != null)
            {
                this.parent.RegisterStrategy(this, instrumentList, (int)this.id);
            }
        }
Exemple #15
0
 public Strategy(Framework framework, string name)
 {
     this.framework = framework;
     this.Name      = name;
     this.strategiesByInstrument = new IdArray <LinkedList <Strategy> >(1000);
     this.strategyByOrderId      = new IdArray <Strategy>(1000);
     this.strategies             = new LinkedList <Strategy>();
     this.status               = StrategyStatus.Stopped;
     this.instruments          = new InstrumentList();
     this.instrumentCountTable = new IdArray <int>(1000);
     if (framework != null)
     {
         this.portfolio = new Portfolio(framework, this.Name);
         framework.PortfolioManager.Add(this.portfolio);
     }
     this.bars              = new BarSeries("", "");
     this.equity            = new TimeSeries();
     this.bids              = new TickSeries("");
     this.asks              = new TickSeries("");
     this.stops             = new List <Stop>();
     this.stopsByInstrument = new IdArray <List <Stop> >(1000);
 }
        public void Clear()
        {
            foreach (Instrument current in this.instruments)
            {
                current.bid   = null;
                current.ask   = null;
                current.trade = null;
            }
            InstrumentList instrumentList = new InstrumentList();

            foreach (Instrument current2 in this.instruments)
            {
                if (!current2.isPersistent)
                {
                    instrumentList.Add(current2);
                }
            }
            foreach (Instrument current3 in instrumentList)
            {
                this.Delete(current3);
            }
        }
Exemple #17
0
        public void RegisterMarketDataRequest(IDataProvider dataProvider, InstrumentList instrumentList)
        {
            InstrumentList instrumentList2 = new InstrumentList();
            InstrumentList instrumentList3 = null;

            if (!this.requests.TryGetValue(dataProvider, out instrumentList3))
            {
                instrumentList3             = new InstrumentList();
                this.requests[dataProvider] = instrumentList3;
            }
            foreach (Instrument current in instrumentList)
            {
                if (!instrumentList3.Contains(current.id))
                {
                    instrumentList3.Add(current);
                    instrumentList2.Add(current);
                }
            }
            if (this.status == StrategyStatus.Running && instrumentList2.Count > 0 && this.framework.SubscriptionManager != null)
            {
                this.framework.SubscriptionManager.Subscribe(dataProvider, instrumentList2);
            }
        }
Exemple #18
0
 public OnUnsubscribe(InstrumentList instruments)
 {
     this.instruments = instruments;
 }
Exemple #19
0
 public OnSubscribe(InstrumentList instruments)
 {
     this.Instruments = instruments;
     this.dateTime1   = DateTime.MinValue;
     this.dateTime2   = DateTime.MaxValue;
 }
Exemple #20
0
 public virtual void Unsubscribe(InstrumentList instruments)
 {
     this.OnUnsubscribe(instruments);
 }
Exemple #21
0
 protected virtual void OnSubscribe(InstrumentList instruments)
 {
 }
Exemple #22
0
        public void StartStrategy(Strategy strategy, StrategyMode mode)
        {
            this.strategy = strategy;
            if (mode == StrategyMode.Backtest)
            {
                this.framework.Mode = FrameworkMode.Simulation;
            }
            else
            {
                this.framework.Mode = FrameworkMode.Realtime;
            }
            if (this.framework.eventManager.status != EventManagerStatus.Running)
            {
                this.framework.eventManager.Start();
            }
            StrategyStatusInfo strategyStatusInfo = new StrategyStatusInfo(this.framework.clock.DateTime, StrategyStatusType.Started);

            strategyStatusInfo.Solution = ((strategy.Name == null) ? "Solution" : strategy.Name);
            strategyStatusInfo.Mode     = mode.ToString();
            this.framework.eventServer.OnLog(new GroupEvent(strategyStatusInfo, null));
            strategy.OnStrategyStart_();
            if (!this.framework.IsExternalDataQueue)
            {
                Dictionary <IDataProvider, InstrumentList> dictionary = new Dictionary <IDataProvider, InstrumentList>();
                while (this.requests.Count != 0)
                {
                    Dictionary <IDataProvider, InstrumentList> dictionary2 = new Dictionary <IDataProvider, InstrumentList>(this.requests);
                    this.requests.Clear();
                    foreach (KeyValuePair <IDataProvider, InstrumentList> current in new Dictionary <IDataProvider, InstrumentList>(dictionary2))
                    {
                        InstrumentList instrumentList = null;
                        if (!dictionary.TryGetValue(current.Key, out instrumentList))
                        {
                            instrumentList          = new InstrumentList();
                            dictionary[current.Key] = instrumentList;
                        }
                        InstrumentList instrumentList2 = new InstrumentList();
                        foreach (Instrument current2 in current.Value)
                        {
                            if (!instrumentList.Contains(current2))
                            {
                                instrumentList.Add(current2);
                                instrumentList2.Add(current2);
                            }
                        }
                        if (current.Key is SellSideStrategy && this.framework.SubscriptionManager != null)
                        {
                            this.framework.SubscriptionManager.Subscribe(current.Key, instrumentList2);
                        }
                    }
                }
                this.status   = StrategyStatus.Running;
                this.requests = dictionary;
                if (this.requests.Count == 0)
                {
                    Console.WriteLine(string.Concat(new object[]
                    {
                        DateTime.Now,
                        " StrategyManager::StartStrategy ",
                        strategy.Name,
                        " has no data requests, stopping..."
                    }));
                    this.StopStrategy();
                    return;
                }
                foreach (KeyValuePair <IDataProvider, InstrumentList> current3 in this.requests)
                {
                    if (!(current3.Key is SellSideStrategy) && this.framework.SubscriptionManager != null)
                    {
                        this.framework.SubscriptionManager.Subscribe(current3.Key, current3.Value);
                    }
                }
            }
        }
Exemple #23
0
 public void Unsubscribe(InstrumentList instrument)
 {
     throw new System.NotImplementedException();
 }