Trading.OrderBook.PriceLevel (trading v0.1.0)

Represents a price level in the order book with efficient order management.

Summary

Functions

Adds an order to the price level.

Checks if the price level is empty.

Creates a new price level.

Gets the first order in the level (price-time priority).

Removes and returns the first order.

Removes an order from the price level.

Converts the price level to a list of orders.

Updates an order in the price level.

Types

t()

@type t() :: %Trading.OrderBook.PriceLevel{
  order_count: non_neg_integer(),
  orders: :queue.queue(Trading.Order.t()),
  price: float(),
  side: :buy | :sell,
  total_volume: non_neg_integer()
}

Functions

add_order(level, order)

@spec add_order(t(), Trading.Order.t()) :: t()

Adds an order to the price level.

empty?(arg1)

@spec empty?(t()) :: boolean()

Checks if the price level is empty.

new(price, side)

@spec new(float(), :buy | :sell) :: t()

Creates a new price level.

peek_first(price_level)

@spec peek_first(t()) :: Trading.Order.t() | nil

Gets the first order in the level (price-time priority).

pop_first(level)

@spec pop_first(t()) :: {t(), Trading.Order.t() | nil}

Removes and returns the first order.

remove_order(level, order_id)

@spec remove_order(t(), String.t()) :: {t(), Trading.Order.t() | nil}

Removes an order from the price level.

to_list(price_level)

@spec to_list(t()) :: [Trading.Order.t()]

Converts the price level to a list of orders.

update_order(level, order_id, update_fn)

@spec update_order(t(), String.t(), (Trading.Order.t() -> Trading.Order.t())) ::
  {t(), Trading.Order.t() | nil}

Updates an order in the price level.