Trading.OrderBook (trading v0.1.0)
Efficient limit order book implementation using ETS for O(log n) operations.
The order book maintains buy and sell sides with price-time priority.
Summary
Functions
Adds an order to the order book.
Gets the best bid and ask prices.
Cancels an order in the order book.
Gets the order book depth up to a certain level.
Gets all orders at a specific price level.
Gets market depth statistics.
Gets total volume at a specific price level.
Creates a new order book for a given symbol.
Gets the total number of orders in the book.
Types
Functions
@spec add_order(t(), Trading.Order.t()) :: {:ok, t()} | {:error, String.t()}
Adds an order to the order book.
Gets the best bid and ask prices.
Cancels an order in the order book.
@spec get_depth(t(), pos_integer()) :: %{bids: list(), asks: list()}
Gets the order book depth up to a certain level.
@spec get_orders_at_price(t(), float(), :buy | :sell) :: [Trading.Order.t()]
Gets all orders at a specific price level.
Gets market depth statistics.
@spec get_volume_at_price(t(), float(), :buy | :sell) :: non_neg_integer()
Gets total volume at a specific price level.
Creates a new order book for a given symbol.
@spec order_count(t()) :: non_neg_integer()
Gets the total number of orders in the book.