// cancel all pending orders` protected void CancelAllOpenOrders() { if (LoggerDiags.Enabled) { SingletonLogger.Instance().InfoLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " CancelAll @ " + Scheduler.GetTime()); } foreach (IOrder order in OpenOrders) { Orderbook.cancelOrder(order); } SetMetricValue(NumBids_METRICNAME, 0.0); SetMetricValue(NumAsks_METRICNAME, 0.0); _orders.Clear(); }
private void EvaluateAllOpenOrders() { IList <IOrder> toUnlist = new List <IOrder>(); foreach (IOrder openOrder in OpenOrders) { if (DecideToCancelOpenOrder(openOrder)) { if (LoggerDiags.Enabled) { SingletonLogger.Instance().DebugLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " cancels " + openOrder + " @ " + Scheduler.GetTime()); } toUnlist.Add(openOrder); Orderbook.cancelOrder(openOrder); } } foreach (IOrder listedOrder in toUnlist) { RemoveFromOpenOrderList(listedOrder); } }
public void Orderbook_CancelOrdersTest() { Console.WriteLine("Orderbook_CancelOrdersTest"); Orderbook ob = new Orderbook(); Matcher m = new Matcher(); ob.setMatcher(m); // no bids or asks Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 0); // place ask 1 IOrder o1 = ob.addAsk(10.0, 3, null); // place bid 2 IOrder o2 = ob.addBid(5.0, 3, null); // no bids or asks Assert.AreEqual(ob.getNumAsks(), 1); Assert.AreEqual(ob.getNumBids(), 1); bool cancelResult = ob.cancelOrder(o1); Assert.AreEqual(cancelResult, true); // no asks, 1 bid Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 1); Scheduler.Instance().Run(); // place bid 3 IOrder o3 = ob.addBid(10.0, 5, null); // no asks, 2 bid Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 2); Scheduler.Instance().Run(); // execution is attempted -- but nothing can execute // since o2 cannot match o3 Scheduler.Instance().Run(); Assert.AreEqual(o1.isFilled(), false); Assert.AreEqual(o1.isCancelled(), true); Assert.AreEqual(o1.getCapital(), 0.0); Assert.AreEqual(o2.isFilled(), false); Assert.AreEqual(o2.isCancelled(), false); Assert.AreEqual(o2.getCapital(), 0.0); Assert.AreEqual(o3.isFilled(), false); Assert.AreEqual(o3.isCancelled(), false); Assert.AreEqual(o3.getCapital(), 0.0); Assert.AreEqual(m.NumAddOrdersReceived, 3, "orders = 3"); Assert.AreEqual(m.NumFillsSent, 0, "fills = 0"); Assert.AreEqual(m.NumPartialFillsSent, 0, "partial fills = 0"); Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 2); }