Longbridge.SharelistContext (longbridge v0.1.0)

Copy Markdown View Source

Community sharelist context.

Manages shared watchlists: create, list, add/remove symbols, rename, and delete.

All functions accept a Longbridge.Config struct and return {:ok, data} | {:error, reason} tuples.

Usage

config = Longbridge.Config.new(...)

{:ok, list} = Longbridge.SharelistContext.create(config,
  name: "Tech Watch",
  symbols: ["AAPL.US", "MSFT.US", "GOOG.US"]
)

Summary

Functions

Adds one or more symbols to a sharelist.

Creates a new sharelist.

Deletes a sharelist by id.

Returns the details (including the current symbol list) of a sharelist by id.

Lists sharelists owned by the current user.

Lists the most-followed public sharelists (curated by the Longbridge community).

Removes one or more symbols from a sharelist.

Functions

add_symbols(config, sharelist_id, symbols, opts \\ [])

@spec add_symbols(Longbridge.Config.t(), String.t(), [String.t()], keyword()) ::
  {:ok, map()} | {:error, term()}

Adds one or more symbols to a sharelist.

Endpoint: POST /v1/sharelists/<id>/items. Idempotent — adding a symbol already in the list is a no-op.

create(config, opts, http_opts \\ [])

@spec create(Longbridge.Config.t(), keyword(), keyword()) ::
  {:ok, map()} | {:error, term()}

Creates a new sharelist.

Options

  • :name — sharelist name (required)
  • :description — optional description
  • :symbols — initial list of symbols (default: [])

delete(config, sharelist_id, opts \\ [])

@spec delete(Longbridge.Config.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Deletes a sharelist by id.

Endpoint: DELETE /v1/sharelists/<id>. Only the owner can delete; the server returns an error if a different account tries.

detail(config, sharelist_id, opts \\ [])

@spec detail(Longbridge.Config.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Returns the details (including the current symbol list) of a sharelist by id.

Endpoint: GET /v1/sharelists/<id>. Returns the sharelist metadata plus a symbols array.

list(config, opts \\ [], http_opts \\ [])

@spec list(Longbridge.Config.t(), keyword(), keyword()) ::
  {:ok, map()} | {:error, term()}

Lists sharelists owned by the current user.

Endpoint: GET /v1/sharelists. Supports :page and :page_size pagination. Each list entry has id, name, description, owner_id, created_at, and updated_at.

popular(config, opts \\ [], http_opts \\ [])

@spec popular(Longbridge.Config.t(), keyword(), keyword()) ::
  {:ok, map()} | {:error, term()}

Lists the most-followed public sharelists (curated by the Longbridge community).

Endpoint: GET /v1/sharelists/popular. Useful for discovery when the user hasn't built their own list yet.

remove_symbols(config, sharelist_id, symbols, opts \\ [])

@spec remove_symbols(Longbridge.Config.t(), String.t(), [String.t()], keyword()) ::
  {:ok, map()} | {:error, term()}

Removes one or more symbols from a sharelist.

Endpoint: DELETE /v1/sharelists/<id>/items. Removing a symbol that's not in the list is a no-op.

rename(config, sharelist_id, name, opts \\ [])

@spec rename(Longbridge.Config.t(), String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Renames a sharelist.

Endpoint: POST /v1/sharelists/<id>. Only the name field is updatable here; pass the new name as the third argument.