rust_ob

Crates.iorust_ob
lib.rsrust_ob
version2.5.3
sourcesrc
created_at2023-08-31 02:02:06.008425
updated_at2024-06-23 06:55:18.956111
descriptionan orderbook library for rust
homepage
repositoryhttps://github.com/toyota-corolla0/rust_ob
max_upload_size
id959390
size42,172
(toyota-corolla0)

documentation

https://docs.rs/rust_ob/latest/rust_ob/

README

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!()
            }
        }
    }
}
Commit count: 91

cargo fmt