public void UpdateDataHistory(DataSessionInfo session, DataHistoryUpdate update)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                SystemMonitor.Warning("Stub used while not operational, operation ignored.");
                return;
            }

            DataHistoryUpdateMessage message = new DataHistoryUpdateMessage(session, update, true);

            CombinedDataSubscriptionInformation combined;

            lock (this)
            {
                combined = GetUnsafeSessionSubscriptions(session);
            }

            lock (combined)
            {
                foreach (KeyValuePair <TransportInfo, DataSubscriptionInfo> info in combined.SubscriptionsUnsafe.Values)
                {
                    if (info.Value.AcceptsUpdate(update))
                    {
                        SendResponding(info.Key, message);
                    }
                }
            }
        }
        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);
        }
        /// <summary>
        /// 
        /// </summary>
        public DataTickHistoryProvider(ISourceDataDelivery dataDelivery, DataSessionInfo session)
        {
            _dataDelivery = dataDelivery;
            _session = session;

            Initialize();
        }
        /// <summary>
        /// The control only consumes dataDelivery provider, so that it is not available for sessionless operations too.
        /// </summary>
        public NewOrderControl(IQuoteProvider dataProvider, DataSessionInfo session, 
                    bool balancedPositionModeVisible, bool balancePositionModeChecked)
        {
            InitializeComponent();

            _dataProvider = dataProvider;
            if (_dataProvider != null)
            {
                _dataProvider.QuoteUpdateEvent += _dataProvider_OnValuesUpdateEvent;
            }

            _balancedPositionModeVisible = balancedPositionModeVisible;
            _balancePositionModeChecked = balancePositionModeChecked;

            _session = session;

            numericUpDownStopLoss.Increment = session.DecimalIncrement;
            numericUpDownStopLoss.DecimalPlaces = session.DecimalPlaces;

            numericUpDownSlippage.Increment = session.DecimalIncrement;
            numericUpDownSlippage.DecimalPlaces = session.DecimalPlaces;

            numericUpDownTakeProfit.Increment = session.DecimalIncrement;
            numericUpDownTakeProfit.DecimalPlaces = session.DecimalPlaces;

            numericUpDownPendingPrice.Increment = session.DecimalIncrement;
            numericUpDownPendingPrice.DecimalPlaces = session.DecimalPlaces;
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        bool DoAddEntry(DataStoreEntry entry)
        {
            entry.Initialize(_dataStoreFilesFolder);

            lock (_entriesAndSessions)
            {
                if (_entriesAndSessions.ContainsKey(entry))
                {
                    SystemMonitor.OperationWarning("Entry already added.");
                    return(false);
                }

                if (entry.Symbol.IsEmpty)
                {
                    SystemMonitor.Warning("Entry added before initialized.");
                    return(false);
                }

                // The sessionInformation reuses the entry Guid, so that it can be easily persisted further.
                DataSessionInfo entrySessionInfo = new DataSessionInfo(entry.Guid, "Data Store Session [" + entry.Symbol.Name + "]",
                                                                       entry.Symbol, DefaultSessionLotSize, entry.DecimalDigits);

                RuntimeDataSessionInformation session = new RuntimeDataSessionInformation(entrySessionInfo, entry.Period.Value);
                _entriesAndSessions.Add(entry, session);
            }

            return(true);
        }
        /// <summary>
        /// The control only consumes dataDelivery provider, so that it is not available for sessionless operations too.
        /// </summary>
        public NewOrderControl(IQuoteProvider dataProvider, DataSessionInfo session,
                               bool balancedPositionModeVisible, bool balancePositionModeChecked)
        {
            InitializeComponent();

            _dataProvider = dataProvider;
            if (_dataProvider != null)
            {
                _dataProvider.QuoteUpdateEvent += _dataProvider_OnValuesUpdateEvent;
            }

            _balancedPositionModeVisible = balancedPositionModeVisible;
            _balancePositionModeChecked  = balancePositionModeChecked;

            _session = session;

            numericUpDownStopLoss.Increment     = session.DecimalIncrement;
            numericUpDownStopLoss.DecimalPlaces = session.DecimalPlaces;

            numericUpDownSlippage.Increment     = session.DecimalIncrement;
            numericUpDownSlippage.DecimalPlaces = session.DecimalPlaces;

            numericUpDownTakeProfit.Increment     = session.DecimalIncrement;
            numericUpDownTakeProfit.DecimalPlaces = session.DecimalPlaces;

            numericUpDownPendingPrice.Increment     = session.DecimalIncrement;
            numericUpDownPendingPrice.DecimalPlaces = session.DecimalPlaces;
        }
        public void UpdateQuote(DataSessionInfo session, Quote?quote, TimeSpan?period)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                SystemMonitor.OperationWarning("Stub used while not operational, operation ignored.", TracerItem.PriorityEnum.Low);
                return;
            }

            QuoteUpdateMessage message = new QuoteUpdateMessage(session, quote, true);

            CombinedDataSubscriptionInformation combined;

            lock (this)
            {
                combined = GetUnsafeSessionSubscriptions(session);
            }

            bool hasActiveSubscriber = false;

            lock (combined)
            {
                foreach (KeyValuePair <TransportInfo, DataSubscriptionInfo> pair in combined.SubscriptionsUnsafe.Values)
                {
                    if (pair.Value.AcceptsUpdate(quote))
                    {
                        hasActiveSubscriber = true;
                        SendResponding(pair.Key, message);
                    }
                }
            }

            SystemMonitor.CheckOperationWarning(hasActiveSubscriber, "Quote update entered for session [" + session.Guid.ToString() + "] symbol [" + session.Symbol.Name + "] and no active subscriber found.");
        }
 /// <summary>
 /// Detailed constructor.
 /// </summary>
 public ModifyOrderControl(ModeEnum mode, ActiveOrder order)
 {
     InitializeComponent();
     _provider = order.OrderExecutionProvider;
     _mode = mode;
     _order = order;
     _dataProvider = order.QuoteProvider;
     _dataProvider.QuoteUpdateEvent += new QuoteProviderUpdateDelegate(_dataProvider_QuoteUpdateEvent);
     _session = order.SessionInfo.Value;
 }
Exemple #9
0
 /// <summary>
 /// Detailed constructor.
 /// </summary>
 public ModifyOrderControl(ModeEnum mode, Order order)
 {
     InitializeComponent();
     _provider     = order.OrderExecutionProvider;
     _mode         = mode;
     _order        = order;
     _dataProvider = order.QuoteProvider;
     _dataProvider.QuoteUpdateEvent += new QuoteProviderUpdateDelegate(_dataProvider_QuoteUpdateEvent);
     _session = order.SessionInfo.Value;
 }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        public void SessionDataSubscriptionUpdate(DataSessionInfo session, bool subscribe, DataSubscriptionInfo?info)
        {
            SystemMonitor.CheckError(session.IsEmtpy == false, "Method needs valid session info assigned to operate.");

            DataSourceStub dataSourceStub = DataSourceStub;

            if (dataSourceStub == null)
            {
                return;
            }

            CombinedDataSubscriptionInformation combined = dataSourceStub.GetUnsafeSessionSubscriptions(session);

            if (combined == null)
            {
                SystemMonitor.OperationError("Update on not existing session.");
                return;
            }

            MBTradingConnectionManager manager = _manager;

            if (manager == null)
            {
                return;
            }

            DataSubscriptionInfo combinedInfo = combined.GetCombinedDataSubscription();

            if (combinedInfo.QuoteSubscription)
            {
                if (manager.Adapter != null)
                {
                    manager.Quotes.SubscribeSymbolSession(session.Symbol,
                                                          Commission.GenerateSymbolCommission(manager.Adapter, session.Symbol));
                }
                else
                {
                    SystemMonitor.OperationError("Failed to perform data subscription update, since manager adapter not assigned.");
                }

                GeneralHelper.FireAndForget(delegate()
                {// Run an async update of quotes.
                    string market;
                    Quote?quote = _manager.Quotes.GetSingleSymbolQuote(session.Symbol.Name, TimeSpan.FromSeconds(10), out market);
                    if (quote.HasValue)
                    {
                        DataSourceStub.UpdateQuote(session, quote, null);
                    }
                });
            }
            else
            {
                manager.Quotes.UnSubscribeSymbolSession(session.Symbol.Name);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public override bool Initialize(DataSessionInfo? sessionInfo)
        {
            if (base.Initialize(sessionInfo) == false)
            {
                return false;
            }

            _mainChartSeries.Initialize(DataProvider, OrderExecutionProvider);

            return true;
        }
        public RuntimeDataSessionInformation GetSymbolRuntimeSessionInformation(Symbol symbol)
        {
            RuntimeDataSessionInformation info = _sourceDataDelivery.GetSymbolRuntimeSessionInformation(symbol);

            if (info != null)
            {// Session info changes on each run (symbol stays the same), so keep it updated.
                _sessionInfo = info.Info;
            }

            return(info);
        }
        void SendDataHistoryUpdate(TransportInfo[] receivers, DataSessionInfo session, DataHistoryRequest request)
        {
            DataSourceStub.IImplementation implementation = Implementation;
            if (implementation == null)
            {
                return;
            }

            DataHistoryUpdate responce = implementation.GetDataHistoryUpdate(session, request);

            SendRespondingToMany(receivers, new DataHistoryUpdateMessage(session, responce, responce != null));
        }
        void SendQuoteUpdate(TransportInfo[] receivers, DataSessionInfo session)
        {
            DataSourceStub.IImplementation implementation = Implementation;
            if (implementation == null)
            {
                return;
            }

            QuoteUpdateMessage message = new QuoteUpdateMessage(session, implementation.GetQuoteUpdate(session), true);

            SendRespondingToMany(receivers, message);
        }
        public bool SubscribeToData(DataSessionInfo session, bool subscribe, DataSubscriptionInfo info)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                return(false);
            }

            DataSubscriptionRequestMessage request  = new DataSubscriptionRequestMessage(session, subscribe, info);
            DataSessionResponseMessage     response = SendAndReceiveResponding <DataSessionResponseMessage>(SourceTransportInfo, request);

            return(response != null && response.OperationResult);
        }
        public bool SetInitialParameters(ISourceManager manager, ComponentId sourceSourceId, ExpertSession session)
        {
            _manager = manager;

            _sessionInfo = session.Info;

            _sourceDataDelivery = manager.ObtainDataDelivery(sourceSourceId);
            //_sourceDataDelivery.OperationalStateChangedEvent += new OperationalStateChangedDelegate(_sourceDataDelivery_OperationalStateChangedEvent);

            StatusSynchronizationSource = _sourceDataDelivery;

            return(true);
        }
Exemple #17
0
        /// <summary>
        /// Helper, gets an expert sessionInformation by its sessionInformation orderInfo.
        /// </summary>
        /// <param name="orderInfo"></param>
        /// <returns></returns>
        public ExpertSession GetExpertSession(DataSessionInfo info)
        {
            lock (this)
            {
                foreach (ExpertSession session in _sessions)
                {
                    if (session.Info.CompareTo(info) == 0)
                    {
                        return(session);
                    }
                }
            }

            return(null);
        }
        public Quote?GetQuoteUpdate(DataSessionInfo session)
        {
            MBTradingConnectionManager manager = _manager;

            if (manager != null)
            {
                MBTradingQuote.SessionQuoteInformation info = manager.Quotes.GetSymbolSessionInformation(session.Symbol.Name);
                if (info != null)
                {
                    return(info.Quote);
                }
            }

            return(null);
        }
Exemple #19
0
        public virtual ISessionDataProvider CreateRemoteExpertSession(DataSessionInfo info, ComponentId dataSourceId, ComponentId orderExecuteId)
        {
            string message = string.Empty;

            ExpertSession session = this.CreateExpertSession(info, dataSourceId, orderExecuteId, false, out message);

            if (session != null)
            {
                if (this.RegisterExpertSession(session))
                {
                    return(session.DataProvider);
                }
            }
            return(null);
        }
Exemple #20
0
        DragControl GetDragControlBySessionInfo(DataSessionInfo sessionInfo)
        {
            foreach (DragControl control in dragContainerControl1.DragControls)
            {
                if (control.ControlContained is PlatformExpertSessionControl)
                {
                    if (((PlatformExpertSessionControl)((DragControl)control).ControlContained).Session.Info.Equals(sessionInfo))
                    {
                        return(control);
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public DataBarHistoryProvider(ISourceDataDelivery dataDelivery, DataSessionInfo session, TimeSpan period, int? defaultHistoryBarsCount)
        {
            _sessionInfo = session;

            if (defaultHistoryBarsCount.HasValue)
            {
                _defaultHistoryBarsCount = defaultHistoryBarsCount.Value;
            }

            _dataDelivery = dataDelivery;
            _indicators = new IndicatorManager(this);
            _period = period;

            Construct();
        }
        public DataHistoryUpdate GetDataHistoryUpdate(DataSessionInfo session, DataHistoryRequest request)
        {
            if (request.Period != Period)
            {
                SystemMonitor.OperationWarning("Source queried for historic information of wrong period.");
                return null;
            }

            List<DataBar> bars = GetSymbolData(session.Symbol);
            if (bars != null)
            {
                return new DataHistoryUpdate(Period, bars);
            }

            return null;
        }
Exemple #23
0
        public DataHistoryUpdate GetDataHistoryUpdate(DataSessionInfo session, DataHistoryRequest request)
        {
            if (!IsPeriodSupported(request.Period))
            {
                SystemMonitor.OperationWarning("Source queried for historic information of wrong period.");
                return(null);
            }

            List <DataBar> bars = GetSymbolData(session.Symbol, request.Period);

            if (bars != null)
            {
                return(new DataHistoryUpdate(request.Period, bars));
            }

            return(null);
        }
        /// <summary>
        ///
        /// </summary>
        public RuntimeDataSessionInformation GetSymbolSessionRuntimeInformation(Symbol inputSymbol)
        {
            // Filter the baseCurrency trough its name and what symbols we know of.
            Symbol?knownSymbol = EstablishSymbolUsage(inputSymbol, TimeSpan.FromSeconds(6));

            if (knownSymbol.HasValue == false)
            {// Failed to start / establish symbol usage.
                return(null);
            }

            DataSessionInfo sessionInfo = new DataSessionInfo(Guid.NewGuid(), knownSymbol.Value.Name,
                                                              knownSymbol.Value, DefaultLotSize, 5);

            RuntimeDataSessionInformation session = new RuntimeDataSessionInformation(sessionInfo);

            session.AvailableDataBarPeriods.AddRange(DefaultAvailablePeriods);
            return(session);
        }
        public DataHistoryUpdate GetDataHistoryUpdate(DataSessionInfo session, DataHistoryRequest request)
        {
            if (request.IsTickBased)
            {
                SystemMonitor.NotImplementedWarning();
                return new DataHistoryUpdate(request.Period, new DataTick[] { });
            }

            if (request.Period != _period)
            {
                return new DataHistoryUpdate(request.Period, new DataBar[] { });
            }

            lock (this)
            {
                return new DataHistoryUpdate(request.Period, _history.ToArray());
            }
        }
Exemple #26
0
        public DataHistoryUpdate GetDataHistoryUpdate(DataSessionInfo session, DataHistoryRequest request)
        {
            if (request.IsTickBased)
            {
                SystemMonitor.NotImplementedWarning();
                return(new DataHistoryUpdate(request.Period, new DataTick[] { }));
            }

            if (request.Period != _period)
            {
                return(new DataHistoryUpdate(request.Period, new DataBar[] { }));
            }

            lock (this)
            {
                return(new DataHistoryUpdate(request.Period, _history.ToArray()));
            }
        }
Exemple #27
0
        /// <summary>
        ///
        /// </summary>
        public void SessionDataSubscriptionUpdate(DataSessionInfo session, bool subscribe, DataSubscriptionInfo?info)
        {
            SystemMonitor.CheckError(session.IsEmtpy == false, "Method needs valid session info assigned to operate.");

            DataSourceStub dataSourceStub = _dataSourceStub;

            if (dataSourceStub == null)
            {
                return;
            }

            CombinedDataSubscriptionInformation combined = dataSourceStub.GetUnsafeSessionSubscriptions(session);

            if (combined == null)
            {
                SystemMonitor.OperationError("Update of a non-existing session.");
                return;
            }
        }
Exemple #28
0
        public Quote?GetQuoteUpdate(DataSessionInfo session)
        {
            FXCMConnectionManager manager = Manager;

            if (manager != null && string.IsNullOrEmpty(session.Symbol.Name) == false)
            {
                object ask  = manager.GetInstrumentData(session.Symbol.Name, "Ask");
                object bid  = manager.GetInstrumentData(session.Symbol.Name, "Bid");
                object time = manager.GetInstrumentData(session.Symbol.Name, "Time");

                if (ask == null || bid == null || time == null)
                {
                    return(null);
                }

                return(new Quote((decimal)((double)ask), (decimal)((double)bid), null, (DateTime)time));
            }

            return(null);
        }
Exemple #29
0
        /// <summary>
        /// Obtain entry based on the sessionInformation orderInfo that corresponds to it.
        /// </summary>
        /// <param name="sessionInformation"></param>
        /// <returns></returns>
        public DataStoreEntry GetEntryBySessionInfo(DataSessionInfo sessionInfo)
        {
            DataStoreEntry entry = null;

            lock (_entriesAndSessions)
            {
                foreach (RuntimeDataSessionInformation information in _entriesAndSessions.Values)
                {
                    if (information.Info.Equals(sessionInfo))
                    {
                        if (_entriesAndSessions.GetByValueSafe(information, ref entry))
                        {
                            return(entry);
                        }
                    }
                }
            }

            return(null);
        }
        public bool RequestQuoteUpdate(DataSessionInfo sessionInfo, bool waitResult)
        {
            Quote?quote = null;

            lock (this)
            {
                if (_sourceDataBarProvider == null || _sourceDataBarProvider.BarCount == 0)
                {// No steps done yet.
                    return(true);
                }
            }

            lock (_sourceDataBarProvider)
            {
                if (_sourceDataBarProvider.BarCount < _step)
                {
                    SystemMonitor.Error("Unexpected case.");
                    return(false);
                }
                else
                {
                    if (_step - 1 >= 0 && _step - 1 < _sourceDataBarProvider.BarCount)
                    {
                        quote = new Quote(_sourceDataBarProvider.BarsUnsafe[_step - 1], _spreadPoints * _sessionInfo.DecimalIncrement);
                    }
                }
            }

            if (quote.HasValue == false)
            {// No dataDelivery.
                return(false);
            }

            if (QuoteUpdateEvent != null)
            {
                QuoteUpdateEvent(this, sessionInfo, quote);
            }

            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        public void SessionDataSubscriptionUpdate(DataSessionInfo session, bool subscribe, DataSubscriptionInfo?info)
        {
            SystemMonitor.CheckError(session.IsEmtpy == false, "Method needs valid session info assigned to operate.");

            DataSourceStub dataSourceStub = _dataSourceStub;

            if (dataSourceStub == null)
            {
                return;
            }

            CombinedDataSubscriptionInformation combined = dataSourceStub.GetUnsafeSessionSubscriptions(session);

            if (combined == null)
            {
                SystemMonitor.OperationError("Update on not existing session.");
                return;
            }

            DataSubscriptionInfo combinedInfo = combined.GetCombinedDataSubscription();

            if (combinedInfo.QuoteSubscription)
            {
                if (!_subscribedSymbols.ContainsKey(session.Symbol.Name))
                {
                    _subscribedSymbols.Add(session.Symbol.Name, session.Symbol);
                }
            }
            else
            {
                if (_subscribedSymbols.ContainsKey(session.Symbol.Name))
                {
                    _subscribedSymbols.Remove(session.Symbol.Name);
                }
            }
        }
        public DataHistoryUpdate GetDataHistoryUpdate(DataSessionInfo session, DataHistoryRequest request)
        {
            MBTradingConnectionManager manager = _manager;

            if (manager != null)
            {
                DataHistoryOperation operation = new DataHistoryOperation(session.Symbol.Name, request);
                if (manager.History.Place(operation) == false)
                {
                    SystemMonitor.OperationError("Failed to place data history operation.");
                    return(null);
                }

                if (operation.CompletionEvent.WaitOne(TimeSpan.FromSeconds(120)) == false)
                {
                    SystemMonitor.OperationError("Data history operation timed out.");
                    return(null);
                }

                return(operation.Responce);
            }

            return(null);
        }
        public CombinedDataSubscriptionInformation GetUnsafeSessionSubscriptions(DataSessionInfo session)
        {
            DataSourceStub.IImplementation implementation = Implementation;
            if (implementation == null)
            {
                return(null);
            }

            bool isSymbolRunningSession;

            lock (this)
            {
                isSymbolRunningSession = (_symbolsRunningSessions.ContainsKey(session.Symbol) == false);
            }

            if (isSymbolRunningSession)
            {
                SystemMonitor.OperationWarning("Received a request for unknow session, creating a new session.");
                // Make sure to leave the sessionInformation orderInfo request outside of locks.
                RuntimeDataSessionInformation sessionInformation = implementation.GetSymbolSessionRuntimeInformation(session.Symbol);
                lock (this)
                {
                    _symbolsRunningSessions.Add(sessionInformation.Info.Symbol, new CombinedDataSubscriptionInformation(sessionInformation));
                }
            }

            lock (this)
            {
                //if (_sessionsSubscriptions.ContainsKey(session) == false)
                //{
                //    _sessionsSubscriptions[session] = new CombinedDataSubscriptionInformation(session);
                //}

                return(_symbolsRunningSessions[session.Symbol]);
            }
        }
        public bool RequestDataHistoryUpdate(DataSessionInfo sessionInfo, DataHistoryRequest request, bool waitResult)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                return(false);
            }

            RequestDataHistoryMessage requestMessage = new RequestDataHistoryMessage(sessionInfo, request)
            {
                RequestResponse = false
            };

            requestMessage.RequestResponse = waitResult;
            if (waitResult)
            {
                ResponseMessage response = SendAndReceiveResponding <ResponseMessage>(SourceTransportInfo, requestMessage, this.DefaultTimeOut);
                return(response != null && response.OperationResult);
            }
            else
            {
                SendResponding(SourceTransportInfo, requestMessage);
                return(true);
            }
        }
        public bool RequestQuoteUpdate(DataSessionInfo sessionInfo, bool waitResult)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                return(false);
            }

            RequestQuoteUpdateMessage requestMessage = new RequestQuoteUpdateMessage(sessionInfo)
            {
                RequestResponce = false
            };

            requestMessage.RequestResponce = waitResult;
            if (waitResult)
            {
                ResponceMessage responce = SendAndReceiveResponding <ResponceMessage>(SourceTransportInfo, requestMessage);
                return(responce != null && responce.OperationResult);
            }
            else
            {
                SendResponding(SourceTransportInfo, requestMessage);
                return(true);
            }
        }
Exemple #36
0
        void delivery_QuoteUpdateEvent(ISourceDataDelivery dataDelivery, DataSessionInfo session, Quote?quote)
        {
            bool isUp = true;
            SymbolInformation information;

            lock (this)
            {
                if (_symbolQuotes.ContainsKey(session.Symbol) == false ||
                    _symbolQuotes[session.Symbol] == null)
                {
                    information = new SymbolInformation(session.Symbol);
                    _symbolQuotes.Add(session.Symbol, information);
                }
                else
                {
                    information = _symbolQuotes[session.Symbol];
                    if (information.Quote.HasValue && quote.HasValue)
                    {
                        if (information.Quote.Value.Ask == quote.Value.Ask &&
                            information.Quote.Value.Bid == quote.Value.Bid)
                        {
                            return;
                        }

                        isUp = information.Quote.Value.Ask < quote.Value.Ask;
                    }
                }

                information.Update(quote, isUp);
            }

            if (QuotesUpdateEvent != null)
            {
                QuotesUpdateEvent(this, information);
            }
        }
Exemple #37
0
        private void listViewOrders_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_sessionManager == null)
            {
                return;
            }

            if (SelectedOrderChangedEvent != null)
            {
                if (listViewOrders.SelectedItems.Count == 0)
                {
                    SelectedOrderChangedEvent(null, null);
                }
                else
                {
                    DataSessionInfo sessionInfo = ((DataSessionInfo?)listViewOrders.SelectedItems[0].Group.Tag).Value;
                    ExpertSession   session     = null;
                    foreach (ExpertSession sessionItem in _sessions)
                    {
                        if (sessionItem.Info.Equals(sessionInfo))
                        {
                            session = sessionItem;
                            break;
                        }
                    }

                    SystemMonitor.CheckError(session != null, "Session for this session info not found.");

                    Order order = listViewOrders.SelectedItems[0].Tag as Order;

                    SystemMonitor.CheckError(session.OrderExecutionProvider == null || session.OrderExecutionProvider.TradeEntities.ContainsOrder(order), "Wrong session for selected order.");

                    SelectedOrderChangedEvent(session, order);
                }
            }
        }
        /// <summary>
        /// Obtain entry based on the sessionInformation orderInfo that corresponds to it.
        /// </summary>
        /// <param name="sessionInformation"></param>
        /// <returns></returns>
        public DataStoreEntry GetEntryBySessionInfo(DataSessionInfo sessionInfo)
        {
            DataStoreEntry entry = null;
            lock (_entriesAndSessions)
            {
                foreach (RuntimeDataSessionInformation information in _entriesAndSessions.Values)
                {
                    if (information.Info.Equals(sessionInfo))
                    {
                        if (_entriesAndSessions.GetByValueSafe(information, ref entry))
                        {
                            return entry;
                        }
                    }
                }
            }

            return null;
        }
 protected virtual void dataDelivery_QuoteUpdateEvent(ISourceDataDelivery dataDelivery, DataSessionInfo session, Quote? quote)
 {
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="account"></param>
 public RequestQuoteUpdateMessage(DataSessionInfo sessionInfo)
     : base(sessionInfo)
 {
 }
        void SendDataHistoryUpdate(TransportInfo[] receivers, DataSessionInfo session, DataHistoryRequest request)
        {
            DataSourceStub.IImplementation implementation = Implementation;
            if (implementation == null)
            {
                return;
            }

            DataHistoryUpdate response = implementation.GetDataHistoryUpdate(session, request);
            SendRespondingToMany(receivers, new DataHistoryUpdateMessage(session, response, response != null));
        }
        public void UpdateDataHistory(DataSessionInfo session, DataHistoryUpdate update)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                SystemMonitor.Warning("Stub used while not operational, operation ignored.");
                return;
            }

            DataHistoryUpdateMessage message = new DataHistoryUpdateMessage(session, update, true);

            CombinedDataSubscriptionInformation combined;
            lock(this)
            {
                 combined = GetUnsafeSessionSubscriptions(session);
            }

            lock(combined)
            {
                foreach (KeyValuePair<TransportInfo, DataSubscriptionInfo> info in combined.SubscriptionsUnsafe.Values)
                {
                    if (info.Value.AcceptsUpdate(update))
                    {
                        SendResponding(info.Key, message);
                    }
                }
            }
        }
        public bool SetInitialParameters(ISourceManager manager, ComponentId sourceSourceId, ExpertSession session)
        {
            _manager = manager;

            _sessionInfo = session.Info;

            _sourceDataDelivery = manager.ObtainDataDelivery(sourceSourceId);
            //_sourceDataDelivery.OperationalStateChangedEvent += new OperationalStateChangedDelegate(_sourceDataDelivery_OperationalStateChangedEvent);

            StatusSynchronizationSource = _sourceDataDelivery;

            return true;
        }
        void delivery_QuoteUpdateEvent(ISourceDataDelivery dataDelivery, DataSessionInfo session, Quote? quote)
        {
            bool isUp = true;
            SymbolInformation information;
            lock (this)
            {
                if (_symbolQuotes.ContainsKey(session.Symbol) == false
                    || _symbolQuotes[session.Symbol] == null)
                {
                    information = new SymbolInformation(session.Symbol);
                    _symbolQuotes.Add(session.Symbol, information);
                }
                else
                {
                    information = _symbolQuotes[session.Symbol];
                    if (information.Quote.HasValue && quote.HasValue)
                    {
                        if (information.Quote.Value.Ask == quote.Value.Ask
                            && information.Quote.Value.Bid == quote.Value.Bid)
                        {
                            return;
                        }

                        isUp = information.Quote.Value.Ask < quote.Value.Ask;
                    }
                }

                information.Update(quote, isUp);
            }

            if (QuotesUpdateEvent != null)
            {
                QuotesUpdateEvent(this, information);
            }
        }
 /// <summary>
 /// 
 /// </summary>
 public DataSubscriptionRequestMessage(DataSessionInfo sessionInfo, bool subscribe, DataSubscriptionInfo? info)
     : base(sessionInfo)
 {
     _information = info;
     _subscribe = subscribe;
 }
        public CombinedDataSubscriptionInformation GetUnsafeSessionSubscriptions(DataSessionInfo session)
        {
            DataSourceStub.IImplementation implementation = Implementation;
            if (implementation == null)
            {
                return null;
            }

            bool isSymbolRunningSession;
            lock (this)
            {
                isSymbolRunningSession = (_symbolsRunningSessions.ContainsKey(session.Symbol) == false);
            }

            if (isSymbolRunningSession)
            {
                SystemMonitor.OperationWarning("Received a request for unknow session, creating a new session.");
                // Make sure to leave the sessionInformation orderInfo request outside of locks.
                RuntimeDataSessionInformation sessionInformation = implementation.GetSymbolSessionRuntimeInformation(session.Symbol);
                lock (this)
                {
                    _symbolsRunningSessions.Add(sessionInformation.Info.Symbol, new CombinedDataSubscriptionInformation(sessionInformation));
                }
            }

            lock (this)
            {
                //if (_sessionsSubscriptions.ContainsKey(session) == false)
                //{
                //    _sessionsSubscriptions[session] = new CombinedDataSubscriptionInformation(session);
                //}

                return _symbolsRunningSessions[session.Symbol];
            }
        }
 /// <summary>
 /// 
 /// </summary>
 public DataHistoryUpdateMessage(DataSessionInfo session, DataHistoryUpdate update, bool operationResult)
     : base(session, operationResult)
 {
     _update = update;
 }
 /// <summary>
 /// 
 /// </summary>
 public DataSessionRequestMessage(DataSessionInfo sessionInfo)
 {
     _sessionInfo = sessionInfo;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        bool DoAddEntry(DataStoreEntry entry)
        {
            entry.Initialize(_dataStoreFilesFolder);

            lock(_entriesAndSessions)
            {
                if (_entriesAndSessions.ContainsKey(entry))
                {
                    SystemMonitor.OperationWarning("Entry already added.");
                    return false;
                }

                if (entry.Symbol.IsEmpty)
                {
                    SystemMonitor.Warning("Entry added before initialized.");
                    return false;
                }

                // The sessionInformation reuses the entry Guid, so that it can be easily persisted further.
                DataSessionInfo entrySessionInfo = new DataSessionInfo(entry.Guid, "Data Store Session [" + entry.Symbol.Name + "]",
                    entry.Symbol, DefaultSessionLotSize, entry.DecimalDigits);

                RuntimeDataSessionInformation session = new RuntimeDataSessionInformation(entrySessionInfo, entry.Period.Value);
                _entriesAndSessions.Add(entry, session);
            }

            return true;
        }
        /// <summary>
        /// 
        /// </summary>
        public bool RequestDataHistoryUpdate(DataSessionInfo sessionInfo, DataHistoryRequest request, bool waitResult)
        {
            if (_sourceDataBarProvider == null)
            {
                ConstructSourceDataBarProvider(request.Period);
                //SystemMonitor.Warning("Source data bar provider not created yet.");
                return true;
            }

            if (request.StartIndex.HasValue == false)
            {
                request.StartIndex = -1;
            }

            if (request.MaxValuesRetrieved.HasValue == false)
            {
                request.MaxValuesRetrieved = int.MaxValue;
            }

            if (request.Period != _sourceDataBarProvider.Period)
            {
                SystemMonitor.NotImplementedCritical("Mode not supported.");
                return false;
            }

            if (request.IsTickBased)
            {
                SystemMonitor.NotImplementedCritical("Mode not supported.");
                return false;
            }

            List<DataBar> bars = new List<DataBar>();
            if (request.StartIndex < 0)
            {
                for (int i = Math.Max(0, _sourceDataBarProvider.BarCount - request.MaxValuesRetrieved.Value);
                    i < _sourceDataBarProvider.BarCount; i++)
                {
                    lock (_sourceDataBarProvider)
                    {
                        bars.Add(_sourceDataBarProvider.BarsUnsafe[i]);
                    }
                }
            }
            else
            {
                for (int i = request.StartIndex.Value;
                    i < request.MaxValuesRetrieved && i < _sourceDataBarProvider.BarCount; i++)
                {
                    lock (_sourceDataBarProvider)
                    {
                        bars.Add(_sourceDataBarProvider.BarsUnsafe[i]);
                    }
                }
            }

            if (this.DataHistoryUpdateEvent != null)
            {
                this.DataHistoryUpdateEvent(this, sessionInfo, new DataHistoryUpdate(request.Period, bars));
            }

            return true;
        }
        void SendQuoteUpdate(TransportInfo[] receivers, DataSessionInfo session)
        {
            DataSourceStub.IImplementation implementation = Implementation;
            if (implementation == null)
            {
                return;
            }

            QuoteUpdateMessage message = new QuoteUpdateMessage(session,  implementation.GetQuoteUpdate(session), true);
            SendRespondingToMany(receivers, message);
        }
 public Quote? GetQuoteUpdate(DataSessionInfo session)
 {
     // No quotes from this provider.
     return null;
 }
        public RuntimeDataSessionInformation GetSymbolRuntimeSessionInformation(Symbol symbol)
        {
            RuntimeDataSessionInformation info = _sourceDataDelivery.GetSymbolRuntimeSessionInformation(symbol);

            if (info != null)
            {// Session info changes on each run (symbol stays the same), so keep it updated.
                _sessionInfo = info.Info;
            }

            return info;
        }
        public void UpdateQuote(DataSessionInfo session, Quote? quote, TimeSpan? period)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                SystemMonitor.OperationWarning("Stub used while not operational, operation ignored.", TracerItem.PriorityEnum.Low);
                return;
            }

            QuoteUpdateMessage message = new QuoteUpdateMessage(session, quote, true);

            CombinedDataSubscriptionInformation combined;
            lock(this)
            {
                 combined = GetUnsafeSessionSubscriptions(session);
            }

            bool hasActiveSubscriber = false;

            lock(combined)
            {
                foreach (KeyValuePair<TransportInfo, DataSubscriptionInfo> pair in combined.SubscriptionsUnsafe.Values)
                {
                    if (pair.Value.AcceptsUpdate(quote))
                    {
                        hasActiveSubscriber = true;
                        SendResponding(pair.Key, message);
                    }
                }
            }

            if (hasActiveSubscriber == false)
            {
                SystemMonitor.Report("Quote update entered for session [" + session.Guid.ToString() + "] symbol [" + session.Symbol.Name + "] and no active subscriber found.");
            }
        }
        public bool RequestQuoteUpdate(DataSessionInfo sessionInfo, bool waitResult)
        {
            Quote? quote = null;
            lock (this)
            {
                if (_sourceDataBarProvider == null || _sourceDataBarProvider.BarCount == 0)
                {// No steps done yet.
                    return true;
                }

            }

            lock (_sourceDataBarProvider)
            {
                if (_sourceDataBarProvider.BarCount < _step)
                {
                    SystemMonitor.Error("Unexpected case.");
                    return false;
                }
                else
                {
                    if (_step - 1 >= 0 && _step - 1 < _sourceDataBarProvider.BarCount)
                    {
                        quote = new Quote(_sourceDataBarProvider.BarsUnsafe[_step - 1], _spreadPoints * _sessionInfo.DecimalIncrement);
                    }
                }
            }

            if (quote.HasValue == false)
            {// No dataDelivery.
                return false;
            }

            if (QuoteUpdateEvent != null)
            {
                QuoteUpdateEvent(this, sessionInfo, quote);
            }

            return true;
        }
 public Quote? GetQuoteUpdate(DataSessionInfo session)
 {
     return new Quote(LastBar.Open, LastBar.Close, null, null);
 }
 public bool SubscribeToData(DataSessionInfo session, bool subscribe, DataSubscriptionInfo subscription)
 {
     return _sourceDataDelivery.SubscribeToData(session, subscribe, subscription);
 }
 /// <summary>
 /// Full constructor.
 /// </summary>
 public QuoteUpdateMessage(DataSessionInfo sessionInfo, Quote? quote, bool operationResult)
     : base(sessionInfo, operationResult)
 {
     _quote = quote;
 }
 public void SessionDataSubscriptionUpdate(DataSessionInfo session, bool subscribe, DataSubscriptionInfo? info)
 {
 }
 /// <summary>
 /// 
 /// </summary>
 public DataSessionResponseMessage(DataSessionInfo sessionInfo, bool operationResult)
     : base(operationResult)
 {
     _sessionInfo = sessionInfo;
 }