Crates.io | rust_ob |
lib.rs | rust_ob |
version | 2.5.3 |
source | src |
created_at | 2023-08-31 02:02:06.008425 |
updated_at | 2024-06-23 06:55:18.956111 |
description | an orderbook library for rust |
homepage | |
repository | https://github.com/toyota-corolla0/rust_ob |
max_upload_size | |
id | 959390 |
size | 42,172 |
An orderbook library for rust
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!()
}
}
}
}