orderbook/
lib.rs

1//! # orderbook-rs
2//!
3//! I did this orderbook in addition to <https://github.com/inv2004/coinbase-pro-rs>
4//!
5//! For performance I put it in flat array, that is why it uses memory actively.
6//! For current coinbase BTC-USD pair it takes 188.1 Mb or RAM.
7//!
8//! It has hardcoded limit for 20000(max price) * 100(cents) = 2*10^6 values it can store.
9//! Call the OB with values which are outside these boundaries will return None,
10//! but, I suppose, this return can be ignored in most cases.
11//!
12
13extern crate uuid;
14#[macro_use] extern crate failure;
15
16type Result<T> = std::result::Result<T, Error>;
17
18#[derive(Debug, Fail)]
19pub enum Error {
20    #[fail(display = "range")]
21    Range,
22    #[fail(display = "bid_less_ask")]
23    BidLessAsk,
24    #[fail(display = "match_uuid")]
25    MatchUuid,
26    #[fail(display = "test price is not bid or ask")]
27    TestFail
28}
29
30pub(crate) const MAX_SIZE: usize = 20000 * 100;
31
32#[derive(Debug)]
33pub enum Side {
34    Buy,
35    Sell,
36}
37
38#[derive(Debug)]
39pub struct BookRecord {
40    pub price: f64,
41    pub size: f64,
42    pub id: uuid::Uuid,
43}
44
45pub mod ob;
46pub use ob::OrderBook;