Implementation:Avhz RustQuant OrderBook
| Knowledge Sources | |
|---|---|
| Domains | Order_Management, Quantitative_Finance |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
Concrete tool for a simple VecDeque-based order book implementation provided by the RustQuant library.
Description
The OrderBook struct provides a straightforward order book implementation using two VecDeque<Order> collections -- one for bids (buy orders) and one for asks (sell orders). This is a simpler alternative to the BTreeMap-based Book struct in the limit_order_book module. The VecDeque data structure allows efficient push/pop from both front and back, though as the documentation notes, it is not the most performant choice for production use. The struct provides new() for construction (const fn), insert_order() which routes an Order to the correct side based on its OrderSide, is_empty() to check if both sides are empty, and len() to get the total number of orders across both sides. The struct implements Default and derives Debug and Clone. Additional operations like best_bid/ask, cancel_order, amend_order, and match_orders are defined as commented-out stubs for future implementation.
Usage
Use this when you need a lightweight, simple order book for prototyping or educational purposes where the full complexity of a price-level-indexed limit order book is not required.
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_trading/src/order_book.rs
- Lines: 1-115
Signature
#[derive(Debug, Clone)]
pub struct OrderBook {
pub bids: VecDeque<Order>,
pub asks: VecDeque<Order>,
}
impl OrderBook {
pub const fn new() -> Self;
pub fn insert_order(&mut self, order: Order);
pub fn is_empty(&self) -> bool;
pub fn len(&self) -> usize;
}
Import
use RustQuant::trading::OrderBook;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| order | Order | Yes | An Order struct to insert into the book (routed by OrderSide) |
Outputs
| Name | Type | Description |
|---|---|---|
| OrderBook | struct | An order book with bid and ask sides |
| bool | is_empty() | True if both bid and ask sides have no orders |
| usize | len() | Total number of orders in the book (bids + asks) |
Usage Examples
use RustQuant::trading::{OrderBook, Order, OrderType, OrderSide, OrderTimeInForce};
use time::OffsetDateTime;
let mut book = OrderBook::new();
assert!(book.is_empty());
// Insert a bid order
let bid = Order {
id: 1,
symbol_id: 100,
order_type: OrderType::Limit,
order_side: OrderSide::BID,
price: 50.0,
stop_price: 0.0,
quantity: 200,
executed_quantity: 0,
leaves_quantity: 200,
time_in_force: OrderTimeInForce::GoodTillCancelled,
timestamp: OffsetDateTime::now_utc(),
};
book.insert_order(bid);
assert_eq!(book.len(), 1);
assert!(!book.is_empty());