Trading.Order (trading v0.1.0)

Represents a trading order with various types and attributes.

Summary

Functions

Checks if an order is active.

Checks if an order can be executed at a given price.

Fills an order partially or completely.

Creates a new order with the given parameters.

Updates order status.

Validates an order.

Types

order_type()

@type order_type() :: :market | :limit | :stop | :stop_limit | :iceberg

side()

@type side() :: :buy | :sell

status()

@type status() :: :new | :partially_filled | :filled | :cancelled | :rejected

t()

@type t() :: %Trading.Order{
  client_id: String.t() | nil,
  hidden_quantity: pos_integer() | nil,
  id: String.t(),
  metadata: map() | nil,
  price: float() | nil,
  quantity: pos_integer(),
  remaining_quantity: pos_integer() | nil,
  side: side(),
  status: status(),
  stop_price: float() | nil,
  time_in_force: time_in_force(),
  timestamp: integer(),
  type: order_type()
}

time_in_force()

@type time_in_force() :: :day | :gtc | :ioc | :fok

Functions

active?(order)

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

Checks if an order is active.

executable_at_price?(order, price)

@spec executable_at_price?(t(), float()) :: boolean()

Checks if an order can be executed at a given price.

fill(order, fill_quantity)

@spec fill(t(), pos_integer()) :: {:ok, t()} | {:error, String.t()}

Fills an order partially or completely.

iceberg_order(id, side, price, total_quantity, visible_quantity, opts \\ [])

@spec iceberg_order(
  String.t(),
  side(),
  float(),
  pos_integer(),
  pos_integer(),
  keyword()
) :: t()

Creates an iceberg order.

limit_order(id, side, price, quantity, opts \\ [])

@spec limit_order(String.t(), side(), float(), pos_integer(), keyword()) :: t()

Creates a limit order.

market_order(id, side, quantity, opts \\ [])

@spec market_order(String.t(), side(), pos_integer(), keyword()) :: t()

Creates a market order.

new(id, side, price, quantity, type, opts \\ [])

@spec new(String.t(), side(), float() | nil, pos_integer(), order_type(), keyword()) ::
  t()

Creates a new order with the given parameters.

stop_order(id, side, stop_price, quantity, opts \\ [])

@spec stop_order(String.t(), side(), float(), pos_integer(), keyword()) :: t()

Creates a stop order.

update_status(order, status)

@spec update_status(t(), status()) :: t()

Updates order status.

validate(order)

@spec validate(t()) :: {:ok, t()} | {:error, String.t()}

Validates an order.