Ejemplo n.º 1
0
        // receive a signal from the Matcher (via the Simulation, via the Population) that an order has been filled
        public void recvOrderNotification(IOrderbook_Agent ob, IOrderbookEvent evt)
        {
            // Fill order events
            if (evt is IOrderbookEvent_FillOrder)
            {
                IOrderbookEvent_FillOrder fillEvent = (IOrderbookEvent_FillOrder)evt;
                IOrder filledOrder = fillEvent.getOrder();

                SingletonLogger.Instance().InfoLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " Fill " + filledOrder + " @ " + Scheduler.GetTime());

                if (filledOrder.isBid())
                {
                    AccumulateHoldings(+1 * fillEvent.getVolume());
                }
                else
                {
                    AccumulateHoldings(-1 * fillEvent.getVolume());
                }

                if (fillEvent.orderFilled())
                {
                    RemoveFromOpenOrderList(filledOrder);
                    FilledOrderNotification(filledOrder, fillEvent.getExecutionPrice(), fillEvent.getVolume());
                }
                else
                {
                    PartialFilledOrderNotification(filledOrder, fillEvent.getExecutionPrice(), fillEvent.getVolume());
                }
            }
            // Add and Cancel events are not forwarded to agents by the Population class
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }