Example #1
0
        /// <summary>
        /// On timer timeout send a newly generated bar to receivers.
        /// </summary>
        public void TimerTimeout(object source, System.Timers.ElapsedEventArgs e)
        {
            GenerateNextRandomBar();

            CombinedDataSubscriptionInformation info = _dataSourceStub.GetUnsafeSessionSubscriptions(_sessionInformation.Info);

            if (info != null && info.GetCombinedDataSubscription().QuoteSubscription)
            {
                _dataSourceStub.UpdateQuote(_sessionInformation.Info, new Quote(LastBar.Open, LastBar.Open - 0.002m, null, DateTime.Now), null);
                _dataSourceStub.UpdateDataHistory(_sessionInformation.Info, new DataHistoryUpdate(_period, new DataBar[] { LastBar }));
            }

            if (OperationalState != OperationalStateEnum.UnInitialized &&
                OperationalState != OperationalStateEnum.Disposed)
            {
                _liveDataTimer.Start();
            }
        }
        public bool InitializeIntegrationSession(string symbol, 
            decimal modePoint, decimal modeDigits, decimal modeSpread, decimal modeStopLevel, decimal modeLotSize, decimal modeTickValue,
            decimal modeTickSize, decimal modeSwapLong, decimal modeSwapShort, decimal modeStarting, decimal modeExpiration,
            decimal modeTradeAllowed, decimal modeMinLot, decimal modeLotStep, decimal modeMaxLot, decimal modeSwapType,
            decimal modeProfitCalcMode, decimal modeMarginCalcMode, decimal modeMarginInit, decimal modeMarginMaintenance,
            decimal modeMarginHedged, decimal modeMarginRequired, decimal modeFreezeLevel)
        {
            TracerHelper.Trace(symbol);
            CombinedDataSubscriptionInformation session = GetDataSession(symbol);

            if (session == null)
            {
                DataSessionInfo sessionInfo = new DataSessionInfo(Guid.NewGuid(), symbol,
                    CreateSymbol(symbol), modeLotSize, (int)modeDigits);

                RuntimeDataSessionInformation runtimeSession = new RuntimeDataSessionInformation(sessionInfo);

                session = new CombinedDataSubscriptionInformation(runtimeSession);

                lock (this)
                {
                    _dataSessions.Add(sessionInfo.Symbol, session);
                }
            }

            return true;
        }
        protected virtual DataSubscriptionResponceMessage Receive(DataSubscriptionRequestMessage message)
        {
            if (message.TransportInfo.OriginalSenderId.HasValue == false)
            {
                SystemMonitor.Error("Received a message with no original sender. Dropped.");
                return(null);
            }

            DataSourceStub.IImplementation implementation = Implementation;
            if (message.SessionInfo.IsEmtpy)
            {// General (un)subscription requestMessage, not specific to a sessionInformation.
                if (message.Subscribe)
                {
                    SystemMonitor.OperationError("Unexpected combination of empty session and subscribe request, ignored.");
                }
                else
                {// Unsubscribe to each that has a orderInfo for this original sender.
                    lock (this)
                    {
                        foreach (CombinedDataSubscriptionInformation combined in _symbolsRunningSessions.Values)
                        {
                            if (combined.FullUnsubscribe(message.TransportInfo.OriginalSenderId.Value))
                            {// For every sessionInformation that has something
                                // Make sure to pass combined as parameter, otherwise the value is in foreach and chages before the thread starts.
                                GeneralHelper.FireAndForget(
                                    delegate(CombinedDataSubscriptionInformation combinedValue)
                                {
                                    if (implementation != null)
                                    {// First allow the implementation to unsubscribe since it needs the combined dataDelivery.
                                        implementation.SessionDataSubscriptionUpdate(combinedValue.SessionInformation.Info, message.Subscribe, message.Information);
                                    }
                                }, combined);
                            }
                        }
                    }
                }
            }
            else
            {
                if (_symbolsRunningSessions.ContainsKey(message.SessionInfo.Symbol) == false ||
                    _symbolsRunningSessions[message.SessionInfo.Symbol].SessionInformation.Info.Equals(message.SessionInfo) == false)
                {
                    SystemMonitor.Warning("Subsribe request for non existing session.");
                    return(new DataSubscriptionResponceMessage(message.SessionInfo, false));
                }

                CombinedDataSubscriptionInformation combined = GetUnsafeSessionSubscriptions(message.SessionInfo);
                if (combined != null)
                {
                    combined.HandleRequest(message.TransportInfo, message.Subscribe, message.Information);
                    if (implementation != null)
                    {
                        GeneralHelper.FireAndForget(delegate()
                        {
                            implementation.SessionDataSubscriptionUpdate(message.SessionInfo, message.Subscribe, message.Information);
                        });
                    }
                }
                else
                {
                    SystemMonitor.OperationError("Combined subscription info not found.");
                }
            }

            // Finalizing / responding section.
            if (message.RequestResponce)
            {
                return(new DataSubscriptionResponceMessage(message.SessionInfo, true));
            }

            return(null);
        }
        void SendToDataSubscribers(CombinedDataSubscriptionInformation session, QuoteUpdateMessage quoteMessage,  
            DataHistoryUpdateMessage updateMessage)
        {
            TracerHelper.TraceEntry();

            lock (this)
            {
                // TODO: make sure proper subscription based filtering is applied here too.
                foreach (KeyValuePair<TransportInfo, DataSubscriptionInfo> pair in session.SubscriptionsUnsafe.Values)
                {

                    if (quoteMessage != null && pair.Value.AcceptsUpdate(quoteMessage.Quote))
                    {
                        TracerHelper.Trace("Sending [" + quoteMessage.GetType().Name + "] to [" + pair.Key.OriginalSenderId.Value.Id.Name + "].");
                        SendResponding(pair.Key, quoteMessage);
                    }

                    if (updateMessage != null && pair.Value.AcceptsUpdate(updateMessage.Update))
                    {
                        TracerHelper.Trace("Sending [" + updateMessage.GetType().Name + "] to [" + pair.Key.OriginalSenderId.Value.Id.Name + "].");
                        SendResponding(pair.Key, updateMessage);
                    }
                }
            }
        }