コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        public bool RemoveSymbol(Symbol symbol)
        {
            ISourceDataDelivery delivery = _delivery;

            if (delivery != null)
            {
                RuntimeDataSessionInformation info = delivery.GetSymbolRuntimeSessionInformation(symbol);
                if (info == null)
                {
                    return(false);
                }

                delivery.SubscribeToData(info.Info, false, new DataSubscriptionInfo(true, false, null));
            }

            lock (this)
            {
                _symbolQuotes.Remove(symbol);
                if (_symbolQuotes.Count == 0)
                {// Release the delivery on last.
                    //_delivery.UnInitialize();
                    //_delivery.Dispose();
                    //_delivery = null;
                    _dataSourceId = null;
                }
            }

            return(true);
        }
コード例 #2
0
        void _dataDelivery_OperationalStatusChangedEvent(IOperational operational, OperationalStateEnum previousOperationState)
        {
            if (operational.OperationalState != OperationalStateEnum.Operational)
            {
                return;
            }

            // Re-map the session orderInfo.
            RuntimeDataSessionInformation information = _dataDelivery.GetSymbolRuntimeSessionInformation(_symbol);

            if (information == null)
            {
                SystemMonitor.OperationError("Failed to map session information for quote provider.");
                _sessionInfo = DataSessionInfo.Empty;
            }
            else
            {
                _sessionInfo = information.Info;

                if (_dataDelivery.SubscribeToData(_sessionInfo, true, new DataSubscriptionInfo(true, false, null)))
                {
                    RequestQuoteUpdate(false);
                }
            }
        }
コード例 #3
0
        public bool AddSymbol(ComponentId dataSourceId, Symbol symbol, out string operationResultMessage)
        {
            if (_dataSourceId.HasValue && _dataSourceId.Value != dataSourceId)
            {
                operationResultMessage = "One source per watch component currently supported.";
                SystemMonitor.Error(operationResultMessage);
                return(false);
            }

            _dataSourceId = dataSourceId;
            if (_delivery == null)
            {
                _delivery = base.ObtainDataDelivery(_dataSourceId.Value);
            }

            RuntimeDataSessionInformation info = _delivery.GetSymbolRuntimeSessionInformation(symbol);

            if (info == null)
            {
                operationResultMessage = "Failed to obtain symbol runtime session information.";
                return(false);
            }

            _delivery.SubscribeToData(info.Info, true, new DataSubscriptionInfo(true, false, null));
            _delivery.QuoteUpdateEvent += new QuoteUpdateDelegate(delivery_QuoteUpdateEvent);

            operationResultMessage = string.Empty;
            return(true);
        }
コード例 #4
0
        void _dataDelivery_OperationalStatusChangedEvent(IOperational operational, OperationalStateEnum previousOperationState)
        {
            if (operational.OperationalState != OperationalStateEnum.Operational)
            {
                return;
            }

            if (_sessionInfo.IsEmtpy)
            {
                SystemMonitor.OperationError("Data bar provider has no valid session assiged.");
                return;
            }

            // Re-map the session orderInfo.
            RuntimeDataSessionInformation information = _dataDelivery.GetSymbolRuntimeSessionInformation(_sessionInfo.Symbol);

            if (information == null)
            {
                SystemMonitor.OperationError("Failed to map session information for data provider.");
                _sessionInfo = DataSessionInfo.Empty;
                return;
            }
            else
            {
                _sessionInfo = information.Info;
            }

            if (_dataDelivery.SubscribeToData(_sessionInfo, true, new DataSubscriptionInfo(false, false, new TimeSpan[] { Period.Value })) == false)
            {
                SystemMonitor.OperationError("Failed to subscribe to bar data updates.");
                return;
            }

            RuntimeDataSessionInformation session = _dataDelivery.GetSymbolRuntimeSessionInformation(_sessionInfo.Symbol);

            if (session != null && session.AvailableDataBarPeriods.Contains(_period.Value))
            {
                _dataDelivery.RequestDataHistoryUpdate(_sessionInfo, new DataHistoryRequest(_period.Value, _defaultHistoryBarsCount), false);
            }
        }
コード例 #5
0
        void ConstructSourceDataBarProvider(TimeSpan period)
        {
            if (_sourceDataBarProvider == null)
            {
                if (_sourceDataDelivery.OperationalState != OperationalStateEnum.Operational)
                {
                    SystemMonitor.OperationError("Can not build data bar provider, source data delivery not ready.");
                    return;
                }

                if (_sourceDataDelivery.GetSymbolRuntimeSessionInformation(_sessionInfo.Symbol).AvailableDataBarPeriods.Contains(period) == false)
                {
                    SystemMonitor.OperationError("Can not build data bar provider, period not supported.");
                    return;
                }

                _period             = period;
                _timeControl.Period = period;

                _sourceDataBarProvider = new DataBarHistoryProvider(_sourceDataDelivery, _sessionInfo, period, 100000);

                _sourceDataBarProvider.DataBarHistoryUpdateEvent += new DataBarHistoryUpdateDelegate(_sourceDataBarProvider_DataBarHistoryUpdateEvent);
            }
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="period"></param>
        /// <returns></returns>
        public bool ObtainDataBarProvider(TimeSpan period)
        {
            lock (this)
            {
                RuntimeDataSessionInformation sessionInfo = _dataDelivery.GetSymbolRuntimeSessionInformation(SessionInfo.Symbol);

                if (sessionInfo == null)
                {
                    SystemMonitor.OperationError("Failed to retrieve runtime session information for symbol [" + SessionInfo.Symbol.Name + "].");
                    return(false);
                }

                if (false == sessionInfo.AvailableDataBarPeriods.Contains(period))
                {
                    SystemMonitor.OperationError("Period not available for data bar provider creation.");
                    return(false);
                }
            }

            IDataBarHistoryProvider provider;

            lock (this)
            {
                if (_dataBarProviders.ContainsKey(period))
                {
                    SystemMonitor.OperationError("Period data bar already created.");
                    return(false);
                }

                provider = _manager.ObtainDataBarHistoryProvider(_dataDelivery.SourceId,
                                                                 _sessionInfo.Symbol, period);

                _dataBarProviders.Add(period, provider);
            }

            if (_dataBarProvider == null)
            {
                SetCurrentDataBarProvider(period);
            }

            if (DataBarProviderCreatedEvent != null)
            {
                DataBarProviderCreatedEvent(this, provider);
            }

            return(true);
        }
コード例 #7
0
        public IQuoteProvider ObtainQuoteProvider(ComponentId source, Symbol symbol)
        {
            if (source.IsEmpty || symbol.IsEmpty)
            {
                SystemMonitor.Warning("Source or symbol empty.");
                return(null);
            }

            lock (this)
            {
                if (_quoteProviders.ContainsKey(source) &&
                    _quoteProviders[source].ContainsKey(symbol))
                {
                    return(_quoteProviders[source][symbol]);
                }
            }

            ISourceDataDelivery delivery = ObtainDataDelivery(source);

            if (delivery == null)
            {
                SystemMonitor.OperationError("Failed to establish data delivery for quote provider.");
                return(null);
            }

            RuntimeDataSessionInformation session = delivery.GetSymbolRuntimeSessionInformation(symbol);

            if (session == null)
            {
                SystemMonitor.OperationError("Failed to establish runtime session information for symbol [" + symbol.Name + "]");
                return(null);
            }

            QuoteProvider provider = new QuoteProvider(session.Info);

            // Make sure to *add before setting up* the initial paramters,
            // since a call from them can get back to this method, and cause a stack overflow.
            AddElement(source, symbol, provider);

            provider.SetInitialParameters(delivery);

            return(provider);
        }
コード例 #8
0
        public IDataBarHistoryProvider ObtainDataBarHistoryProvider(ComponentId source, Symbol symbol, TimeSpan period)
        {
            if (source.IsEmpty || symbol.IsEmpty)
            {
                SystemMonitor.Warning("Source or symbol empty.");
                return(null);
            }

            lock (this)
            {
                if (_dataBarProviders.ContainsKey(source) &&
                    _dataBarProviders[source].ContainsKey(symbol) &&
                    _dataBarProviders[source][symbol].ContainsKey(period))
                {
                    return(_dataBarProviders[source][symbol][period]);
                }
            }

            ISourceDataDelivery delivery = GetDataDelivery(source);

            if (delivery == null)
            {
                SystemMonitor.OperationError("Failed to establish data delivery for quote provider.");
                return(null);
            }

            RuntimeDataSessionInformation session = delivery.GetSymbolRuntimeSessionInformation(symbol);

            if (session == null)
            {
                SystemMonitor.OperationError("Failed to establish runtime session information for symbol [" + symbol.Name + "]");
            }

            DataBarHistoryProvider provider = new DataBarHistoryProvider(delivery, session.Info, period, null);

            // By default assign a volume indicator.
            provider.Indicators.AddIndicator(new VolumeCustom());

            AddElement(source, symbol, period, provider);

            return(provider);
        }
コード例 #9
0
        void _dataDelivery_OperationalStatusChangedEvent(IOperational operational, OperationalStateEnum previousOperationState)
        {
            if (operational.OperationalState != OperationalStateEnum.Operational)
            {
                return;
            }

            RuntimeDataSessionInformation info = _dataDelivery.GetSymbolRuntimeSessionInformation(_session.Symbol);

            if (info != null)
            {
                if (info.TickDataAvailabe)
                {
                    _dataDelivery.RequestDataHistoryUpdate(_session, new DataHistoryRequest(TimeSpan.Zero, null), false);
                }
            }
            else
            {
                SystemMonitor.OperationError("Failed to estblish runtime data session information.");
            }
        }
コード例 #10
0
        public IDataTickHistoryProvider ObtainDataTickHistoryProvider(ComponentId source, Symbol symbol)
        {
            if (source.IsEmpty || symbol.IsEmpty)
            {
                SystemMonitor.Warning("Source or symbol empty.");
                return(null);
            }

            lock (this)
            {
                if (_dataTickProviders.ContainsKey(source) &&
                    _dataTickProviders[source].ContainsKey(symbol))
                {
                    return(_dataTickProviders[source][symbol]);
                }
            }

            ISourceDataDelivery delivery = ObtainDataDelivery(source);

            if (delivery == null)
            {
                SystemMonitor.OperationError("Failed to establish data delivery for quote provider.");
                return(null);
            }

            RuntimeDataSessionInformation session = delivery.GetSymbolRuntimeSessionInformation(symbol);

            if (session == null)
            {
                SystemMonitor.OperationError("Failed to establish runtime session information for symbol [" + symbol.Name + "]");
                return(null);
            }

            DataTickHistoryProvider provider = new DataTickHistoryProvider(delivery, session.Info);

            AddElement(source, symbol, provider);

            return(provider);
        }
コード例 #11
0
        /// <summary>
        ///
        /// </summary>
        bool GetProviders(Symbol symbol, out IQuoteProvider quotes, out IDataBarHistoryProvider bars)
        {
            quotes = _manager.ObtainQuoteProvider(_dataDelivery.SourceId, symbol);
            RuntimeDataSessionInformation sessionInformation = _dataDelivery.GetSymbolRuntimeSessionInformation(symbol);

            if (sessionInformation.AvailableDataBarPeriods == null || sessionInformation.AvailableDataBarPeriods.Count == 0)
            {
                quotes = null;
                bars   = null;
                SystemMonitor.OperationError("Can not close order since no suitable data provider sessions found.");
                return(false);
            }

            bars = _manager.ObtainDataBarHistoryProvider(_dataDelivery.SourceId, symbol, sessionInformation.AvailableDataBarPeriods[0]);

            if (quotes == null || quotes.Ask.HasValue == false || bars == null)
            {
                return(false);
            }

            return(true);
        }
コード例 #12
0
        /// <summary>
        /// Get dataDelivery sessions for baseCurrency, source must be dataDelivery source.
        /// </summary>
        public DataSessionInfo?GetSymbolDataSessionInfo(ComponentId sourceId, Symbol symbol)
        {
            lock (_cachedDataSessions)
            {
                if (_cachedDataSessions.ContainsKey(sourceId) == false)
                {
                    _cachedDataSessions.Add(sourceId, new Dictionary <Symbol, DataSessionInfo?>());
                }

                if (_cachedDataSessions[sourceId].ContainsKey(symbol) == false)
                {
                    _cachedDataSessions[sourceId].Add(symbol, null);
                }
                else if (_cachedDataSessions[sourceId][symbol].HasValue)
                {
                    return(_cachedDataSessions[sourceId][symbol]);
                }
            }

            if (IsLocalSource(sourceId))
            {
                ISourceDataDelivery delivery = ObtainDataDelivery(sourceId);
                if (delivery == null)
                {
                    SystemMonitor.OperationError("Failed to establish local delivery.");
                    return(null);
                }

                RuntimeDataSessionInformation session = delivery.GetSymbolRuntimeSessionInformation(symbol);
                if (session == null)
                {
                    SystemMonitor.OperationError("Failed to establish symbol session [" + symbol.Name + "].");
                    return(null);
                }
                return(session.Info);
            }

            List <ArbiterClientId?> sourcePath;

            if (GetSourcePath(sourceId, out sourcePath) == false)
            {
                SystemMonitor.OperationError("Failed to establish source path.");
                return(null);
            }

            RequestSymbolsRuntimeInformationMessage request = new RequestSymbolsRuntimeInformationMessage(new Symbol[] { symbol });
            ResponceMessage responce = this.SendAndReceiveForwarding <ResponceMessage>(sourcePath, request);

            if (responce != null && responce.OperationResult)
            {
                SessionsRuntimeInformationMessage responceMessage = (SessionsRuntimeInformationMessage)responce;
                if (responceMessage.Informations.Count > 0)
                {
                    lock (_cachedDataSessions)
                    {
                        _cachedDataSessions[sourceId][symbol] = responceMessage.Informations[0].Info;
                    }

                    return(responceMessage.Informations[0].Info);
                }
            }

            return(null);
        }