Longbridge.PortfolioContext (longbridge v0.1.0)

Copy Markdown View Source

Portfolio context.

Provides exchange rates and portfolio P&L analysis. Current positions are served by Longbridge.TradeContext.stock_positions/1 and fund_positions/1.

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

Usage

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

{:ok, rates} = Longbridge.PortfolioContext.exchange_rates(config)

Summary

Functions

Returns current exchange rates (all currencies the server knows).

Returns portfolio profit & loss analysis.

Returns detailed profit & loss breakdown for a date range.

Functions

exchange_rates(config, base_currency \\ nil, http_opts \\ [])

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

Returns current exchange rates (all currencies the server knows).

base_currency is optional. The upstream returns rates for every supported counter-currency when omitted.

Trailing http_opts is forwarded to HTTPClient.request_json/5, so callers may override :http_url, :finch, etc. on a per-call basis.

portfolio_pl(config, opts \\ [])

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

Returns portfolio profit & loss analysis.

Options

  • :market:HK, :US, :CN, :SG

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.

portfolio_positions(config, opts \\ [])

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

Returns detailed profit & loss breakdown for a date range.

Options

  • :start_date"YYYY-MM-DD" (required)
  • :end_date"YYYY-MM-DD" (required)
  • :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.