Ejemplo n.º 1
0
        ScratchManager m_ScratchManager; // scratch manager

        #endregion                       // members


        #region Constructors
        // *****************************************************************
        // ****                     Constructors                        ****
        // *****************************************************************
        //
        //
        //
        protected override void SetupInitialize(Lib.Engines.IEngineHub myEngineHub, Lib.Engines.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);
            }
            else
            {   // this is the second set up call from the correct container, add correct sub engine mappings
            }
        }
Ejemplo n.º 2
0
 //
 //
 //
 public override void SetupBegin(Lib.Engines.IEngineHub myEngineHub, Lib.Engines.IEngineContainer engineContainer)
 {
     base.SetupBegin(myEngineHub, engineContainer);
     foreach (IEngine iEng in engineContainer.GetEngines())
     { // Find order Engine
         if (iEng is Spreader)
         {
             this.m_Spreader = (Spreader)iEng;                                             // find our order engine
         }
         if (iEng is HedgeManager)
         {
             this.m_HedgeManager = (HedgeManager)iEng;
         }
     }
 }
Ejemplo n.º 3
0
        //
        //
        /// <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);

            //}
        }
Ejemplo n.º 4
0
        //
        //
        /// <summary>
        /// Called by our internal listener thread
        /// </summary>
        /// <param name="myEngineHub"></param>
        /// <param name="engineContainer"></param>
        public override void SetupBegin(Lib.Engines.IEngineHub myEngineHub, Lib.Engines.IEngineContainer engineContainer)
        {
            base.SetupBegin(myEngineHub, engineContainer);                      // call base class

            //
            // Subscribe to events
            //
            //m_ExecutionListener.InstrumentFound += new EventHandler(ExecutionListener_InstrumentsFound);

            //
            // Find all needed pointers to engines
            //
            //foreach (IEngine iEng in engineContainer.GetEngines())      // find the user created risk manager
            //    if (iEng is RiskManagerSpreader)
            //        m_RiskManager = (RiskManagerSpreader)iEng;
            //    else if (iEng is HedgeManager)
            //        m_HedgeManager = (HedgeManager)iEng;


            //if (m_RiskManager == null)
            //    throw new NotImplementedException("All Strategies Must Have a Risk Manager, Please Add One To Your User Config - Must Be UV.Execution.Risk.RiskManagerQuoter type");
            //if (m_HedgeManager == null)
            //    throw new NotImplementedException("All Quoters Must Have a Hedge Manager, Please Add One To Your User Config - Must Be UV.Execution.HedgeManager type");

            //
            // Set up all legs
            //
            //StringBuilder spreadName = new StringBuilder();                                             // synthetic spread name for reporting spread fills
            //for (int leg = 0; leg < m_SpreaderLegs.Count; ++leg)
            //{
            //    SpreaderLeg spreadLeg = m_SpreaderLegs[leg];
            //    spreadLeg.LeanablePriceChanged += new EventHandler(Instrument_LeanablePriceChanged);    // subscribe to pricing updates.
            //    spreadLeg.MarketStateChanged += new EventHandler(Instrument_MarketStateChanged);        // subscribe to market state changes.
            //    spreadLeg.ParameterChanged += new EventHandler(Instrument_ParameterChanged);            // param changes need to make the quoter update.

            //    spreadLeg.UpdateDripQty(1);
            //    m_Instruments.Add(spreadLeg.m_PriceLeg.InstrumentName);

            //    FillBook fillBook = new FillBook(spreadLeg.m_PriceLeg.InstrumentName.ToString(), 0);    // Multiplier will need to be set once we have instrument details!
            //    m_LegFillBooks[leg] = fillBook;                                                         // add book to array to pass to spread fill generator

            //    m_IsQuotingLeg[leg] = spreadLeg.m_QuotingEnabled;
            //    m_PendingQuoteOrders[leg] = new Order[2];                                               // 2-sides of the mkt
            //    m_QuotingLegPrices[leg] = new double[2];
            //    m_IsQuotingLegPriceOffMarket[leg] = new bool[2];
            //    m_IsLegLeanable[leg] = new bool[2];

            //    m_LegRatios[leg] = spreadLeg.m_PriceLeg.Weight;                                         // add ratio and multipliers to array to pass to spread fill generator
            //    m_LegPriceMultipliers[leg] = spreadLeg.m_PriceLeg.PriceMultiplier;

            //    m_QuoteFillCount[leg] = new int[2];                                                     // Quote Fill counts to start are 0 for bid side
            //    m_QuotePartialCount[leg] = new int[2];                                                  // Quote partial counts to start are 0 for bid side

            //    if (leg != (m_SpreaderLegs.Count - 1))  //append spread name
            //        spreadName.AppendFormat("{0}.", spreadLeg.m_PriceLeg.InstrumentName);
            //    else
            //        spreadName.Append(spreadLeg.m_PriceLeg.InstrumentName);
            //}
            //m_SyntheticSpreadFillBook = new FillBook(spreadName.ToString(), 0);                         // create synthetic fill book for our synthetics fills. no mult.
            //Product syntheticProduct = new Product("SyntheticExch", spreadName.ToString(), ProductTypes.Synthetic);
            //InstrumentName syntheticInstrName = new InstrumentName(syntheticProduct, string.Empty);
            //m_SpreadFillGenerator = new ExecutionEngines.SpreaderFills.SpreaderFillGenerator(           // instantiate the spread fill generator passing an array of legRatios, and an array of books to it.
            //    syntheticInstrName, m_LegRatios, m_LegPriceMultipliers, m_LegFillBooks);
            //m_SpreadFillGenerator.SyntheticSpreadFilled += new EventHandler(SpreadFillGenerator_SyntheticSpreadFilled);
        }