Exemplo n.º 1
0
        }// ProcessParameterChangeRequest()

        //
        //
        // *****************************************
        // ****  ProcessSyntheticOrderRequest   ****
        // *****************************************
        /// <summary>
        /// A request for submission of a synthetic order.
        /// </summary>
        /// <param name="engineEventArg"></param>
        private void ProcessSyntheticOrderRequest(EngineEventArgs engineEventArg)
        {
            SyntheticOrder  syntheticOrder = (SyntheticOrder)engineEventArg.DataObjectList[0];
            ThreadContainer strategy       = null;
            int             strategyID     = engineEventArg.EngineContainerID;

            if (strategyID < 0)
            {   // This request is for all strategies
                Log.NewEntry(LogLevel.Error, "ProcessEngineEvent: Negative EngineContainerId not allowed in {0}.", syntheticOrder);
                engineEventArg.EngineHubName = this.ServiceName;
                engineEventArg.Status        = EngineEventArgs.EventStatus.Failed;
                OnEngineChanged(engineEventArg);
            }
            else if (m_ExecutionContainers[DefaultHubName].TryGetValue(strategyID, out strategy))
            {   // Found the strategy, pass it the request now.
                // He is on another thread, so give him a thread safe copy.
                strategy.ProcessEvent(engineEventArg.Copy());
            }
            else
            {   // Unknown strategy
                Log.NewEntry(LogLevel.Error, "ProcessEngineEvent: Unknown EngineContainerId {0}", syntheticOrder);
                engineEventArg.EngineHubName = this.ServiceName;
                engineEventArg.Status        = EngineEventArgs.EventStatus.Failed;
                OnEngineChanged(engineEventArg);
            }
        }
Exemplo n.º 2
0
        //
        // *****************************************
        // ****     ProcessEngineEvent          ****
        // *****************************************
        /// <summary>
        /// A request from outside to change a parameter value.
        /// </summary>
        protected void ProcessEngineEvent(EngineEventArgs eventArgs)
        {
            ThreadContainer strategy   = null;
            int             strategyID = eventArgs.EngineContainerID; // parameter change requested for this strategy.

            if (strategyID < 0)
            {   // This request is for all strategies
                Log.NewEntry(LogLevel.Error, "ProcessEngineEvent: Negative EngineContainerId not allowed in {0}.", eventArgs);
                eventArgs.EngineHubName = this.ServiceName;
                eventArgs.Status        = EngineEventArgs.EventStatus.Failed;
                OnEngineChanged(eventArgs);
            }
            else if (m_ExecutionContainers[DefaultHubName].TryGetValue(strategyID, out strategy))
            {   // Found the strategy, pass it the request now.
                // He is on another thread, so give him a thread safe copy.
                // He will be allowed to modify this object to compose his response.
                //EngineEventArgs copyEventArgs = eventArgs.Copy();
                strategy.ProcessEvent(eventArgs.Copy());
            }
            else
            {   // Unknown strategy
                Log.NewEntry(LogLevel.Error, "ProcessEngineEvent: Unknown EngineContainerId {0}", eventArgs);
                eventArgs.EngineHubName = this.ServiceName;
                eventArgs.Status        = EngineEventArgs.EventStatus.Failed;
                OnEngineChanged(eventArgs);
            }
        }// ProcessParameterChangeRequest()
        //
        //
        //
        //
        #endregion//Public Methods


        #region Private Methods
        // *****************************************************************
        // ****                     Private Methods                     ****
        // *****************************************************************
        //
        //
        //
        // ****         Process Remote Engine Events        ****
        //
        /// <summary>
        /// This is called by the StrategyHub thread.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        protected void ProcessRemoteEngineEvents(object sender, EventArgs eventArgs)
        {
            if (eventArgs is EngineEventArgs)
            {
                EngineEventArgs eventArg = (EngineEventArgs)eventArgs;
                switch (eventArg.MsgType)
                {
                case EngineEventArgs.EventType.NewEngine:
                    int ptr = 0;
                    m_EngineGuis = new List <EngineGui>();
                    while (eventArg.DataObjectList.Count > ptr)
                    {
                        if (eventArg.DataObjectList[ptr] is EngineGui)
                        {
                            m_EngineGuis.Add((EngineGui)eventArg.DataObjectList[ptr]);
                        }
                        else
                        {
                        }
                        ptr++;
                    }
                    this.IsReadyForSetup = true;
                    ((StrategyHub)m_LocalEngineHub).ProcessStrategy(m_EngineContainerId);
                    break;

                default:
                    if (eventArg.Status == EngineEventArgs.EventStatus.Confirm)     // TODO: pass fails too?
                    {
                        EngineEventArgs outEventArg = eventArg.Copy();
                        outEventArg.EngineHubName = m_LocalEngineHubName;
                        ((StrategyHub)m_LocalEngineHub).OnEngineChanged(outEventArg);
                    }
                    break;
                }
            }
            else
            {
                Log.NewEntry(LogLevel.Error, "ProcessRemoteEvents: Unknown event {0}", eventArgs);
            }
        }//ProcessRemoteEngineHubEvents
        public override void ProcessEvent(EventArgs eArgs)
        {
            if ((eArgs is EngineEventArgs) == false)
            {
                Log.NewEntry(LogLevel.Error, "ProcessEvent: Unknown event {0}", eArgs);
                return;
            }
            EngineEventArgs eventArgs = (EngineEventArgs)eArgs;

            if (eventArgs.Status == EngineEventArgs.EventStatus.Request)
            {
                if (eventArgs.EngineHubName.Equals(m_LocalEngineHubName))
                {
                    EngineEventArgs outEventArg = eventArgs.Copy();
                    outEventArg.EngineHubName = m_RemoteEngineHub.ServiceName;
                    m_RemoteEngineHub.HubEventEnqueue(outEventArg);
                }
            }
            else
            {
                Log.NewEntry(LogLevel.Error, "ProcessEvent: Recieved non-request {0}", eventArgs);
            }
        }//ProcessEvent()
Exemplo n.º 5
0
 //
 //
 // *********************************************
 // ****      SendSyntheticOrderToRemote()   ****
 // *********************************************
 /// <summary>
 /// Called by an order engine who would like to send back to the strategy hub
 /// a synthetic order that has been updated. - This should probably be renamed.
 /// but just going with this for now.
 /// </summary>
 /// <param name="syntheticOrder"></param>
 public void SendSyntheticOrderToRemote(SyntheticOrder syntheticOrder)
 {
     m_ConfirmSynthOrderEventArg.DataObjectList.Clear(); // clear before each reuse.
     m_ConfirmSynthOrderEventArg.DataObjectList.Add(syntheticOrder);
     this.RemoteEngineHub.HubEventEnqueue(m_ConfirmSynthOrderEventArg.Copy());
 }
Exemplo n.º 6
0
        //
        //
        //
        //
        #endregion//Public Methods


        #region Private Methods
        // *****************************************************************
        // ****                     Private Methods                     ****
        // *****************************************************************
        //
        //
        //
        // *****************************************************
        // ****         Process Remote Engine Events        ****
        // *****************************************************
        /// <summary>
        /// This is called by the StrategyHub thread whenever it receives events
        /// from the remote engineHub/engine that we are subscribed to.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        protected void ProcessRemoteEngineEvents(object sender, EventArgs eventArgs)
        {
            if (eventArgs is EngineEventArgs)
            {
                EngineEventArgs eventArg = (EngineEventArgs)eventArgs;
                switch (eventArg.MsgType)
                {   // *****************************
                // ****     New Engine      ****
                // *****************************
                case EngineEventArgs.EventType.NewEngine:
                    int ptr = 0;
                    m_EngineGuis = new List <EngineGui>();
                    while (eventArg.DataObjectList.Count > ptr)
                    {
                        if (eventArg.DataObjectList[ptr] is EngineGui)
                        {
                            m_EngineGuis.Add((EngineGui)eventArg.DataObjectList[ptr]);      // extract engine guis from remote engine
                        }
                        else
                        {
                        }
                        ptr++;
                    }
                    // Request parameter values from the new engine.
                    m_RemoteEngineHub.HubEventEnqueue(EngineEventArgs.RequestAllParameters(m_RemoteEngineHub.ServiceName, m_EngineContainerId, m_EngineID));

                    break;

                // *****************************************
                // ****         ParameterChange         ****
                // *****************************************
                case EngineEventArgs.EventType.ParameterChange:
                    if (eventArg.Status == EngineEventArgs.EventStatus.Confirm || eventArg.Status == EngineEventArgs.EventStatus.Failed)
                    {
                        // Update my internal values for this parameter.
                        for (int i = 0; i < eventArg.DataIntA.Length; ++i)
                        {
                            int paramId = eventArg.DataIntA[i];
                            m_ParameterValueTable[paramId] = eventArg.DataObjectList[i];
                        }
                        // Broadcast the parameter change value
                        EngineEventArgs outEventArg = eventArg.Copy();
                        outEventArg.EngineHubName = m_LocalEngineHubName;               // only hub name differs, so change it.
                        ((StrategyHub)m_LocalEngineHub).OnEngineChanged(outEventArg);
                    }
                    break;

                // *****************************************
                // ****         ParameterValue          ****
                // *****************************************
                case EngineEventArgs.EventType.ParameterValue:
                    // When I receive parameter change confirmations, I broadcast them as if they originated from me.
                    if (eventArg.Status == EngineEventArgs.EventStatus.Confirm || eventArg.Status == EngineEventArgs.EventStatus.Failed)
                    {
                        // Update my internal values for this parameter.
                        for (int i = 0; i < eventArg.DataIntA.Length; ++i)
                        {
                            int paramId = eventArg.DataIntA[i];
                            m_ParameterValueTable[paramId] = eventArg.DataObjectList[i];
                        }
                        // Broadcast the parameter change value
                        EngineEventArgs outEventArg = eventArg.Copy();
                        outEventArg.EngineHubName = m_LocalEngineHubName;               // only hub name differs, so change it.
                        ((StrategyHub)m_LocalEngineHub).OnEngineChanged(outEventArg);

                        // Inform strategy we are ready to complete setup after first ParameterValue callback.
                        // Criteria:  1) Loaded engine guis from NewEngine call back, 2) got parameter values.
                        if (this.IsReadyForSetup == false)
                        {
                            if (m_EngineGuis != null)
                            {
                                this.IsReadyForSetup = true;
                                ((StrategyHub)m_LocalEngineHub).RequestSetupComplete(m_EngineContainerId);
                            }
                        }
                    }
                    break;

                // *****************************************
                // ****             default             ****
                // *****************************************
                default:
                    // Whenever I receive other events from the remote engine,
                    // I will broadcast them as if they originated from me.
                    if (eventArg.Status == EngineEventArgs.EventStatus.Confirm || eventArg.Status == EngineEventArgs.EventStatus.Failed)
                    {
                        EngineEventArgs outEventArg = eventArg.Copy();
                        outEventArg.EngineHubName = m_LocalEngineHubName;               // only hub name differs, so change it.
                        ((StrategyHub)m_LocalEngineHub).OnEngineChanged(outEventArg);
                    }
                    break;
                }
            }
            else
            {
                Log.NewEntry(LogLevel.Error, "ProcessRemoteEvents: Unknown event {0}", eventArgs);
            }
        }//ProcessRemoteEngineHubEvents