Dollar-cost averaging (DCA) plan context.
Manages recurring buy plans: create, list, update, pause, resume, and stop.
All functions accept a Longbridge.Config struct and return
{:ok, data} | {:error, reason} tuples.
Usage
config = Longbridge.Config.new(...)
{:ok, plan} = Longbridge.DCAContext.create_plan(config,
symbol: "AAPL.US",
amount: "100.00",
frequency: :weekly
)
Summary
Functions
Creates a new DCA plan.
Stops (permanently finishes) a plan by plan_id.
Lists all DCA plans. Supports pagination.
Pauses an active plan by plan_id.
Fetches a single plan by plan_id from the list endpoint.
Resumes a paused plan by plan_id.
Updates an existing plan. Same options as create_plan/2 plus :plan_id.
Types
Functions
@spec create_plan(Longbridge.Config.t(), keyword(), keyword()) :: {:ok, map()} | {:error, term()}
Creates a new DCA plan.
Options
:symbol— target symbol (required):amount— amount per period (required):frequency—:daily,:weekly,:biweekly,:monthly(required):day_of_week— for weekly frequency, e.g."Monday":day_of_month— for monthly frequency,"1"through"31":allow_margin— boolean, defaults tofalse
Trailing http_opts is forwarded to HTTPClient.request_json/5,
so callers may override :http_url, :finch, etc. on a per-call basis.
@spec delete_plan(Longbridge.Config.t(), String.t(), keyword()) :: {:ok, map()} | {:error, term()}
Stops (permanently finishes) a plan by plan_id.
The upstream API does not expose a true DELETE; finishing is the irreversible terminal state.
@spec list_plans( Longbridge.Config.t(), keyword() ) :: {:ok, map()} | {:error, term()}
Lists all DCA plans. Supports pagination.
Options
:page— 1-indexed page (default1):limit— page size (default100):status—:active,:suspended, or:finished:symbol— filter by symbol
HTTP-level keys such as :http_url and :finch may be passed in
the same keyword list; they are forwarded to HTTPClient.request_json/5
alongside the built query string. Function-built :params take
precedence over any caller-supplied :params.
@spec pause_plan(Longbridge.Config.t(), String.t(), keyword()) :: {:ok, map()} | {:error, term()}
Pauses an active plan by plan_id.
@spec plan_detail(Longbridge.Config.t(), String.t(), keyword()) :: {:ok, map() | nil} | {:error, term()}
Fetches a single plan by plan_id from the list endpoint.
The upstream API does not have a per-plan detail endpoint; this helper filters the list response so callers that only want one plan don't have to walk the pagination.
@spec resume_plan(Longbridge.Config.t(), String.t(), keyword()) :: {:ok, map()} | {:error, term()}
Resumes a paused plan by plan_id.
@spec update_plan(Longbridge.Config.t(), keyword(), keyword()) :: {:ok, map()} | {:error, term()}
Updates an existing plan. Same options as create_plan/2 plus :plan_id.
Trailing http_opts is forwarded to HTTPClient.request_json/5,
so callers may override :http_url, :finch, etc. on a per-call basis.