This library contains an optimized implementation of a Limit Order Book (LOB). It keeps the aggregate quantities at each level.
Note: Will add the comments describing the project later on.
- Add the library to your project.
- Import the
optimized_lob
struct fromoptimized-lob
. - The
orderbook_manager
struct contains all the functions you need to manage the LOB. You can perform add, cancel, execute, delete, and replace operations on the LOB. - There are individual wrapper structs as well that you might need to store price, quantity, order ID, book ID, etc.
A simple example demonstrating the use of library to add, delete, and replace orders.
extern crate optimized_lob;
use optimized_lob::{
order::OrderId, orderbook_manager::OrderBookManager, quantity::Qty, utils::BookId,
};
fn test_lob() {
let mut orderbook_manager = OrderBookManager::new();
// Add an order
orderbook_manager.add_order(
OrderId(0), // Order ID
BookId(0), // Book ID
Qty(100), // Quantity
600, // Price
true, // Is Bid
);
// Replace an order
orderbook_manager.replace_order(
OrderId(0), // Order ID to replace
OrderId(1), // New Order ID
Qty(50), // New Quantity
500, // New Price
);
// Remove an order
orderbook_manager.remove_order(OrderId(1));
}
See Also:
- CppTrader matching engine implementation
- A StackOverflow answer along with his implementation of an optimized LOB.
- This blog post gives a good idea for the low-level design of the orderbook.