CCXT.WS.Subscription (ccxt_client v0.6.1)

Copy Markdown View Source

WebSocket subscription pattern dispatcher.

Parallel of CCXT.WS.Auth: a function-head dispatcher that routes a pattern atom to the matching per-pattern module. Each pattern module implements the CCXT.WS.Subscription.Behaviour callbacks.

Supported Patterns

Pattern atomExchangesFrame shape
:op_subscribebybit, bitmex%{"op"=>"subscribe","args"=>[strings]}
:op_subscribe_objectsokx%{"op"=>"subscribe","args"=>[objects]}
:method_subscribebinance, xt, aster%{"method"=>"SUBSCRIBE","params"=>[strings]}
:method_params_subscribekraken, cryptocom%{"method"=>"subscribe","params"=>%{"channel"=>[strings]}}
:method_subscriptionhyperliquid%{"method"=>"subscribe","subscription"=>%{"type"=>…}}
:method_topicsexmo%{"method"=>"subscribe","topics"=>[strings]}
:method_as_topiccoinex, phemex%{"method"=>"ticker.subscribe","params"=>[],"id"=>…}
:jsonrpc_subscribederibitJSON-RPC 2.0 envelope with correlation id
:event_subscribegate, bitfinex, woo, bitrue%{"event"=>"subscribe","channel"=>…} variants
:type_subscribekucoin, coinbaseexchange%{"type"=>"subscribe","topic"=>…} variants
:sub_subscribehtx, huobi%{"sub"=>…}one frame per channel, no id (see SubBased moduledoc)
:reqtype_subbingx%{"reqType"=>"sub","dataType"=>…}one frame per channel
:action_subscribealpaca, lbank%{"action"=>"subscribe","params"=>%{…}}
:custombithumb, upbit, deepcoin, … (escape hatch)dispatches on config[:custom_type]

Return shape

build_subscribe/3 returns {:ok, frame_or_frames} where frame_or_frames is map() | [map()]. Single-frame exchanges return a map; multi-frame exchanges (HTX, BingX, Upbit-custom) return a list.

Pattern modules may also surface input-shape rejections as {:error, term()} (e.g. :multiple_maps_not_supported / :mixed_channel_types from :event_subscribe and :method_params_subscribe when callers mix shapes). The dispatcher passes those tuples through verbatim — it never wraps them in {:ok, _}.

Unknown patterns return {:error, {:unknown_pattern, atom}} — matches CCXT.WS.Auth's dispatcher-head behavior.

Summary

Functions

Builds the subscribe frame(s) for the pattern and channel list.

Builds the unsubscribe frame(s) — same return shape as build_subscribe/3.

Returns the implementing module for a pattern, or nil if unknown.

Lists every supported subscription pattern atom.

Types

build_result()

@type build_result() :: {:ok, frame() | [frame()]} | {:error, term()}

channel()

@type channel() :: String.t() | map()

config()

@type config() :: map()

frame()

@type frame() :: map()

pattern()

@type pattern() ::
  :op_subscribe
  | :op_subscribe_objects
  | :method_subscribe
  | :method_params_subscribe
  | :method_subscription
  | :method_topics
  | :method_as_topic
  | :jsonrpc_subscribe
  | :event_subscribe
  | :type_subscribe
  | :sub_subscribe
  | :reqtype_sub
  | :action_subscribe
  | :custom

Functions

build_subscribe(pattern, channels, config)

@spec build_subscribe(pattern(), [channel()], config()) :: build_result()

Builds the subscribe frame(s) for the pattern and channel list.

Returns {:ok, map()} for the common single-frame case, or {:ok, [map()]} for multi-frame exchanges (HTX, BingX, Upbit-custom). Callers should handle both shapes.

build_unsubscribe(pattern, channels, config)

@spec build_unsubscribe(pattern(), [channel()], config()) :: build_result()

Builds the unsubscribe frame(s) — same return shape as build_subscribe/3.

module_for_pattern(arg1)

@spec module_for_pattern(pattern()) :: module() | nil

Returns the implementing module for a pattern, or nil if unknown.

patterns()

@spec patterns() :: [pattern()]

Lists every supported subscription pattern atom.