Current section
Files
Jump to
Current section
Files
lib/ccxt/ws/subscription/action_subscribe.ex
defmodule CCXT.WS.Subscription.ActionSubscribe do
@moduledoc """
Alpaca/LBank-style subscribe frame keyed on an `"action"` field with a
params object.
%{"action" => "subscribe", "params" => %{"channels" => ["ticker"]}}
Config keys:
- `:op_field` — default `"action"`
- `:args_field` — default `"params"`
- `:channels_key` — key under which the channel list is placed within
the params object (default `"channels"`)
Not wired in `CCXT.WS.Config` today (no priority-tier exchange uses it).
"""
@behaviour CCXT.WS.Subscription.Behaviour
@impl true
def subscribe(channels, config) when is_list(channels) do
build(channels, config, "subscribe")
end
@impl true
def unsubscribe(channels, config) when is_list(channels) do
build(channels, config, "unsubscribe")
end
defp build(channels, config, action) do
action_field = Map.get(config, :op_field, "action")
params_field = Map.get(config, :args_field, "params")
channels_key = Map.get(config, :channels_key, "channels")
%{action_field => action, params_field => %{channels_key => channels}}
end
end