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); } } }
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); } } }
public void recvOrderbookNotification(IOrderbook_Matcher ob, IOrderbookEvent evt) { String line = ""; if (evt is IOrderbookEvent_AddOrder) { // log an Add row IOrderbookEvent_AddOrder addEvt = (IOrderbookEvent_AddOrder)evt; IOrder order = addEvt.getOrder(); string status = "Add"; string time = "" + String.Format("{0:.###}", Scheduler.GetTime()); string price = "" + (ob.getNumBids() > 0 ? String.Format("{0:.###}", ob.getHighestBid()) : "?") + "," + (ob.getNumAsks() > 0 ? String.Format("{0:.###}", ob.getLowestAsk()) : "?"); string direction = "" + (order.isBid() ? "BID" : "ASK"); string orderprice = "" + String.Format("{0:.###}", order.getPrice()); string ordersize = "" + order.getVolume(); string owner = "\"" + order.getOwner().ToString() + "\""; line = status + "," + time + "," + price + "," + direction + "," + orderprice + "," + ordersize + "," + owner; Console.WriteLine(line); } else if (evt is IOrderbookEvent_CancelOrder) { // log a Cancel IOrderbookEvent_CancelOrder cancelEvt = (IOrderbookEvent_CancelOrder)evt; IOrder order = cancelEvt.getOrder(); string status = "Cancel"; string time = "" + String.Format("{0:.###}", Scheduler.GetTime()); string price = "" + (ob.getNumBids() > 0 ? String.Format("{0:.###}", ob.getHighestBid()) : "?") + "," + (ob.getNumAsks() > 0 ? String.Format("{0:.###}", ob.getLowestAsk()) : "?"); string direction = "" + (order.isBid() ? "BID" : "ASK"); string orderprice = "" + String.Format("{0:.###}", order.getPrice()); string ordersize = "" + order.getVolume(); string owner = "\"" + order.getOwner().ToString() + "\""; line = status + "," + time + "," + price + "," + direction + "," + orderprice + "," + ordersize + "," + owner; Console.WriteLine(line); } else if (evt is IOrderbookEvent_FillOrder) { // no op IOrderbookEvent_FillOrder fillEvt = (IOrderbookEvent_FillOrder)evt; IOrder order = fillEvt.getOrder(); string status = "Fill"; string time = "" + String.Format("{0:.###}", Scheduler.GetTime()); string price = "" + (ob.getNumBids() > 0 ? String.Format("{0:.###}", ob.getHighestBid()) : "?") + "," + (ob.getNumAsks() > 0 ? String.Format("{0:.###}", ob.getLowestAsk()) : "?"); string direction = "" + (order.isBid() ? "BID" : "ASK"); string orderprice = "" + String.Format("{0:.###}", order.getPrice()); string ordersize = "" + order.getVolume(); string owner = "\"" + order.getOwner().ToString() + "\""; line = status + "," + time + "," + price + "," + direction + "," + orderprice + "," + ordersize + "," + owner; Console.WriteLine(line); } OrderbookBoundaries newbdy = new OrderbookBoundaries(); newbdy.process(ob); if (_bdy.differentFrom(newbdy)) { Console.WriteLine("*** OB boundaries changed!! " + newbdy.ToString()); } _bdy = newbdy; using (FileStream fs = new FileStream("frames/OB-" + _tag + ".txt", FileMode.Append, FileAccess.Write)) using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine(line); } if (Scheduler.GetTime() - _LastDumpTime > DUMP_INTERVAL) { _LastDumpTime = Scheduler.GetTime(); using (FileStream fs = new FileStream("frames/BIDS-" + _tag + "-" + _DumpNumber + ".dat", FileMode.Append, FileAccess.Write)) using (StreamWriter sw = new StreamWriter(fs)) { if (_Virgin) { sw.WriteLine("#==================================="); _Virgin = true; } IDictionary <double, IList <IOrder_Mutable> > bids = ob.getBids_Mutable(); sw.WriteLine("# num bid: " + bids.Keys.Count); sw.WriteLine("# low bid: " + (ob.getNumBids() > 0 ? "" + ob.getLowestBid():"?")); sw.WriteLine("# high bid: " + (ob.getNumBids() > 0 ? "" + ob.getHighestBid():"?")); foreach (double price in bids.Keys) { IList <IOrder_Mutable> orders = bids[price]; double vol = 0; foreach (IOrder_Mutable o in orders) { vol += o.getVolume(); } sw.WriteLine("" + price + "," + vol + ""); } } using (FileStream fs = new FileStream("frames/ASKS-" + _tag + "-" + _DumpNumber + ".dat", FileMode.Append, FileAccess.Write)) using (StreamWriter sw = new StreamWriter(fs)) { if (_Virgin) { sw.WriteLine("#==================================="); _Virgin = true; } IDictionary <double, IList <IOrder_Mutable> > asks = ob.getAsks_Mutable(); sw.WriteLine("# num ask: " + asks.Keys.Count); sw.WriteLine("# low ask: " + (ob.getNumAsks() > 0 ? "" + ob.getLowestAsk():"?")); sw.WriteLine("# high ask: " + (ob.getNumAsks() > 0 ? "" + ob.getHighestAsk():"?")); foreach (double price in asks.Keys) { IList <IOrder_Mutable> orders = asks[price]; double vol = 0; foreach (IOrder_Mutable o in orders) { vol += o.getVolume(); } sw.WriteLine("" + price + "," + vol); } } using (FileStream fs = new FileStream("frames/GP-" + _tag + "-" + _DumpNumber + ".gp", FileMode.Append, FileAccess.Write)) using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine("set terminal postscript eps color"); sw.WriteLine("set output \"EPS-" + _tag + "-" + String.Format("{0:00000000}", _DumpNumber) + ".eps\""); sw.WriteLine("set title \"Orderbook at time=" + Scheduler.GetTime() + " in " + _tag + "\""); sw.WriteLine("set ylabel \"Orders (count)\""); sw.WriteLine("set xlabel \"Price\""); sw.WriteLine("binwidth=0.125"); sw.WriteLine("set boxwidth binwidth"); sw.WriteLine("bin(x,width)=width*floor(x/width) + binwidth/2.0"); sw.WriteLine("plot 'Asks-" + _tag + "-" + _DumpNumber + ".dat' using (bin($1,binwidth)):(1.0) smooth freq with boxes t \"ASKS " + _tag + "-" + _DumpNumber + "\" fs solid 0.50, 'Bids-" + _tag + "-" + _DumpNumber + ".dat' using (bin($1,binwidth)):(1.0) smooth freq with boxes t \"BIDS " + _tag + "-" + _DumpNumber + "\" fill empty"); } _DumpNumber++; } }