/// <summary> /// Prepare the object for operation. Access to this allows externals to use the 2 /// step component registration process. /// Called to bring up a component for operation. Does not add the component /// permanently to the platform. /// </summary> public bool InitializeComponent(PlatformComponent component) { TracerHelper.Trace(component.Name); try { if (component.IsInitialized == false) { Arbiter.AddClient(component); // This allows the component to persist while initializing. component.PersistenceDataUpdatedEvent += new GeneralHelper.GenericDelegate <IDBPersistent>(HandleComponentPersistenceDataUpdatedEvent); } if (component.IsInitialized || component.Initialize(this)) { return(true); } } catch (Exception ex) { SystemMonitor.Error(string.Format("Exception occured during initializing component [{0}, {1}]", component.Name, ex.Message)); } // Failed to initialize component. component.PersistenceDataUpdatedEvent -= new GeneralHelper.GenericDelegate <IDBPersistent>(HandleComponentPersistenceDataUpdatedEvent); Arbiter.RemoveClient(component); return(false); }
/// <summary> /// Source is starting. /// </summary> /// <param name="platform"></param> /// <returns></returns> protected override bool OnInitialize(Platform platform) { Arbiter.AddClient(_dataStub); ChangeOperationalState(OperationalStateEnum.Operational); return(true); }
void Adapters_ItemAddedEvent(GenericContainer <IIntegrationAdapter> keeper, IIntegrationAdapter adapter) { adapter.PersistenceDataUpdateEvent += new IntegrationAdapterUpdateDelegate(adapter_PersistenceDataUpdateEvent); if (Arbiter != null) { Arbiter.AddClient(adapter); } if (OperationalState != OperationalStateEnum.Unknown) { RaisePersistenceDataUpdatedEvent(); } }
/// <summary> /// Create a dataDelivery delivery component, corresponding to the given sourceSourceId and account /// </summary> /// <param name="sourceSourceId"></param> /// <param name="account"></param> /// <returns></returns> protected ISourceDataDelivery CreateDataDelivery(ComponentId sourceId) { if (sourceId == _dataStoreSourceInfo.ComponentId) { List <PlatformComponent> components = Platform.GetComponentsByType(typeof(DataStoreManagementComponent)); if (components.Count == 0) { SystemMonitor.Error("Failed to find data store management component."); return(null); } DataStoreDataDelivery delivery = new DataStoreDataDelivery(_dataStoreSourceInfo.ComponentId); if (delivery.Initialize() == false) { SystemMonitor.OperationError("Failed to initialize data store data delivery."); return(null); } return(delivery); } SourceInfo?sourceInfo = GetSourceInfo(sourceId, SourceTypeEnum.DataProvider); if (sourceInfo.HasValue == false) { SystemMonitor.OperationError("Source info not found for source [" + sourceId.Print() + "].", TracerItem.PriorityEnum.High); return(null); } if ((sourceInfo.Value.SourceType & SourceTypeEnum.DataProvider) == 0) { SystemMonitor.OperationError("Can not create data delivery to source that does not implement data provider [" + sourceId.Print() + "].", TracerItem.PriorityEnum.Critical); return(null); } TransportInfo info = GetSourceTransportInfoToMe(sourceId); if (info == null) { return(null); } // This is a remote dataDelivery source, create a corresponding delivery. DataSourceClientStub stubDelivery = new DataSourceClientStub(); Arbiter.AddClient(stubDelivery); stubDelivery.SetInitialParameters(sourceId, info); return(stubDelivery); }
/// <summary> /// /// </summary> protected bool InitializeSources() { if (Arbiter != null && _dataSourceStub != null) { Arbiter.AddClient(_dataSourceStub); } if (Arbiter != null && _orderExecutionStub != null) { Arbiter.AddClient(_orderExecutionStub); } SystemMonitor.CheckError(Arbiter != null, "Arbiter must be assigned to start sources."); return(true); }
protected override bool OnInitialize(Platform platform) { string symbolsFile = _filesFolder + "//" + YahooStockSymbolsFileName; if (File.Exists(symbolsFile) == false) { SystemMonitor.Error("Failed to initialize " + this.GetType().Name + " [Symbols file not found: " + symbolsFile + "]"); return(false); } ChangeOperationalState(OperationalStateEnum.Operational); Arbiter.AddClient(_dataSourceStub); GeneralHelper.FireAndForget(LoadSymbols); return(true); }
/// <summary> /// /// </summary> /// <param name="platform"></param> /// <returns></returns> protected override bool OnInitialize(Platform platform) { if (base.OnInitialize(platform) == false) { return(false); } ChangeOperationalState(OperationalStateEnum.Operational); // Make sure to add them instantly since initial subscriptions and requests may start very soon. // We can not wait for the fire and forget to perform for that. foreach (IIntegrationAdapter adapter in Adapters.ToArray()) { Arbiter.AddClient(adapter); } GeneralHelper.FireAndForget(delegate() {// Begin starting the adapters, once they are added to the Arbiter and ready to begin operation. foreach (IIntegrationAdapter adapter in Adapters.ToArray()) { bool mustStart; lock (this) { mustStart = _startedAdaptersIds.Contains(adapter.SubscriptionClientID.Id); } if (mustStart) { string operationResultMessage; adapter.Start(out operationResultMessage); } } lock (this) { _startedAdaptersIds.Clear(); } }); return(true); }
public bool Start(out string operationResultMessage) {// This will start the integration client. if (Arbiter == null) { operationResultMessage = "Arbiter not assigned."; return(false); } if (IsStarted) { operationResultMessage = "Adapter already started."; return(false); } if (_integrationClient == null) { _integrationClient = new TransportIntegrationClient(_integrationUri); } if (_integrationClient != null && _integrationClientId.IsEmpty == false) { _integrationClient.SetArbiterSubscriptionClientId(_integrationClientId); } _integrationClient.MandatoryRequestMessageReceiverID = this.SubscriptionClientID; _integrationClient.ConnectionStatusChangedEvent += new TransportIntegrationClient.ConnectionStatusChangedDelegate(_integrationClient_ConnectionStatusChangedEvent); Arbiter.AddClient(_integrationClient); _integrationClientId = _integrationClient.SubscriptionClientID; _isStarted = true; ChangeOperationalState(OperationalStateEnum.Initialized); operationResultMessage = string.Empty; return(true); }
/// <summary> /// Create an execution provider to match the given sourceSourceId. /// </summary> /// <param name="sourceSourceId"></param> /// <param name="account"></param> /// <returns></returns> public ISourceOrderExecution CreateExecutionProvider(ComponentId sourceId, ComponentId dataSourceId) { SourceTypeEnum?mode = GetSourceTypeFlags(sourceId, SourceTypeEnum.OrderExecution); if (sourceId == _backtestingExecutionSourceInfo.ComponentId) { BackTestOrderExecutionProvider provider = new BackTestOrderExecutionProvider(sourceId); if (provider.SetInitialParameters(this, ObtainDataDelivery(dataSourceId)) == false) { SystemMonitor.OperationError("Failed to initialize backtesting data provider."); return(null); } return(provider); } else { SourceInfo?sourceInfo = GetSourceInfo(sourceId, SourceTypeEnum.OrderExecution); if (sourceInfo.HasValue == false) { SystemMonitor.OperationError("Source info not found for source [" + sourceId.Print() + "].", TracerItem.PriorityEnum.High); return(null); } if ((sourceInfo.Value.SourceType & SourceTypeEnum.OrderExecution) == 0) { SystemMonitor.OperationError("Can not create order execution to source that does not implement data provider [" + sourceId.Print() + "].", TracerItem.PriorityEnum.Critical); return(null); } PlatformSourceOrderExecutionProvider platformExecutionProvider = new PlatformSourceOrderExecutionProvider(); Arbiter.AddClient(platformExecutionProvider); platformExecutionProvider.SetInitialParameters(this, sourceId, dataSourceId); return(platformExecutionProvider); } }