Skip to content

Commit

Permalink
Merge pull request enewhuis#13 from thakkarparth007/find_bidask_bug
Browse files Browse the repository at this point in the history
Fix bug in find_bid and find_ask
  • Loading branch information
dale-wilson committed Jan 11, 2017
2 parents 38fa592 + a3998ab commit d0f0df4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/book/order_book.h
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ OrderBook<OrderPtr>::find_bid(
break;
// Else if this bid's price is too low to match the search price
} else if (result->first < search_price) {
result = bids_.end();
break; // No more possible
}
}
Expand All @@ -805,6 +806,7 @@ OrderBook<OrderPtr>::find_ask(
break;
// Else if this ask's price is too high to match the search price
} else if (result->first > search_price) {
result = asks_.end();
break; // No more possible
}
}
Expand Down
12 changes: 9 additions & 3 deletions test/unit/ut_order_book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,28 +936,34 @@ TEST(TestMatchMultipleMarketOrderAsk)
TEST(TestCancelBid)
{
SimpleOrderBook order_book;
SimpleOrder ask1(false, 1252, 100);
SimpleOrder ask2(false, 1252, 100);
SimpleOrder ask1(false, 1251, 100);
SimpleOrder ask0(false, 1251, 100);
SimpleOrder bid0(true, 1250, 100);

// No match
ASSERT_TRUE(add_and_verify(order_book, &bid0, false));
ASSERT_TRUE(add_and_verify(order_book, &ask0, false));
ASSERT_TRUE(add_and_verify(order_book, &ask1, false));
ASSERT_TRUE(add_and_verify(order_book, &ask2, false));

// Verify sizes
ASSERT_EQ(1, order_book.bids().size());
ASSERT_EQ(2, order_book.asks().size());
ASSERT_EQ(3, order_book.asks().size());

// Verify depth
DepthCheck dc(order_book.depth());
ASSERT_TRUE(dc.verify_bid(1250, 1, 100));
ASSERT_TRUE(dc.verify_ask(1251, 1, 100));
ASSERT_TRUE(dc.verify_ask(1251, 2, 200));
ASSERT_TRUE(dc.verify_ask(1252, 1, 100));

// Cancel bid
ASSERT_TRUE(cancel_and_verify(order_book, &bid0, impl::os_cancelled));

// Cancel correctness
ASSERT_TRUE(cancel_and_verify(order_book, &ask1, impl::os_cancelled));
ASSERT_TRUE(cancel_and_verify(order_book, &ask1, impl::os_cancelled));

// Verify depth
dc.reset();
ASSERT_TRUE(dc.verify_bid(0, 0, 0));
Expand Down

0 comments on commit d0f0df4

Please sign in to comment.