public void TestFokAskPartialMatch() { var order_book = new SimpleOrderBook(); var ask2 = new SimpleOrder(false, 1252, 100); var ask1 = new SimpleOrder(false, 1251, 100); var ask0 = new SimpleOrder(false, 1250, 300); var bid0 = new SimpleOrder(true, 1250, 100); var bid1 = new SimpleOrder(true, 1249, 100); var bid2 = new SimpleOrder(true, 1248, 100); // No match Assert.IsTrue(AddAndVerify(order_book, ask1, false)); Assert.IsTrue(AddAndVerify(order_book, ask2, false)); Assert.IsTrue(AddAndVerify(order_book, bid0, false)); Assert.IsTrue(AddAndVerify(order_book, bid1, false)); Assert.IsTrue(AddAndVerify(order_book, bid2, false)); // Verify sizes Assert.AreEqual(3, order_book.Bids.Count()); Assert.AreEqual(2, order_book.Asks.Count()); // Verify depth var dc = new DepthCheck(order_book.Depth); Assert.IsTrue(dc.VerifyBid(1250, 1, 100)); Assert.IsTrue(dc.VerifyBid(1249, 1, 100)); Assert.IsTrue(dc.VerifyBid(1248, 1, 100)); Assert.IsTrue(dc.VerifyAsk(1251, 1, 100)); Assert.IsTrue(dc.VerifyAsk(1252, 1, 100)); // Partial Match - will not fill and will cancel order { var fc0 = new FillChecker(bid0, 0, 0); var fc1 = new FillChecker(bid1, 0, 0); var fc2 = new FillChecker(bid2, 0, 0); var fc3 = new FillChecker(ask0, 0, 0, FOK); var fc4 = new FillChecker(ask1, 0, 0); var fc5 = new FillChecker(ask2, 0, 0); Assert.IsTrue(AddAndVerify(order_book, ask0, false, false, FOK)); fc0.AssertFillSuccess(); fc1.AssertFillSuccess(); fc2.AssertFillSuccess(); fc3.AssertFillSuccess(); fc4.AssertFillSuccess(); fc5.AssertFillSuccess(); } // Verify sizes Assert.AreEqual(3, order_book.Bids.Count()); Assert.AreEqual(2, order_book.Asks.Count()); // Verify depth dc.Reset(); Assert.IsTrue(dc.VerifyBid(1250, 1, 100)); Assert.IsTrue(dc.VerifyBid(1249, 1, 100)); Assert.IsTrue(dc.VerifyBid(1248, 1, 100)); Assert.IsTrue(dc.VerifyAsk(1251, 1, 100)); Assert.IsTrue(dc.VerifyAsk(1252, 1, 100)); }
public void TestIocBidFullMatch() { var order_book = new SimpleOrderBook(); var ask2 = new SimpleOrder(false, 1252, 100); var ask1 = new SimpleOrder(false, 1251, 100); var ask0 = new SimpleOrder(false, 1250, 400); var bid0 = new SimpleOrder(true, 1250, 300); var bid1 = new SimpleOrder(true, 1249, 100); var bid2 = new SimpleOrder(true, 1248, 100); // No match Assert.True(AddAndVerify(order_book, ask0, false)); Assert.True(AddAndVerify(order_book, ask1, false)); Assert.True(AddAndVerify(order_book, ask2, false)); Assert.True(AddAndVerify(order_book, bid1, false)); Assert.True(AddAndVerify(order_book, bid2, false)); // Verify sizes Assert.Equal(2, order_book.Bids.Count()); Assert.Equal(3, order_book.Asks.Count()); // Verify depth var dc = new DepthCheck(order_book.Depth); Assert.True(dc.VerifyBid(1249, 1, 100)); Assert.True(dc.VerifyBid(1248, 1, 100)); Assert.True(dc.VerifyAsk(1250, 1, 400)); Assert.True(dc.VerifyAsk(1251, 1, 100)); Assert.True(dc.VerifyAsk(1252, 1, 100)); // Full Match - will complete order { var fc0 = new FillChecker(bid0, 300, 1250 * 300, IOC); var fc1 = new FillChecker(bid1, 0, 0); var fc2 = new FillChecker(bid2, 0, 0); var fc3 = new FillChecker(ask0, 300, 1250 * 300); var fc4 = new FillChecker(ask1, 0, 0); var fc5 = new FillChecker(ask2, 0, 0); Assert.True(AddAndVerify(order_book, bid0, true, true, IOC)); fc0.AssertFillSuccess(); fc1.AssertFillSuccess(); fc2.AssertFillSuccess(); fc3.AssertFillSuccess(); fc4.AssertFillSuccess(); fc5.AssertFillSuccess(); } // Verify sizes Assert.Equal(2, order_book.Bids.Count()); Assert.Equal(3, order_book.Asks.Count()); // Verify depth dc.Reset(); Assert.True(dc.VerifyBid(1249, 1, 100)); Assert.True(dc.VerifyBid(1248, 1, 100)); Assert.True(dc.VerifyAsk(1250, 1, 100)); Assert.True(dc.VerifyAsk(1251, 1, 100)); Assert.True(dc.VerifyAsk(1252, 1, 100)); }
public void TestRegAskMatchMulti() { var order_book = new SimpleOrderBook(); var ask0 = new SimpleOrder(sellSide, prc2, qty1); var ask1 = new SimpleOrder(sellSide, prc0, qty4); var bid1 = new SimpleOrder(buySide, prc1, qty1); // AON var bid2 = new SimpleOrder(buySide, prc1, qty1); // AON var bid0 = new SimpleOrder(buySide, prc0, qty7); // Calculate some expected results // ask1(400) matches bid 1(100), bid2(100), and part(200) of bid0 // leaving 500 shares of bid 0) Quantity bid0FillQty = qty4 - qty1 - qty1; Quantity bid0RemainQty = qty7 - bid0FillQty; decimal bid0FillAmount = bid0FillQty * prc0; decimal bid1FillAmount = prc1 * qty1; decimal bid2FillAmount = prc1 * qty1; decimal ask1FillAmount = bid1FillAmount + bid2FillAmount + bid0FillAmount; // No match Assert.IsTrue(AddAndVerify(order_book, ask0, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, bid0, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, bid1, expectNoMatch, expectNoComplete, AON)); Assert.IsTrue(AddAndVerify(order_book, bid2, expectNoMatch, expectNoComplete, AON)); // Verify sizes Assert.AreEqual(3, order_book.Bids.Count()); Assert.AreEqual(1, order_book.Asks.Count()); // Verify depth var dc = new DepthCheck(order_book.Depth); Assert.IsTrue(dc.VerifyBid(prc1, 2, qty2)); Assert.IsTrue(dc.VerifyBid(prc0, 1, qty7)); Assert.IsTrue(dc.VerifyAsk(prc2, 1, qty1)); // Match - complete { var fc0 = new FillChecker(bid1, qty1, prc1 * qty1); var fc1 = new FillChecker(bid2, qty1, prc1 * qty1); var fc2 = new FillChecker(bid0, qty2, prc0 * qty2); var fc3 = new FillChecker(ask1, qty4, ask1FillAmount); Assert.IsTrue(AddAndVerify(order_book, ask1, expectMatch, expectComplete)); fc0.AssertFillSuccess(); fc1.AssertFillSuccess(); fc2.AssertFillSuccess(); fc3.AssertFillSuccess(); } // Verify depth dc.Reset(); Assert.IsTrue(dc.VerifyBid(prc0, 1, bid0RemainQty)); Assert.IsTrue(dc.VerifyAsk(prc2, 1, qty1)); // Verify sizes Assert.AreEqual(1, order_book.Bids.Count()); Assert.AreEqual(1, order_book.Asks.Count()); }
public void TestAonAskNoMatchMulti() { var order_book = new SimpleOrderBook(); var ask0 = new SimpleOrder(sellSide, prc2, qty1); // no match (price) var ask1 = new SimpleOrder(sellSide, prc0, qty6); // AON var bid0 = new SimpleOrder(buySide, prc0, qty4); // AON no match var bid1 = new SimpleOrder(buySide, prc1, qty1); // AON var bid2 = new SimpleOrder(buySide, prc1, qty4); // No match Assert.IsTrue(AddAndVerify(order_book, ask0, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, bid0, expectNoMatch, expectNoComplete, AON)); Assert.IsTrue(AddAndVerify(order_book, bid1, expectNoMatch, expectNoComplete, AON)); //AON)); //noConditions Assert.IsTrue(AddAndVerify(order_book, bid2, expectNoMatch)); // Verify sizes Assert.AreEqual(3, order_book.Bids.Count()); Assert.AreEqual(1, order_book.Asks.Count()); // Verify depth var dc = new DepthCheck(order_book.Depth); Assert.IsTrue(dc.VerifyBid(prc1, 2, qty1 + qty4)); Assert.IsTrue(dc.VerifyBid(prc0, 1, qty4)); Assert.IsTrue(dc.VerifyAsk(prc2, 1, qty1)); // This test was bogus -- testing a bug in the matching algorithm // I fixed the bug and the test started to fail. // So fixed the test to expect: // Ask1 (600 AON) should match bid0 (400 AON) + bid1(100) + bid 2(100 of 400) // // Now we need a new test of an AON that should NOT match! // No match { // ASSERT_NO_THROW( var fc0 = new FillChecker(bid0, qty4, prc0 * qty4); var fc1 = new FillChecker(bid1, qty1, qty1 * prc1); var fc2 = new FillChecker(bid2, qty1, prc1 * qty1); var fc3 = new FillChecker(ask1, qty6, prc0 * qty4 + qty1 * prc1 + prc1 * qty1); Assert.IsTrue(AddAndVerify(order_book, ask1, expectMatch, expectComplete, AON)); fc0.AssertFillSuccess(); fc1.AssertFillSuccess(); fc2.AssertFillSuccess(); fc3.AssertFillSuccess(); //); } // Verify depth dc.Reset(); Assert.IsTrue(dc.VerifyBid(prc1, 1, qty4 - qty1)); // Verify sizes Assert.AreEqual(1, order_book.Bids.Count()); Assert.AreEqual(1, order_book.Asks.Count()); }
public void TestAonBidMatchMulti() { var order_book = new SimpleOrderBook(); var ask3 = new SimpleOrder(sellSide, prc2, qty1); var ask2 = new SimpleOrder(sellSide, prc2, qty1); var ask1 = new SimpleOrder(sellSide, prc1, qty4); // AON no match var ask0 = new SimpleOrder(sellSide, prc1, qty4); var bid1 = new SimpleOrder(buySide, MARKET_ORDER_PRICE, qty6); // AON var bid0 = new SimpleOrder(buySide, prc0, qty1); // No match Assert.IsTrue(AddAndVerify(order_book, bid0, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, ask0, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, ask1, expectNoMatch, expectNoComplete, AON)); Assert.IsTrue(AddAndVerify(order_book, ask2, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, ask3, expectNoMatch)); // Verify sizes Assert.AreEqual(1, order_book.Bids.Count()); Assert.AreEqual(4, order_book.Asks.Count()); // Verify depth var dc = new DepthCheck(order_book.Depth); Assert.IsTrue(dc.VerifyBid(prc0, 1, qty1)); Assert.IsTrue(dc.VerifyAsk(prc1, 2, qty4 + qty4)); Assert.IsTrue(dc.VerifyAsk(prc2, 2, qty1 + qty1)); // Match - complete { //ASSERT_NO_THROW( var fc1 = new FillChecker(bid1, qty6, prc1 * qty2 + prc1 * qty4); var fc2 = new FillChecker(ask0, qty2, prc1 * qty2); var fc3 = new FillChecker(ask1, qty4, prc1 * qty4); var fc4 = new FillChecker(ask2, 0, prc2 * (Quantity)0); var fc5 = new FillChecker(ask3, 0, prc2 * (Quantity)0); Assert.IsTrue(AddAndVerify(order_book, bid1, expectMatch, expectComplete, AON)); fc1.AssertFillSuccess(); fc2.AssertFillSuccess(); fc3.AssertFillSuccess(); fc4.AssertFillSuccess(); fc5.AssertFillSuccess(); //); } // Verify depth dc.Reset(); Assert.IsTrue(dc.VerifyBid(prc0, 1, qty1)); Assert.IsTrue(dc.VerifyAsk(prc1, 1, qty2)); Assert.IsTrue(dc.VerifyAsk(prc2, 2, qty1 + qty1)); // Verify sizes Assert.AreEqual(1, order_book.Bids.Count()); Assert.AreEqual(3, order_book.Asks.Count()); }
public void TestAonAskNoMatch() { var order_book = new SimpleOrderBook(); var ask0 = new SimpleOrder(sellSide, prc2, qty1); var ask1 = new SimpleOrder(sellSide, prc1, qty4); // AON var bid1 = new SimpleOrder(buySide, prc1, qty1); var bid2 = new SimpleOrder(buySide, prc1, qty1); var bid0 = new SimpleOrder(buySide, prc0, qty7); // No match Assert.IsTrue(AddAndVerify(order_book, ask0, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, bid0, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, bid1, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, bid2, expectNoMatch)); // Verify sizes Assert.AreEqual(3, order_book.Bids.Count()); Assert.AreEqual(1, order_book.Asks.Count()); // Verify depth var dc = new DepthCheck(order_book.Depth); Assert.IsTrue(dc.VerifyBid(prc1, 2, qty2)); Assert.IsTrue(dc.VerifyBid(prc0, 1, qty7)); Assert.IsTrue(dc.VerifyAsk(prc2, 1, qty1)); // Match - complete { var fc0 = new FillChecker(bid1, qtyNone, prcNone); var fc1 = new FillChecker(bid2, qtyNone, prcNone); var fc2 = new FillChecker(bid0, qtyNone, prcNone); var fc3 = new FillChecker(ask1, qtyNone, prcNone); Assert.IsTrue(AddAndVerify(order_book, ask1, expectNoMatch, expectNoComplete, AON)); fc0.AssertFillSuccess(); fc1.AssertFillSuccess(); fc2.AssertFillSuccess(); fc3.AssertFillSuccess(); } // Verify depth dc.Reset(); Assert.IsTrue(dc.VerifyBid(prc1, 2, qty2)); Assert.IsTrue(dc.VerifyBid(prc0, 1, qty7)); Assert.IsTrue(dc.VerifyAsk(prc1, 1, qty4)); Assert.IsTrue(dc.VerifyAsk(prc2, 1, qty1)); // Verify sizes Assert.AreEqual(3, order_book.Bids.Count()); Assert.AreEqual(2, order_book.Asks.Count()); }
public void TestAonBidNoMatchMulti() { var order_book = new SimpleOrderBook(); var ask2 = new SimpleOrder(sellSide, prc2, qty4); // AON no match var ask1 = new SimpleOrder(sellSide, prc2, qty1); var ask0 = new SimpleOrder(sellSide, prc1, qty4); var bid1 = new SimpleOrder(buySide, MARKET_ORDER_PRICE, qty6); // AON var bid0 = new SimpleOrder(buySide, prc0, qty1); // No match Assert.IsTrue(AddAndVerify(order_book, bid0, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, ask0, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, ask1, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, ask2, expectNoMatch, expectNoComplete, AON)); // Verify sizes Assert.AreEqual(1, order_book.Bids.Count()); Assert.AreEqual(3, order_book.Asks.Count()); // Verify depth var dc = new DepthCheck(order_book.Depth); Assert.IsTrue(dc.VerifyBid(prc0, 1, qty1)); Assert.IsTrue(dc.VerifyAsk(prc1, 1, qty4)); Assert.IsTrue(dc.VerifyAsk(prc2, 2, qty4 + qty1)); // Match - complete { //ASSERT_NO_THROW( var fc0 = new FillChecker(bid0, qtyNone, prcNone); var fc1 = new FillChecker(bid1, qty6, qty2 * prc1 + qty4 * prc2); // filled 600 @ 751000 var fc2 = new FillChecker(ask0, qty2, qty2 * prc1); // filled 200 @ 250200 var fc3 = new FillChecker(ask1, qtyNone, prcNone); // 0 var fc4 = new FillChecker(ask2, qty4, qty4 * prc2); // filled 400 @ 500800 Assert.IsTrue(AddAndVerify(order_book, bid1, expectMatch, expectComplete, AON)); fc0.AssertFillSuccess(); fc1.AssertFillSuccess(); fc2.AssertFillSuccess(); fc3.AssertFillSuccess(); fc4.AssertFillSuccess(); //); } // Verify depth dc.Reset(); Assert.IsTrue(dc.VerifyBid(prc0, 1, qty1)); Assert.IsTrue(dc.VerifyAsk(prc1, 1, qty2)); }
public void TestReplaceAonBidPriceMatch() { var order_book = new SimpleOrderBook(); var ask2 = new SimpleOrder(sellSide, prc3, qty1); var ask1 = new SimpleOrder(sellSide, prc2, qty1); var ask0 = new SimpleOrder(sellSide, prc1, qty1); var bid1 = new SimpleOrder(buySide, prc1, qty2); // AON var bid0 = new SimpleOrder(buySide, prc0, qty1); // No match Assert.True(AddAndVerify(order_book, bid0, expectNoMatch)); Assert.True(AddAndVerify(order_book, bid1, expectNoMatch, expectNoComplete, AON)); Assert.True(AddAndVerify(order_book, ask0, expectNoMatch)); Assert.True(AddAndVerify(order_book, ask1, expectNoMatch)); Assert.True(AddAndVerify(order_book, ask2, expectNoMatch)); // Verify sizes Assert.Equal(2, order_book.Bids.Count()); Assert.Equal(3, order_book.Asks.Count()); // Verify depth var dc = new DepthCheck(order_book.Depth); Assert.True(dc.VerifyBid(prc1, 1, qty2)); Assert.True(dc.VerifyBid(prc0, 1, qty1)); Assert.True(dc.VerifyAsk(prc1, 1, qty1)); Assert.True(dc.VerifyAsk(prc2, 1, qty1)); Assert.True(dc.VerifyAsk(prc3, 1, qty1)); // Match - complete { var fc1 = new FillChecker(ask0, qty1, prc1 * qty1); var fc2 = new FillChecker(ask1, qty1, prc2 * qty1); Assert.True(ReplaceAndVerify( order_book, bid1, qtyNone, prc2, OrderState.Complete, qty2)); fc1.AssertFillSuccess(); fc2.AssertFillSuccess(); } // Verify depth dc.Reset(); Assert.True(dc.VerifyBid(prc0, 1, qty1)); Assert.True(dc.VerifyAsk(prc3, 1, qty1)); // Verify sizes Assert.Equal(1, order_book.Bids.Count()); Assert.Equal(1, order_book.Asks.Count()); }
public void TestRegBidMatchMulti() { var order_book = new SimpleOrderBook(); var ask2 = new SimpleOrder(sellSide, prc1, qty7); var ask1 = new SimpleOrder(sellSide, prc1, qty1); // AON var ask0 = new SimpleOrder(sellSide, prc1, qty1); // AON var bid1 = new SimpleOrder(buySide, prc1, qty4); var bid0 = new SimpleOrder(buySide, prc0, qty1); // No match Assert.True(AddAndVerify(order_book, bid0, expectNoMatch)); Assert.True(AddAndVerify(order_book, ask0, expectNoMatch, expectNoComplete, AON)); Assert.True(AddAndVerify(order_book, ask1, expectNoMatch, expectNoComplete, AON)); Assert.True(AddAndVerify(order_book, ask2, expectNoMatch, expectNoComplete)); // Verify sizes Assert.Equal(1, order_book.Bids.Count()); Assert.Equal(3, order_book.Asks.Count()); // Verify depth var dc = new DepthCheck(order_book.Depth); Assert.True(dc.VerifyBid(prc0, 1, qty1)); Assert.True(dc.VerifyAsk(prc1, 3, qty7 + qty1 + qty1)); // Match - complete { var fc0 = new FillChecker(bid1, qty4, prc1 * qty4); var fc1 = new FillChecker(ask0, qty1, prc1 * qty1); var fc2 = new FillChecker(ask1, qty1, prc1 * qty1); var fc3 = new FillChecker(ask2, qty2, prc1 * qty2); Assert.True(AddAndVerify(order_book, bid1, expectMatch, expectComplete)); fc0.AssertFillSuccess(); fc1.AssertFillSuccess(); fc2.AssertFillSuccess(); fc3.AssertFillSuccess(); } // Verify depth dc.Reset(); Assert.True(dc.VerifyBid(prc0, 1, qty1)); Assert.True(dc.VerifyAsk(prc1, 1, qty4 + qty1)); // Verify sizes Assert.Equal(1, order_book.Bids.Count()); Assert.Equal(1, order_book.Asks.Count()); }
public void TestAonAskMatchMulti() { var order_book = new SimpleOrderBook(); var ask0 = new SimpleOrder(sellSide, prc2, qty1); // no match due to price var ask1 = new SimpleOrder(sellSide, prc0, qty6); // AON var bid1 = new SimpleOrder(buySide, prc1, qty1); // AON var bid2 = new SimpleOrder(buySide, prc1, qty1); var bid3 = new SimpleOrder(buySide, prc1, qty1); var bid0 = new SimpleOrder(buySide, prc0, qty7); // No match Assert.IsTrue(AddAndVerify(order_book, ask0, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, bid0, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, bid1, expectNoMatch, expectNoComplete, AON)); Assert.IsTrue(AddAndVerify(order_book, bid2, expectNoMatch)); Assert.IsTrue(AddAndVerify(order_book, bid3, expectNoMatch)); // Verify sizes Assert.AreEqual(4, order_book.Bids.Count()); Assert.AreEqual(1, order_book.Asks.Count()); // Verify depth var dc = new DepthCheck(order_book.Depth); Assert.IsTrue(dc.VerifyBid(prc1, 3, qty3)); Assert.IsTrue(dc.VerifyBid(prc0, 1, qty7)); Assert.IsTrue(dc.VerifyAsk(prc2, 1, qty1)); // Match - complete { // ASSERT_NO_THROW( decimal b1Cost = prc1 * qty1; var fc0 = new FillChecker(bid1, qty1, b1Cost); decimal b2Cost = prc1 * qty1; var fc1 = new FillChecker(bid2, qty1, b2Cost); decimal b3Cost = prc1 * qty1; var fc2 = new FillChecker(bid3, qty1, b3Cost); Quantity b0Fill = qty6 - qty1 - qty1 - qty1; decimal b0Cost = b0Fill * prc0; var fc3 = new FillChecker(bid0, b0Fill, b0Cost); decimal a1Cost = b0Cost + b1Cost + b2Cost + b3Cost; var fc4 = new FillChecker(ask1, qty6, a1Cost); Assert.IsTrue(AddAndVerify(order_book, ask1, expectMatch, expectComplete, AON)); fc0.AssertFillSuccess(); fc1.AssertFillSuccess(); fc2.AssertFillSuccess(); fc3.AssertFillSuccess(); fc4.AssertFillSuccess(); // ); } // Verify depth dc.Reset(); Assert.IsTrue(dc.VerifyBid(prc0, 1, qty4)); Assert.IsTrue(dc.VerifyAsk(prc2, 1, qty1)); // Verify sizes Assert.AreEqual(1, order_book.Bids.Count()); Assert.AreEqual(1, order_book.Asks.Count()); }