20 stable releases
2.5.3 | Jun 23, 2024 |
---|---|
2.5.2 | Oct 19, 2023 |
2.2.1 | Sep 25, 2023 |
1.0.6 | Sep 2, 2023 |
1.0.5 | Aug 31, 2023 |
#62 in Finance
Used in rust_pie_ob
23KB
403 lines
rust_ob
An orderbook library for rust
Features
- standard price-time priority
- execution of limit and market orders
- support for negative prices
Usage
use rust_decimal::Decimal;
use rust_ob::{errors, OrderBook, Side};
fn main() {
// create orderbook
let mut ob = OrderBook::new();
// process limit order
{
let result = ob.process_limit_order(1, Side::Buy, Decimal::from(10), Decimal::from(10));
use errors::ProcessLimitOrder as E;
let order_match_vec = match result {
Ok(v) => v,
Err(E::OrderAlreadyExists) => {
// handle error
panic!()
}
Err(E::NonPositiveQuantity) => {
// handle error
panic!()
}
};
for order_match in order_match_vec {
// handle matches
// more information about order_match_vec can be found in documentation for OrderBook::process_limit_order
}
}
// cancel order
{
let result = ob.cancel_order(1);
use errors::CancelOrder as E;
match result {
Ok(()) => {}
Err(E::OrderNotFound) => {
// handle error
panic!()
}
}
}
}
Dependencies
~0.6–1MB
~19K SLoC