Trading.Backtest.Strategy behaviour (trading v0.1.0)

Base behaviour for trading strategies.

Summary

Functions

Creates a new strategy instance.

Processes fill notifications.

Processes market data and generates signals.

Types

signal()

@type signal() :: %{
  id: String.t(),
  strategy: atom(),
  symbol: String.t(),
  direction: :long | :short | :flat,
  position_size_pct: float(),
  price: float() | nil,
  order_type: atom() | nil,
  metadata: map()
}

t()

@type t() :: %Trading.Backtest.Strategy{
  module: module(),
  params: map(),
  state: term()
}

Callbacks

init(params)

@callback init(params :: map()) :: {:ok, state :: term()} | {:error, reason :: term()}

on_fill(state, fill)

@callback on_fill(
  state :: term(),
  fill :: map()
) :: {:ok, state :: term()}

on_market_data(state, symbol, market_data, context)

@callback on_market_data(
  state :: term(),
  symbol :: String.t(),
  market_data :: map(),
  context :: map()
) :: {:ok, state :: term()} | {:signal, signal(), state :: term()}

Functions

new(module, params)

@spec new(module(), map()) :: t()

Creates a new strategy instance.

on_fill(strategy, fill)

@spec on_fill(t(), map()) :: t()

Processes fill notifications.

on_market_data(strategy, symbol, market_data, context)

@spec on_market_data(t(), String.t(), map(), map()) ::
  {:ok, t()} | {:signal, signal()}

Processes market data and generates signals.