CCXT.Dispatch (ccxt_client v0.6.1)

Copy Markdown View Source

Shared request dispatcher for generated exchange endpoint functions.

All generated endpoint functions delegate to call/4, which handles:

  1. Path interpolation — replaces {param} templates with values from params
  2. Base URL resolution — navigates exchange.base_urls using endpoint sections
  3. Signing — authenticates private endpoint requests via CCXT.Signing.sign/4
  4. HTTP delegation — calls CCXT.HTTP.request/4 or CCXT.HTTP.signed_request/4

Future phases

  • Phase 5: Response parsing (field mapping to unified structs)
  • Task 17: Symbol denormalization (unified → exchange-specific format)

Summary

Types

Compile-time endpoint configuration from spec

Functions

Dispatches a request to an exchange endpoint.

Replaces {param} placeholders in path with values from params, returning remaining params.

Navigates base_urls using endpoint sections to find the appropriate base URL.

Types

endpoint_config()

@type endpoint_config() :: %{
  name: atom(),
  method: atom(),
  path: String.t(),
  sections: [String.t()],
  weight: number(),
  url_prefix: String.t(),
  authenticated: boolean()
}

Compile-time endpoint configuration from spec

Functions

call(exchange, endpoint_config, params \\ %{}, opts \\ [])

@spec call(CCXT.Exchange.t(), endpoint_config(), map(), keyword()) ::
  {:ok, CCXT.HTTP.response()} | {:error, CCXT.Error.t()}

Dispatches a request to an exchange endpoint.

Resolves the base URL from the endpoint's sections, interpolates path templates, and delegates to CCXT.HTTP.request/4.

Parameters

  • exchange%CCXT.Exchange{} runtime configuration
  • endpoint_config — compile-time endpoint map with :name, :method, :path, :sections, :weight
  • params — request parameters (query for GET/HEAD/DELETE, body for POST/PUT/PATCH)
  • opts — passed through to CCXT.HTTP.request/4 (:timeout, :headers, etc.)

Examples

config = %{name: :public_get_v5_market_tickers, method: :get,
  path: "v5/market/tickers", sections: ["public"], weight: 5}

CCXT.Dispatch.call(exchange, config, %{"category" => "spot"})

interpolate_path(path, params)

@spec interpolate_path(String.t(), map()) :: {String.t(), map()}

Replaces {param} placeholders in path with values from params, returning remaining params.

resolve_base_url(sections, base_urls)

@spec resolve_base_url([String.t()], map()) :: String.t()

Navigates base_urls using endpoint sections to find the appropriate base URL.