Skip to content

Commit

Permalink
cleanup head/tail
Browse files Browse the repository at this point in the history
  • Loading branch information
geseq committed Jan 29, 2024
1 parent 2503205 commit 60493b2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
3 changes: 1 addition & 2 deletions include/orderqueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ class OrderQueue : public boost::intrusive::set_base_hook<boost::intrusive::opti
[[nodiscard]] Decimal price() const;
uint64_t len();
[[nodiscard]] Decimal totalQty() const;
[[nodiscard]] Order *head();
[[nodiscard]] Order *tail();
void append(Order *o);
void remove(Order *o);
Decimal process(const TradeNotification &tn, const PostOrderFill &postFill, OrderID takerOrderID, Decimal qty);
[[nodiscard]] const OrderList &order_list() const { return orders_; }

friend bool operator<(const OrderQueue &a, const OrderQueue &b) { return a.price_ < b.price_; }
friend bool operator>(const OrderQueue &a, const OrderQueue &b) { return a.price_ > b.price_; }
Expand Down
2 changes: 1 addition & 1 deletion include/pricelevel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PriceLevel {
template <PriceType Q = P>
Decimal processLimitOrder(const TradeNotification& tn, const PostOrderFill& pf, OrderID takerOrderID, Decimal price, Decimal qty, Flag flag);

PriceTree& price_tree() { return price_tree_; };
const PriceTree& price_tree() const { return price_tree_; };
};

} // namespace orderbook
Expand Down
4 changes: 0 additions & 4 deletions src/orderqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

namespace orderbook {

Order* OrderQueue::head() { return &orders_.front(); }

Order* OrderQueue::tail() { return &orders_.back(); }

Decimal OrderQueue::price() const { return price_; }

Decimal OrderQueue::totalQty() const { return total_qty_; }
Expand Down
15 changes: 6 additions & 9 deletions test/orderqueue_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

#include "util.cpp"

namespace orderbook {

namespace test {
namespace orderbook::test {

class OrderQueueTest : public ::testing::Test {
protected:
Expand All @@ -25,8 +23,8 @@ TEST_F(OrderQueueTest, TestOrderQueue) {
oq->append(&o1);
oq->append(&o2);

auto* head = oq->head();
auto* tail = oq->tail();
auto* head = &oq->order_list().front();
auto* tail = &oq->order_list().back();

ASSERT_NE(head, nullptr);
ASSERT_NE(tail, nullptr);
Expand All @@ -36,8 +34,8 @@ TEST_F(OrderQueueTest, TestOrderQueue) {

oq->remove(&o1);

ASSERT_EQ(oq->head(), &o2);
ASSERT_EQ(oq->head(), oq->tail());
ASSERT_EQ(&oq->order_list().front(), &o2);
ASSERT_EQ(oq->order_list().front(), oq->order_list().back());

ASSERT_EQ(oq->len(), 1);
ASSERT_EQ(oq->totalQty(), Decimal(100, 0));
Expand All @@ -46,6 +44,5 @@ TEST_F(OrderQueueTest, TestOrderQueue) {
oq->remove(&o2);
}

} // namespace test
} // namespace orderbook
} // namespace orderbook::test

8 changes: 4 additions & 4 deletions test/pricelevel_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ TEST_F(PriceLevelTest, TestPriceLevel) {
ASSERT_EQ(bidLevel.depth(), 2);
ASSERT_EQ(bidLevel.len(), 2);

ASSERT_EQ(tree.begin()->head(), o2.get()) << "Invalid price levels: head of the first element does not match o1";
ASSERT_EQ(tree.begin()->tail(), o2.get()) << "Invalid price levels: tail of the first element does not match o1";
ASSERT_EQ(tree.rbegin()->head(), o1.get()) << "Invalid price levels: head of the last element does not match o2";
ASSERT_EQ(tree.rbegin()->tail(), o1.get()) << "Invalid price levels: tail of the last element does not match o2";
ASSERT_EQ(&tree.begin()->order_list().front(), o2.get()) << "Invalid price levels: head of the first element does not match o1";
ASSERT_EQ(&tree.begin()->order_list().back(), o2.get()) << "Invalid price levels: tail of the first element does not match o1";
ASSERT_EQ(&tree.rbegin()->order_list().front(), o1.get()) << "Invalid price levels: head of the last element does not match o2";
ASSERT_EQ(&tree.rbegin()->order_list().back(), o1.get()) << "Invalid price levels: tail of the last element does not match o2";

bidLevel.remove(o1.get());

Expand Down

0 comments on commit 60493b2

Please sign in to comment.