Many helper functions are omitted for brevity.
Book
struct Book {
    MarketConfig marketConfig;
    TokenConfig tokenConfig;
    uint256 quoteTokenOpenInterestInAtoms;
    uint256 baseTokenOpenInterestInAtoms;
    uint256 nextOrderId;
    uint256 numBids;
    uint256 numAsks;
    RedBlackTree bidTree;
    RedBlackTree askTree;
    mapping(uint256 => Order) orders;
    mapping(uint256 => Limit) bidLimits;
    mapping(uint256 => Limit) askLimits;
}

removeOrderFromBook

removeOrderFromBook
function removeOrderFromBook(
    Book storage self, 
    Order memory order
) internal

Removes a specified order from the book, updating the relevant limits and open interest.

addOrderToBook

addOrderToBook
function addOrderToBook(
    Book storage self, 
    Order memory order
) internal

Adds a new order to the book, updating the relevant limits and open interest.

getOrder

getOrder
function getOrder(
    Book storage self, 
    uint256 orderId
) internal view returns (Order storage)

Retrieves an order from the book using the specified order ID.

getLimit

getLimit
function getLimit(
    Book storage self, 
    uint256 priceInTicks, 
    Side side
) internal view returns (Limit storage)

Retrieves the limit at a specified price and side (buy or sell) from the book.

getMaxBidPriceInTicks

getMaxBidPriceInTicks
function getMaxBidPriceInTicks(
    Book storage self
) internal view returns (uint256)

Returns the maximum bid price in ticks from the book.

getMinBidPriceInTicks

getMinBidPriceInTicks
function getMinBidPriceInTicks(
    Book storage self
) internal view returns (uint256)

Returns the minimum bid price in ticks from the book.

getMaxAskPriceInTicks

getMaxAskPriceInTicks
function getMaxAskPriceInTicks(
    Book storage self
) internal view returns (uint256)

Returns the maximum ask price in ticks from the book.

getMinAskPriceInTicks

getMinAskPriceInTicks
function getMinAskPriceInTicks(
    Book storage self
) internal view returns (uint256)

Returns the minimum ask price in ticks from the book.

getMaxNumOrders

getMaxNumOrders
function getMaxNumOrders(
    Book storage self
) internal view returns (uint256)

Returns the maximum number of orders allowed in the book.

getTOB

getTOB
function getTOB(
    Book storage self
) internal view returns (uint256, uint256)

Returns the top of book prices, which are the maximum bid and minimum ask prices.

getNextBiggestTick

getNextBiggestTick
function getNextBiggestTick(
    Book storage self, 
    uint256 priceInTicks, 
    Side side
) internal view returns (uint256)

Finds the next biggest price tick on the specified side (buy or sell) in the book.

getNextSmallestTick

getNextSmallestTick
function getNextSmallestTick(
    Book storage self, 
    uint256 priceInTicks, 
    Side side
) internal view returns (uint256)

Finds the next smallest price tick on the specified side (buy or sell) in the book.

getOrders

getOrders
function getOrders(
    Book storage self, 
    uint256 startOrderId, 
    uint256 numOrders
) internal view returns (Order[] memory)

Retrieves a specified number of orders starting from a given order ID.

getBidLimit

getBidLimit
function getBidLimit(
    Book storage self, 
    uint256 priceInTicks
) internal view returns (Limit storage)

Retrieves the bid limit at a specified tick price from the book.

getAskLimit

getAskLimit
function getAskLimit(
    Book storage self, 
    uint256 priceInTicks
) internal view returns (Limit storage)

Retrieves the ask limit at a specified tick price from the book.

getOpenInterest

getOpenInterest
function getOpenInterest(
    Book storage self
) internal view returns (uint256, uint256)

Returns the current open interest for both quote and base tokens in atoms.