CCXT.Signing.Classifier (ccxt_client v0.6.1)

Copy Markdown View Source

Classifies exchange signing patterns from spec AST data.

Analyzes structure.sign_method AST from each exchange spec to determine which of the 9 signing patterns it uses, plus exchange-specific config (header names, encoding preferences).

Classification Strategy

  1. Header-name matching (primary) — distinctive header strings in the AST uniquely identify patterns (e.g., X-BAPI-* → Bybit-style headers)
  2. Hash algorithm fallback — sha384/sha512/sha256 in AST identifiers
  3. Parent inheritance — child exchanges (e.g., binancecoinm) inherit from their parent's pattern
  4. :custom fallback — unclassifiable exchanges get the escape hatch

Usage

spec = CCXT.Spec.load!("bybit")
{pattern, config} = CCXT.Signing.Classifier.classify(spec)
#=> {:hmac_sha256_headers, %{api_key_header: "X-BAPI-API-KEY", ...}}

Summary

Functions

Classifies the signing pattern for an exchange spec.

Classifies a signing pattern from a raw sign_method AST map.

Returns the parent exchange ID for a child exchange, or nil.

Returns all known parent→child mappings.

Types

classification()

@type classification() :: {CCXT.Signing.pattern(), config()}

config()

@type config() :: %{optional(atom()) => term()}

Functions

classify(spec)

@spec classify(map()) :: classification()

Classifies the signing pattern for an exchange spec.

Returns {pattern_atom, config_map} where config contains exchange-specific header names and encoding preferences.

If the spec has no sign_method, falls back to parent inheritance or returns {:custom, %{}}.

classify_from_ast(ast)

@spec classify_from_ast(map()) :: classification()

Classifies a signing pattern from a raw sign_method AST map.

Useful when you have the AST directly without a full spec wrapper.

parent_for(exchange_id)

@spec parent_for(String.t()) :: String.t() | nil

Returns the parent exchange ID for a child exchange, or nil.

parent_map()

@spec parent_map() :: %{required(String.t()) => String.t()}

Returns all known parent→child mappings.