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); } }
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); } }
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); }
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); } }
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); } }
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); } }
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); } } } }