Beispiel #1
0
        //
        //
        protected override void SetupInitialize(IEngineHub myEngineHub, IEngineContainer engineContainer, int engineID, bool setupGui)
        {
            if (typeof(UV.Strategies.ExecutionHubs.ExecutionContainers.MultiThreadContainer).IsAssignableFrom(engineContainer.GetType()))
            {   // this is the "first" set up call from the manager container.
                base.SetupInitialize(myEngineHub, engineContainer, engineID, setupGui);
                m_MultiThreadContainer = (MultiThreadContainer)engineContainer;
                m_MultiThreadContainer.TryAddEngine(m_Scratcher);       // we need to add our sub engines to the container, just to allow set up and messaging to correctly function
            }
            else
            {   // this is the second set up call from the correct container, add correct sub engine mappings
                ThreadContainer execContainer = (ThreadContainer)engineContainer;
                execContainer.TryAddEngine(m_Scratcher);

                if (execContainer.IOrderEngine is CurveTrader)
                {
                    m_CurveTrader = (CurveTrader)execContainer.IOrderEngine;
                }

                m_MultiThreadContainer.TryAddEngineIdToManagingContainer(execContainer, m_Scratcher.EngineID);
            }
        }
        //
        //
        /// <summary>
        /// Called by the execution hub thread, not the execution listener!
        /// </summary>
        /// <param name="myEngineHub"></param>
        /// <param name="engineContainer"></param>
        /// <param name="engineID"></param>
        /// <param name="setupGui"></param>
        protected override void SetupInitialize(Lib.Engines.IEngineHub myEngineHub, Lib.Engines.IEngineContainer engineContainer, int engineID, bool setupGui)
        {
            base.SetupInitialize(myEngineHub, engineContainer, engineID, setupGui);
            m_Hub = (Hub)myEngineHub;
            ExecutionHub executionHub = (ExecutionHub)myEngineHub;

            m_ExecutionContainer = (ThreadContainer)engineContainer;           // this must be a multithreaded container for this execution to work
            m_Log = m_Hub.Log;

            //
            // Set up engines translation with manager container
            //
            MultiThreadContainer multiThreadContainer = (MultiThreadContainer)m_ExecutionContainer;

            multiThreadContainer.TryAddEngineIdToManagingContainer(multiThreadContainer, this.EngineID);


            //
            // Create new execution containers to be managed on seperate threads for each curve trader
            //

            foreach (CurveTrader curveTrader in m_CurveTraders)
            {
                ThreadContainer container = new ThreadContainer();
                container.EngineContainerID   = System.Threading.Interlocked.Increment(ref m_LastContainerId);  // increment our id and save our engine id
                container.EngineContainerName = string.Format("CurveTrader{0}", container.EngineContainerID);   // Add basic name
                container.RemoteEngineHub     = executionHub;                                                   // pointer to the local hub, a remote strategy will not control this
                container.TotalEngineCount    = 1;                                                              // this is only the number of "super engines" not sub engines!

                m_ExecutionContainer.TryAddEngine(curveTrader);                                                 // add this engine to both containers!
                container.TryAddEngine(curveTrader);                                                            // need to be careful here with "double" launching
                curveTrader.m_CurveTradeManager = this;                                                         // give pointer to manager to each trader...careful with threads!
                m_CurveTraderPendingLaunch.Add(curveTrader.EngineID);                                           // engine id's we are waiting on to launch properly

                multiThreadContainer.TryAddEngineIdToManagingContainer(container, curveTrader.EngineID);

                // now that all engines are added, sent off the container to the hub to be finish processing.
                EngineEventArgs engineEventArgs = new EngineEventArgs();
                engineEventArgs.MsgType           = EngineEventArgs.EventType.AddContainer;
                engineEventArgs.Status            = EngineEventArgs.EventStatus.Request;
                engineEventArgs.EngineContainerID = container.EngineContainerID;
                engineEventArgs.DataObjectList    = new List <object>();
                engineEventArgs.DataObjectList.Add("ExecutionHub");
                engineEventArgs.DataObjectList.Add(container);

                m_Hub.HubEventEnqueue(engineEventArgs);
            }

            //foreach (CurveLegList curveLegs in m_CurveLegLists)
            //{   // call hub to create the execution container for each of these sub stratgies, once it is created and done, assign the list
            //    // to the object, the hub will call the set up functions afterwards
            //    ThreadContainer container = new ThreadContainer();
            //    container.EngineContainerID = System.Threading.Interlocked.Increment(ref m_LastContainerId);     // increment our id and save our engine id
            //    container.EngineContainerName = string.Format("CurveTrader{0}", container.EngineContainerID);   // Add basic name
            //    container.RemoteEngineHub = executionHub;                                                       // pointer to the local hub, a remote strategy will not control this
            //    container.TotalEngineCount = 2;                                                                 // this is only the number of "super engines" not sub engines!
            //    // Add all Engines to container here

            //    CurveTrader curveTrader = new CurveTrader();                                                    // create new curve trader execution unit
            //    curveTrader.Id = container.EngineContainerID;                                                   // use same id as container, (they are 1:1)
            //    curveTrader.EngineID = 0;                                                                       // I am the first engine, so assign me 0

            //    m_CurveTraderPendingLaunch.Add(curveTrader.Id);                                                 // save id to make sure we have everything before we start
            //    m_CurveTraders.Add(curveTrader);                                                                // keep pointer to curve trader, carefuly using it due to threading!

            //    curveTrader.m_CurveLegs = curveLegs;                                                            // assign the needed legs to the new unit
            //    curveTrader.m_CurveTradeManager = this;                                                         // give curve trader pointer so he can call back up to me.

            //    // TODO: create any other engines here?
            //    // TODO: subscribe to these engines events? when they are launched we want to launch ourselves, etc
            //    if(!container.TryAddEngine((Engine)curveTrader))
            //    {
            //        m_Log.NewEntry(LogLevel.Error, "CurveTradeManager: Unable to create execution unit!");
            //        continue;
            //    }

            //    m_ExecutionContainer.TryAddEngine(curveLegs);

            //    // now that all engines are added, sent off the container to the hub to be finish processing.
            //    EngineEventArgs engineEventArgs = new EngineEventArgs();
            //    engineEventArgs.MsgType = EngineEventArgs.EventType.AddContainer;
            //    engineEventArgs.Status = EngineEventArgs.EventStatus.Request;
            //    engineEventArgs.EngineContainerID = container.EngineContainerID;
            //    engineEventArgs.DataObjectList = new List<object>();
            //    engineEventArgs.DataObjectList.Add("ExecutionHub");
            //    engineEventArgs.DataObjectList.Add(container);

            //    m_Hub.HubEventEnqueue(engineEventArgs);

            //}
        }