Skip to content

Commit

Permalink
clear function to remove all orders
Browse files Browse the repository at this point in the history
  • Loading branch information
Kautenja committed Jan 25, 2020
1 parent c4134a3 commit 0e57c9e
Show file tree
Hide file tree
Showing 4 changed files with 520 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/limit_order_book.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class LimitOrderBook {
/// Initialize a new limit order book object.
LimitOrderBook() : sells(), buys(), orders() { }

/// Clear all the orders in the book.
void clear() {
sells.clear();
buys.clear();
orders.clear();
}

/// Add a new sell limit order to the book.
///
/// @param order_id the ID for the order
Expand Down
14 changes: 14 additions & 0 deletions include/limit_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ struct LimitTree {
size(0),
volume(0) { }

/// Clear all the limits in the tree
void clear() {
// delete all the limits
for(auto item = limits.begin(); item != limits.end(); item++)
delete item->second;
// clear the pairs from the map
limits.clear();
// set remaining tracers to 0
root = nullptr;
best = nullptr;
size = 0;
volume = 0;
}

/// Place a limit order on the limit tree.
///
/// @param order an order that matches the side of this tree
Expand Down
Loading

0 comments on commit 0e57c9e

Please sign in to comment.