예제 #1
0
        /// <summary>
        ///
        /// </summary>
        public void UnRegisterExpertSession(ExpertSession session)
        {
            lock (this)
            {
                if (SessionDestroyingEvent != null)
                {
                    SessionDestroyingEvent(this, session);
                }

                if (session.OperationalState == OperationalStateEnum.Operational ||
                    session.OperationalState == OperationalStateEnum.Initialized)
                {
                    SystemMonitor.CheckError(Arbiter != null, "Make sure entering here only when the entire host is still valid and only a session needs to be destroyed.");
                    ((PlatformExpertSession)session).UnInitialize();
                }

                session.Dispose();

                _sessions.Remove((PlatformExpertSession)session);
            }

            if (SessionDestroyedEvent != null)
            {
                SessionDestroyedEvent(this, session);
            }

            if (SessionsUpdateEvent != null)
            {
                SessionsUpdateEvent(this);
            }
        }
        public bool RemoveAssembly(Assembly assembly)
        {
            lock (this)
            {
                if (_expertContainingAssembliesAndPaths.ContainsKey(assembly) == false)
                {
                    SystemMonitor.Error("Failed to remove assembly [" + assembly.FullName + "]");
                    return(false);
                }

                SystemMonitor.CheckError(_expertContainingAssembliesAndPaths.Remove(assembly));

                foreach (ExpertInformation container in GeneralHelper.EnumerableToArray <ExpertInformation>(_expertInfos))
                {
                    if (container.ContainingAssembly == assembly)
                    {
                        RemoveExpert(container);
                    }
                }
            }

            if (ExpertAssemblyRemovedEvent != null)
            {
                ExpertAssemblyRemovedEvent(assembly);
            }
            return(true);
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            toolStripAdditional.Visible = false;

            ordersControlExpertSession.AllowOrderManagement = true;

            // Move all the items from the additional toolstrip to the one on the expertSessionControl.
            List <ToolStripItem> additionalItems = new List <ToolStripItem>();

            foreach (ToolStripItem item in toolStripAdditional.Items)
            {
                additionalItems.Add(item);
            }

            for (int i = additionalItems.Count - 1; i >= 0; i--)
            {
                expertSessionControl.toolStripMain.Items.Insert(0, additionalItems[i]);
            }

            // Checks.
            SystemMonitor.CheckError(this.Parent is ExpertHostControl);

            // Match orders control and chart orders.
            expertSessionControl.CorrespondingOrdersControl = ordersControlExpertSession;
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        protected override void OnRecalculateParameters(ISourceOrderExecution provider, bool fullRecalculation)
        {
            SystemMonitor.CheckError(provider.SupportsActiveOrderManagement, "Wrong position type for this provider.");

            Order[] orders = provider.TradeEntities.GetOrdersBySymbol(Symbol);
            lock (this)
            {
                _info.Volume            = 0;
                _info.PendingBuyVolume  = 0;
                _info.PendingSellVolume = 0;
                _info.Result            = 0;

                foreach (ActiveOrder order in GeneralHelper.SafeChildTypeIteration <Order, ActiveOrder>(orders))
                {
                    if (order.State == OrderStateEnum.Executed)
                    {
                        _info.Volume += order.CurrentDirectionalVolume;
                        _info.Result += order.GetResult(Order.ResultModeEnum.Currency);
                    }
                    else if (order.State == OrderStateEnum.Submitted)
                    {
                        if (order.IsBuy)
                        {
                            _info.PendingBuyVolume += order.CurrentVolume;
                        }
                        else
                        {
                            _info.PendingSellVolume += order.CurrentVolume;
                        }
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Places and tries to execute a market order synchronously. Since it might be a modification of an
        /// existing active order, no specific order Id is returned - instead a bool indicating operation result.
        /// </summary>
        /// <param name="manipulateExistingOrders">[where applicable] Is the operation allowed to close a matching existing order, or should we always open a new one. This is suitable for Active orders brokers, that dissallow hedged orders at the same time.</param>
        public string ExecuteMarket(OrderTypeEnum orderType, int volume, decimal?price, decimal?slippage,
                                    decimal?takeProfit, decimal?stopLoss, TimeSpan timeOut, out PositionExecutionInfo executionInfo,
                                    out string operationResultMessage)
        {
            operationResultMessage = string.Empty;
            executionInfo          = PositionExecutionInfo.Empty;

            ISourceOrderExecution provider = _orderProvider;

            if (provider == null || provider.DefaultAccount == null)
            {
                operationResultMessage = "Position not properly initialized.";
                return(string.Empty);
            }

            // Trace pre-execution info.
            string traceMessage = string.Format("Submit Type[{0}] Volume [{1}] Price [{2}] Slippage [{3}] TP [{4}] SL [{5}] TimeOut [{6}]", orderType.ToString(),
                                                volume.ToString(), GeneralHelper.ToString(price), GeneralHelper.ToString(slippage), GeneralHelper.ToString(takeProfit),
                                                GeneralHelper.ToString(stopLoss), timeOut.ToString());

            traceMessage += GenerateConditionsInfo();

            TracerHelper.Trace(_tracer, traceMessage, TracerItem.PriorityEnum.High);

            _isProcessing = true;

            string result = OnExecuteMarket(provider, orderType, volume, price, slippage, takeProfit, stopLoss, timeOut,
                                            out executionInfo, out operationResultMessage);

            SystemMonitor.CheckError(result == executionInfo.ExecutionId, operationResultMessage);

            _isProcessing = false;

            return(result);
        }
예제 #6
0
 public override void EntityExecutionStarted(ExecutionEntity entity)
 {
     lock (_executingEntities)
     {
         SystemMonitor.CheckError(_executingEntities.Contains(entity), "Removing entity not present in conversation.");
     }
 }
예제 #7
0
        /// <summary>
        /// Will start a shoutcast mode conversation, the sender sending to all.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="requestMessage"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public ConversationMultiPoint CreateConversation(ArbiterClientId senderID, Message message, TimeSpan timeout)
        {
            if (message is TransportMessage)
            {
                SystemMonitor.CheckError(((TransportMessage)message).TransportInfo.CurrentTransportInfo != null);
                TracerHelper.Trace("sender[" + senderID.Id.Name + "], message [" + message.GetType().Name + "] [" + ((TransportMessage)message).TransportInfo.TransportInfoCount + "]");
            }
            else
            {
                TracerHelper.Trace("sender[" + senderID.Id.Name + "], message [" + message.GetType().Name + "]");
            }

            if (GetClientByID(senderID, false) == null)
            {
                SystemMonitor.Error("Creating conversation by not present sender/owner.");
                return(null);
            }

            ConversationMultiPoint conversation = new ConversationMultiPoint(_executionManager, message, senderID, GatherMessageClients(message, senderID), timeout);

            if (_isDisposed)
            {// Possible to get disposed while operating here.
                return(null);
            }

            lock (_timeOutMonitor)
            {
                _timeOutMonitor.AddEntity(conversation);
            }
            return(conversation);
        }
        /// <summary>
        /// Helper.
        /// </summary>
        protected bool GetSourcePath(ComponentId sourceId, out List <ArbiterClientId?> sourcePath)
        {
            SystemMonitor.CheckError(sourceId != _dataStoreSourceInfo.ComponentId, "Data store source has no path.");
            SystemMonitor.CheckError(sourceId != _backtestingExecutionSourceInfo.ComponentId, "Local execution source has no path.");

            sourcePath = null;
            SourcesUpdateMessage responce = this.SendAndReceive <SourcesUpdateMessage>(new GetSourceInfoMessage(sourceId));

            if (responce == null || responce.OperationResult == false)
            {
                return(false);
            }

            if (responce.Sources.Count > 0)
            {
                if (responce.Sources[0].TransportInfo != null)
                {
                    sourcePath = responce.Sources[0].TransportInfo.CreateRespondingClientList();
                }
                else
                {
                    sourcePath = null;
                }

                return(true);
            }

            return(false);
        }
예제 #9
0
        /// <summary>
        /// Places and tries to execute a market order synchronously. Since it might be a modification of an
        /// existing active order, no specific order Id is returned - instead a bool indicating operation result.
        /// </summary>
        /// <param name="manipulateExistingOrders">[where applicable] Is the operation allowed to close a matching existing order, or should we always open a new one. This is suitable for Active orders brokers, that dissallow hedged orders at the same time.</param>
        public string ExecuteMarket(OrderTypeEnum orderType, int volume, decimal?price, decimal?slippage,
                                    decimal?takeProfit, decimal?stopLoss, TimeSpan timeOut, out PositionExecutionInfo executionInfo,
                                    out string operationResultMessage)
        {
            //TracerHelper.TraceEntry();

            operationResultMessage = string.Empty;
            executionInfo          = PositionExecutionInfo.Empty;

            ISourceOrderExecution provider = _provider;

            if (provider == null || provider.DefaultAccount == null)
            {
                operationResultMessage = "Position not properly initialized.";
                return(string.Empty);
            }

            _isProcessing = true;

            string result = OnExecuteMarket(provider, orderType, volume, price, slippage, takeProfit, stopLoss, timeOut,
                                            out executionInfo, out operationResultMessage);

            SystemMonitor.CheckError(result == executionInfo.ExecutionId, operationResultMessage);

            _isProcessing = false;

            return(result);
        }
예제 #10
0
        /// <summary>
        ///
        /// </summary>
        protected override string OnSubmit(ISourceOrderExecution provider, OrderTypeEnum orderType, int volume, decimal?price,
                                           decimal?slippage, decimal?takeProfit, decimal?stopLoss, out string operationResultMessage)
        {
            SystemMonitor.CheckError(provider.SupportsActiveOrderManagement, "Wrong position type for this provider.");

            IQuoteProvider quotes = _manager.ObtainQuoteProvider(_dataDelivery.SourceId, Symbol);

            ActiveOrder order = new ActiveOrder(_manager, provider, quotes,
                                                _dataDelivery.SourceId, Symbol, true);

            price = ProcessPrice(quotes, orderType, price);

            string id = provider.SubmitOrder(provider.DefaultAccount.Info, order, _info.Symbol,
                                             orderType, volume, slippage, price, takeProfit, stopLoss, string.Empty, out operationResultMessage);

            if (string.IsNullOrEmpty(id))
            {
                return(string.Empty);
            }

            OrderInfo info = new OrderInfo(id, Symbol, orderType, OrderStateEnum.Submitted, volume,
                                           price, null, null, null, null, null, null, null, null, null, null, string.Empty, null);

            order.AdoptInfo(info);
            provider.TradeEntities.AddOrder(order);

            return(id);
        }
예제 #11
0
 void component_OperationalStatusChangedEvent(IOperational component, OperationalStateEnum previousState)
 {
     SystemMonitor.CheckError(_components.ContainsValue((PlatformComponent)component), "Component not present.");
     if (ActiveComponentChangedOperationalStateEvent != null)
     {
         ActiveComponentChangedOperationalStateEvent(this, (PlatformComponent)component, previousState);
     }
 }
예제 #12
0
 /// <summary>
 ///
 /// </summary>
 public PassiveOrder(ISourceManager manager, ComponentId dataSourceId, ComponentId orderExecutionSourceId)
 {
     SystemMonitor.CheckError(dataSourceId.IsEmpty == false && orderExecutionSourceId.IsEmpty == false, "Source Id not available to order.");
     _manager               = manager;
     _dataSourceId          = dataSourceId;
     _orderExectionSourceId = orderExecutionSourceId;
     _executionProvider     = manager.ObtainOrderExecutionProvider(orderExecutionSourceId, dataSourceId);
 }
예제 #13
0
 public override void EntityExecutionFailed(ExecutionEntity entity, Exception exception)
 {
     SystemMonitor.Error("Execution of entity failed [" + exception.ToString() + "].");
     lock (_executingEntities)
     {
         SystemMonitor.CheckError(_executingEntities.Contains(entity), "Removing entity not present in conversation.");
         _executingEntities.Remove(entity);
     }
 }
예제 #14
0
 public override void EntityTimedOut(ExecutionEntity entity)
 {
     lock (_executingEntities)
     {
         SystemMonitor.CheckError(_executingEntities.Contains(entity), "Removing entity not present in conversation.");
         _executingEntities.Remove(entity);
     }
     this.SetTimedOut();
 }
예제 #15
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);
            }
        }
예제 #16
0
        /// <summary>
        /// Will create the corresponding order, based to the passed in order information.
        /// Used to create corresponding orders to ones already existing in the platform.
        /// </summary>
        public virtual bool AdoptInfo(OrderInfo info)
        {
            SystemMonitor.CheckError(string.IsNullOrEmpty(this.Id) || info.Id == this.Id, "Order Id changed, this is not expected behaviour.");
            lock (this)
            {
                _info          = info;
                _initialVolume = 1;
            }

            return(true);
        }
        void SetExpert(Expert expert)
        {
            SystemMonitor.CheckError(expert == null || _expert == null || expert == _expert, "Change expert mode not supported yet. Use one control per expert.");
            _expert = expert;

            if (_expert == null)
            {
                expertSessionControl.Session = null;
                accountControl1.Account      = null;
                expertSessionControl.CorrespondingOrdersControl = null;
                return;
            }

            toolStripButtonInitialize.Enabled = _expert.Manager != null && _expert.Manager.SessionCount == 0;
            expertSessionControl.CorrespondingOrdersControl = ordersControlExpertSession;

            if (_expert.Manager != null)
            {
                int height = 0;
                if (((ExpertHost)_expert.Manager).UISerializationInfo.TryGetValue <int>("tabControl1.Height", ref height))
                {
                    tabControl1.Height = height;
                }
            }

            if (_expert.Manager != null && _expert.Manager.SessionCount > 0)
            {
                expertSessionControl.Session = (PlatformExpertSession)_expert.Manager.SessionsArray[0];
                //toolStripButtonOrders.Checked = expertSessionControl.Session.OrderExecutionProvider != null;

                positionsControl1.Initialize(_expert.Manager, _expert.Manager.GetDataDelivery(_expert.Manager.SessionsArray[0].DataProvider.SourceId), _expert.Manager.SessionsArray[0].OrderExecutionProvider);

                if (_expert.Manager.SessionsArray[0].OrderExecutionProvider != null)
                {
                    _expert.Manager.SessionsArray[0].OrderExecutionProvider.AccountInfoUpdateEvent += new AccountInfoUpdateDelegate(OrderExecutionProvider_AccountInfoUpdateEvent);
                    if (_expert.Manager.SessionsArray[0].OrderExecutionProvider.DefaultAccount != null)
                    {
                        accountControl1.Account = _expert.Manager.SessionsArray[0].OrderExecutionProvider.DefaultAccount;
                    }
                }

                tabControl1.Visible     = _expert.Manager.SessionsArray[0].OrderExecutionProvider != null;
                accountControl1.Visible = tabControl1.Visible;
                if (tabControl1.Visible == false)
                {
                    tabControl1.SelectedTab = tabControl1.TabPages[2];
                }
            }
            else
            {
                //toolStripButtonOrders.Checked = false;
                expertSessionControl.Session = null;
            }
        }
예제 #18
0
        /// <summary>
        /// Change default TransportClient behaviour.
        /// Handle a requestMessage received from local Arbiter and send down the pipe.
        /// </summary>
        /// <param name="requestMessage"></param>
        protected override void OnMessageReceived(TransportMessage message)
        {
            TracerHelper.TraceEntry();
            if (message.TransportInfo == null)
            {
                SystemMonitor.Error("Transport message stack can not be null.");
            }

            if (message.TransportInfo == null ||
                message.TransportInfo.TransportInfoCount == 0 ||
                message.TransportInfo.CurrentTransportInfo.Value.ReceiverID == null ||
                message.TransportInfo.CurrentTransportInfo.Value.ReceiverID.HasValue == false ||
                message.TransportInfo.CurrentTransportInfo.Value.ReceiverID.Value.Equals(this.SubscriptionClientID) == false)
            {// This requestMessage was sent to me, not to one of the clients on the server.
                SystemMonitor.Error("Error. Send messages to server-client instances.");
                return;
            }

            // We shall now establish the tag defining which will be the client connection receiving the requestMessage (or all).
            // by default send to all.
            string tagID = "*";

            if (message.IsRequest)
            {// Request.
                if (message.TransportInfo.ForwardTransportInfoCount != 0)
                {
                    if (message.TransportInfo.CurrentForwardTransportInfoAddress.HasValue)
                    {// Has value - take it into account, if no value is present, just use the "*" pop,
                     // and use the rest of the AdditionalForwardTransportSessionStack.
                        tagID = message.TransportInfo.CurrentForwardTransportInfoAddress.Value.SessionTag;
                    }

                    // Pop in both cases - if it is null or it is value.
                    message.TransportInfo.PopForwardTransportInfo();
                }
            }
            else
            {// Responce.
                // Clear the transporting information from the last node to here.
                message.TransportInfo.PopTransportInfo();

                // Now this is the additional marking in the case with the server - the marking of the PipeChannel.
                SystemMonitor.CheckError(message.TransportInfo.TransportInfoCount > 0 &&
                                         message.TransportInfo.CurrentTransportInfo.Value.SenderID.Value.Id.Name == "PipeChannelID");

                // Responce requestMessage, read and pop out the channel ID entry .
                tagID = message.TransportInfo.PopTransportInfo().Value.SenderID.Value.SessionTag;
            }

            MessageContainer container = new MessageContainer(message);

            TracerHelper.Trace("[" + message.GetType().Name + "], tag [" + tagID + "] length [" + container.MessageStreamLength + "]");
            GeneralHelper.FireAndForget(delegate() { _transportServer.SendMessageContainer(tagID, container); });
        }
        void PlatformNewsManager_SourceRemovedEvent(NewsManager manager, NewsSource source)
        {
            SystemMonitor.CheckError(_persistenceHelper.Delete <NewsSource>(new NewsSource[] { (source) }), "Failed to delete source from DB.");

            source.PersistenceDataUpdatedEvent -= new GeneralHelper.GenericDelegate <IDBPersistent>(source_PersistenceDataUpdatedEvent);
            source.ItemsAddedEvent             -= new NewsSource.ItemsUpdateDelegate(source_ItemsAddingAcceptEvent);
            source.ItemsUpdatedEvent           -= new NewsSource.ItemsUpdateDelegate(source_ItemsUpdatedEvent);

            _persistenceHelper.Delete <NewsSource>(source);

            _persistenceHelper.Delete <RssNewsItem>(new MatchExpression("NewsSourceId", source.Id));
        }
예제 #20
0
        /// <summary>
        ///
        /// </summary>
        protected override string OnExecuteMarket(ISourceOrderExecution provider, OrderTypeEnum orderType, int volume,
                                                  decimal?price, decimal?slippage, decimal?takeProfit, decimal?stopLoss, TimeSpan timeOut,
                                                  out PositionExecutionInfo executionInfo, out string operationResultMessage)
        {
            SystemMonitor.CheckError(provider.SupportsActiveOrderManagement == false, "Wrong position type for this provider.");

            executionInfo = PositionExecutionInfo.Empty;
            PassiveOrder order;

            lock (this)
            {
                order = new PassiveOrder(_manager, _dataDelivery.SourceId, provider.SourceId);
            }

            OrderInfo?infoReference;

            bool result = provider.SynchronousExecute(provider.DefaultAccount.Info, order, _info.Symbol,
                                                      orderType, volume, slippage, price, takeProfit, stopLoss, string.Empty, out infoReference, out operationResultMessage);

            if (result && infoReference.HasValue)
            {
                OrderInfo infoAssign = infoReference.Value;
                if (infoAssign.Type == OrderTypeEnum.UNKNOWN)
                {
                    infoAssign.Type = orderType;
                }

                if (infoAssign.Volume == int.MinValue ||
                    infoAssign.Volume == int.MaxValue)
                {// Volume was not retrieved by integration.
                    infoAssign.Volume = volume;
                }

                if (infoAssign.OpenPrice.HasValue)
                {
                    executionInfo = new PositionExecutionInfo(infoReference.Value.Id, _dataDelivery.SourceId, provider.SourceId, Symbol,
                                                              infoAssign.Type, infoAssign.OpenPrice.Value, volume, volume,
                                                              infoAssign.OpenTime, PositionExecutionInfo.ExecutionResultEnum.Success);
                }
                else
                {
                    SystemMonitor.Error("Received execution result, but price not assigned.");
                }

                order.AdoptInfo(infoAssign);

                provider.TradeEntities.AddOrder(order);

                return(infoReference.Value.Id);
            }

            return(string.Empty);
        }
예제 #21
0
        /// <summary>
        ///
        /// </summary>
        internal bool Initialize(MbtQuotes quotesClient)
        {
            SystemMonitor.CheckError(_messageLoopOperator.InvokeRequred == false, "Init must better be called on message loop method.");

            if (_quotesClient != null)
            {
                return(false);
            }

            _quotesClient = quotesClient;
            return(true);
        }
예제 #22
0
        public override void EntityExecutionFinished(ExecutionEntity entity)
        {
            lock (_executingEntities)
            {
                SystemMonitor.CheckError(_executingEntities.Contains(entity), "Removing entity not present in conversation.");
                _executingEntities.Remove(entity);

                if (_executingEntities.Count == 0)
                {// OK, we are done.
                    this.Die();
                }
            }
        }
예제 #23
0
        /// <summary>
        /// Initialize execution account with its owner provider.
        /// </summary>
        /// <param name="session"></param>
        public bool SetInitialParameters(ISourceManager manager, ISourceOrderExecution orderExecutionProvider, ISourceDataDelivery dataDelivery)
        {
            SystemMonitor.CheckError(_provider == null, "Order account already initialized.");

            _manager = manager;
            //why is the provider not ready
            _provider     = orderExecutionProvider;
            _dataDelivery = dataDelivery;

            SystemMonitor.CheckWarning(_manager != null && _provider != null && _dataDelivery != null, "Account not properly initialized.");

            return(true);
        }
예제 #24
0
        /// <summary>
        /// Helper.
        /// </summary>
        protected bool GetSourcePath(ComponentId sourceId, out List <ArbiterClientId?> sourcePath)
        {
            SystemMonitor.CheckError(sourceId != _dataStoreSourceInfo.ComponentId, "Data store source has no path.");
            SystemMonitor.CheckError(sourceId != _backtestingExecutionSourceInfo.ComponentId, "Local execution source has no path.");

            // Go around the messaging mechanism for this one, since it seems to overload the system somehow.
            SourceManagementComponent management = (SourceManagementComponent)Platform.GetFirstComponentByType(typeof(SourceManagementComponent));

            if (management == null)
            {
                sourcePath = null;
                return(false);
            }

            SourceInfo?info = management.GetSourceInfo(sourceId);

            if (info.HasValue == false)
            {
                sourcePath = null;
                return(false);
            }

            sourcePath = info.Value.TransportInfo.CreateRespondingClientList();
            return(true);

            //sourcePath = null;

            //SourcesUpdateMessage response = this.SendAndReceive<SourcesUpdateMessage>(
            //    new GetSourceInfoMessage(sourceId));

            //if (response == null || response.OperationResult == false)
            //{
            //    return false;
            //}

            //if (response.Sources.Count > 0)
            //{
            //    if (response.Sources[0].TransportInfo != null)
            //    {
            //        sourcePath = response.Sources[0].TransportInfo.CreateRespondingClientList();
            //    }
            //    else
            //    {
            //        sourcePath = null;
            //    }

            //    return true;
            //}

            //return false;
        }
        /// <summary>
        /// Stop operation.
        /// </summary>
        public void UnInitialize()
        {
            lock (this)
            {
                if (IsInitialized == false)
                {
                    return;
                }

                OnUnInitialize();
            }

            SystemMonitor.CheckError(OperationalState != OperationalStateEnum.Operational && OperationalState != OperationalStateEnum.Initialized, "Component not uninitialized(or not operational) after UnInit.");
        }
예제 #26
0
        /// <summary>
        /// Since we are in back test delivery, it is possible to receive this before we are initialized,
        /// since the underlying data bar provider gets launched before this class does.
        /// </summary>
        void _sourceDataBarProvider_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
        {
            SystemMonitor.CheckError(provider == _sourceDataBarProvider, "Data provider update not expected.");

            RestoreLastStep();

            if (_pendingSessionInfo.HasValue && _pendingRequest.HasValue)
            {// Executed only the first time.
                _pendingSessionInfo = null;
                _pendingRequest     = null;

                RequestDataHistoryUpdate(_pendingSessionInfo.Value, _pendingRequest.Value, false);
            }
        }
예제 #27
0
        public bool Initialize(MbtHistMgr historyClient)
        {
            SystemMonitor.CheckError(_messageLoopOperator.InvokeRequred == false, "Init must better be called on message loop method.");

            _historyClient = historyClient;

            // *Never* subscribe to COM events of a property, always make sure to hold the object alive
            // http://www.codeproject.com/Messages/2189754/Re-Losing-COM-events-handler-in-Csharp-client.aspx

            _historyClient.OnDataEvent += new _IMbtHistEvents_OnDataEventEventHandler(_historyClient_OnDataEvent);
            _historyClient.OnError     += new _IMbtHistEvents_OnErrorEventHandler(_historyClient_OnError);

            return(true);
        }
        /// <summary>
        /// Helper.
        /// </summary>
        bool DoCloseOrder(AccountInfo account, Order order, decimal?allowedSlippage, decimal?desiredPrice, out decimal closingPrice,
                          out DateTime closingTime, out string modifiedId, out string operationResultMessage)
        {
            TracerHelper.Trace(this.Name);

            closingPrice = decimal.MinValue;
            closingTime  = DateTime.MinValue;
            modifiedId   = order.Id;

            if (OperationalState != OperationalStateEnum.Operational)
            {
                operationResultMessage = "Attempted operations on non operational order executioner.";
                SystemMonitor.Error(operationResultMessage);
                return(false);
            }

            allowedSlippage = ProcessSlippage(allowedSlippage);

            CloseOrderVolumeMessage message = new CloseOrderVolumeMessage(account, order.Symbol, order.Id,
                                                                          order.Tag, desiredPrice, allowedSlippage);

            message.PerformSynchronous = true;

            ResponseMessage response = this.SendAndReceiveResponding <ResponseMessage>
                                           (SourceTransportInfo, message);

            if (response == null)
            {// Time out.
                operationResultMessage = "Failed receive result for order request. In this scenario inconsistency may occur!";
                SystemMonitor.Error(operationResultMessage);
                return(false);
            }

            if (response.OperationResult)
            {
                CloseOrderVolumeResponseMessage responseMessage = (CloseOrderVolumeResponseMessage)response;
                operationResultMessage = "Order closed.";
                closingPrice           = responseMessage.ClosingPrice;
                closingTime            = responseMessage.ClosingDateTime;

                SystemMonitor.CheckError(order.Id == responseMessage.OrderId.ToString(), "Order id mismatch [" + order.Id + " / " + responseMessage.OrderId + "].");

                modifiedId = responseMessage.OrderModifiedId.ToString();
                return(true);
            }

            operationResultMessage = response.OperationResultMessage;
            return(false);
        }
예제 #29
0
        /// <summary>
        ///
        /// </summary>
        public bool Initialize(FXCMAdapter adapter, FXCMConnectionManager manager)
        {
            SystemMonitor.CheckError(_messageLoopOperator.InvokeRequred == false, "Init must better be called on message loop method.");

            //TODO: Guess what this piece does
            StatusSynchronizationEnabled = true;
            StatusSynchronizationSource  = manager;

            _adapter = adapter;
            _manager = manager;

            ChangeOperationalState(OperationalStateEnum.Operational);

            return(true);
        }
예제 #30
0
        /// <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);
        }