示例#1
0
 private void notifyAllAgentEvaluationFactories(ISimulationEvent se)
 {
     foreach (IAgentEvaluationFactory af in _aflist)
     {
         af.recvSimulationNotification(this, se);
     }
 }
示例#2
0
        public void recvSimulationNotification(ISimulationParameters sim, ISimulationEvent se)
        {
            SingletonLogger.Instance().DebugLog(typeof(AbstractPassiveTrajectoryFactory), "AbstractPassiveTrajectoryFactory recvSimulationNotification");

            // events received from ISimulation

            if (se.OrderbookEvent == null)
            {
                if (se is ISimulationStart)
                {
                    SingletonLogger.Instance().DebugLog(typeof(AbstractPassiveTrajectoryFactory), "AbstractPassiveTrajectoryFactory SET Sim!");
                    _sim = sim;
                    reset();
                    SimulationStartNotification();
                }

                if (se is ISimulationEnd)
                {
                    SimulationEndNotification();
                    SingletonLogger.Instance().DebugLog(typeof(AbstractPassiveTrajectoryFactory), "AbstractPassiveTrajectoryFactory CLEAR Sim!");
                    _sim = null;
                }
            }
            else
            {
                if (_sim == null)
                {
                    // too late
                    SingletonLogger.Instance().DebugLog(typeof(AbstractPassiveTrajectoryFactory), "AbstractPassiveTrajectoryFactory Too Late!");
                    return;
                }

                if (se.OrderbookEvent is IOrderbookEvent_FillOrder)
                {
                    IOrderbookEvent_FillOrder fillEvent = (IOrderbookEvent_FillOrder)se.OrderbookEvent;
                    IOrder filledOrder = fillEvent.getOrder();
                    if (fillEvent.orderFilled())
                    {
                        FilledOrderNotification(filledOrder, fillEvent.getExecutionPrice(), fillEvent.getVolume());
                    }
                    else
                    {
                        PartialFilledOrderNotification(filledOrder, fillEvent.getExecutionPrice(), fillEvent.getVolume());
                    }
                }
                else if (se.OrderbookEvent is IOrderbookEvent_AddOrder)
                {
                    IOrderbookEvent_AddOrder addEvent = (IOrderbookEvent_AddOrder)se.OrderbookEvent;
                    IOrder newOrder = addEvent.getOrder();
                    NewOrderNotification(newOrder);
                }
                else if (se.OrderbookEvent is IOrderbookEvent_CancelOrder)
                {
                    IOrderbookEvent_CancelOrder cancelEvent = (IOrderbookEvent_CancelOrder)se.OrderbookEvent;
                    IOrder cancelledOrder = cancelEvent.getOrder();
                    CancelOrderNotification(cancelledOrder);
                }
            }
        }
示例#3
0
 private void notifyAllTrajectoryFactories(ISimulationEvent se)
 {
     foreach (IPassiveTrajectoryFactory tf in _tflist)
     {
         SingletonLogger.Instance().DebugLog(typeof(Simulation), "notifyAllTrajectoryFactories");
         tf.recvSimulationNotification(this, se);
     }
 }
示例#4
0
        public void recvSimulationNotification(ISimulationParameters sim, ISimulationEvent se)
        {
            // events received from ISimulation

            if (se.OrderbookEvent == null)
            {
                if (se is ISimulationStart)
                {
                    SingletonLogger.Instance().DebugLog(typeof(AbstractAgentEvaluationFactory), "*** AbstractAgentEvaluationFactory got ISimulationStart");
                    _sim = sim;
                    reset();
                    SimulationStartNotification();
                }

                if (se is ISimulationEnd)
                {
                    SingletonLogger.Instance().DebugLog(typeof(AbstractAgentEvaluationFactory), "*** AbstractAgentEvaluationFactory got ISimulationEnd");
                    SimulationEndNotification();
                    _sim = null;
                }
            }
            else
            {
                SingletonLogger.Instance().DebugLog(typeof(AbstractAgentEvaluationFactory), "*** AbstractAgentEvaluationFactory got ISimulationEvent with non-null Orderbook");

                if (se.OrderbookEvent is IOrderbookEvent_FillOrder)
                {
                    IOrderbookEvent_FillOrder fillEvent = (IOrderbookEvent_FillOrder)se.OrderbookEvent;
                    IOrder filledOrder = fillEvent.getOrder();
                    if (fillEvent.orderFilled())
                    {
                        FilledOrderNotification(filledOrder, fillEvent.getExecutionPrice(), fillEvent.getVolume());
                    }
                    else
                    {
                        PartialFilledOrderNotification(filledOrder, fillEvent.getExecutionPrice(), fillEvent.getVolume());
                    }
                }
                else if (se.OrderbookEvent is IOrderbookEvent_AddOrder)
                {
                    IOrderbookEvent_AddOrder addEvent = (IOrderbookEvent_AddOrder)se.OrderbookEvent;
                    IOrder newOrder = addEvent.getOrder();
                    NewOrderNotification(newOrder);
                }
                else if (se.OrderbookEvent is IOrderbookEvent_CancelOrder)
                {
                    IOrderbookEvent_CancelOrder cancelEvent = (IOrderbookEvent_CancelOrder)se.OrderbookEvent;
                    IOrder cancelledOrder = cancelEvent.getOrder();
                    CancelOrderNotification(cancelledOrder);
                }
            }
        }
示例#5
0
        // handle events from simulation
        public void recvSimulationNotification(ISimulationParameters sim, ISimulationEvent se)
        {
            if (se.OrderbookEvent == null)
            {
                if (se is ISimulationStart)
                {
                    SingletonLogger.Instance().InfoLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " Start @ " + Scheduler.GetTime());
                    _sim = sim;
                    SimulationStartNotification(sim.Population);
                }

                if (se is ISimulationEnd)
                {
                    SingletonLogger.Instance().InfoLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " End @ " + Scheduler.GetTime());
                    SimulationEndNotification();
                    //CancelAllOpenOrders();
                    _sim = null;
                }
            }
        }
示例#6
0
 // delegate signals from the Simulation to appropriate agents
 public void recvSimulationNotification(ISimulationParameters sim, ISimulationEvent se)
 {
     if (se.OrderbookEvent == null)
     {
         // start and end events go to all agents
         if (se is ISimulationStart)
         {
             foreach (IAgent ag in _agents)
             {
                 ag.recvSimulationNotification(sim, se);
             }
         }
         else if (se is ISimulationEnd)
         {
             foreach (IAgent ag in _agents)
             {
                 ag.recvSimulationNotification(sim, se);
             }
         }
     }
     else
     {
         // fill events go to the order owner only
         if (se.OrderbookEvent is IOrderbookEvent_FillOrder)
         {
             IOrderbookEvent_FillOrder fillEvent = (IOrderbookEvent_FillOrder)se.OrderbookEvent;
             IOrderOwner owner = fillEvent.getOrder().getOwner();
             if (_agents.Contains((IAgent)owner))
             {
                 owner.recvOrderNotification(sim.Orderbook, fillEvent);
             }
             else
             {
                 throw new Exception("Population is attempting to forward signal to an unrecognized IAgent");
             }
         }
         // Add and Cancel events are ignored by the Population class
     }
 }
示例#7
0
 public void AddSimulationEvent(ISimulationEvent simulationEvent, int atTick)
 {
     SnapshotsRingBuffer[GetSnapshotIndexForTick(atTick)].SimulationEvents.Add(simulationEvent);
 }
示例#8
0
 private void notifyPopulation(ISimulationEvent se)
 {
     _pop.recvSimulationNotification(this, se);
 }
示例#9
0
 public void broadcast(ISimulationEvent se)
 {
     notifyPopulation(se);
     notifyAllAgentEvaluationFactories(se);
     notifyAllTrajectoryFactories(se);
 }